source: trunk/src/civ.m @ 312

Last change on this file since 312 was 312, checked in by gostiaux, 12 years ago

type of batch submission with oar added

File size: 177.3 KB
RevLine 
[112]1%'civ': function associated with the interface 'civ.fig' for PIV, spline interpolation and stereo PIV (patch)
[2]2%------------------------------------------------------------------------
[309]3%  provides an interface for the software menucivx
[2]4% function varargout = civ(varargin)
[309]5% provides an interface for the software menucivx
[2]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
[309]25% Last Modified by GUIDE v2.5 30-Nov-2011 21:52:52
[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.
[298]47function civ_OpeningFcn(hObject, eventdata, handles, fileinput)
[12]48%------------------------------------------------------------------------
[2]49% This function has no output args, see OutputFcn.
[298]50
51%% General settings
[2]52handles.output = hObject;
[298]53guidata(hObject, handles); % Update handles structure
[309]54set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display)
[252]55
[298]56%% Adjust the GUI according to the binaries available in PARAM.xml
[276]57path_civ=fileparts(which('civ')); %path to civ
[298]58addpath (path_civ) ; %add the path to civ, (useful in case of change of working directory after civ has been s opened in the working directory)
[273]59errormsg=[];%default error message
60xmlfile='PARAM.xml';
61if exist(xmlfile,'file')
62    try
63        t=xmltree(xmlfile);
64        sparam=convert(t);
65    catch
66        errormsg={' Unable to read the file PARAM.xml defining the civx binaries:'; lasterr};
67    end
68else
69    errormsg=[xmlfile ' not found: path to civx binaries undefined'];
70end
71if ~isempty(errormsg)
[301]72    msgbox_uvmat('WARNING',errormsg);
[273]73end
74test_batch=0;%default: ,no batch mode available
75if isfield(sparam,'BatchParam') && isfield(sparam.BatchParam,'BatchMode')
76    test_batch=strcmp(sparam.BatchParam.BatchMode,'sge'); %sge is currently the only implemented batch mod
77end
78if test_batch==0
79    set(handles.BATCH,'Enable','off')% put the BATCH button in grey (unactivated)
80    set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])% put the BATCH button in grey (unactivated)
81end
82if isfield(sparam.RunParam,'CivBin')
83    if ~exist(sparam.RunParam.CivBin,'file')
[276]84        sparam.RunParam.CivBin=fullfile(path_civ,sparam.RunParam.CivBin);
[273]85    end
86else
87    sparam.RunParam.CivBin='';
88end
89
[298]90%% load the list of previously browsed files in the upper bar menu Open/
[296]91dir_perso=prefdir; % path to the directory .matlab for personal data
92profil_perso=fullfile(dir_perso,'uvmat_perso.mat');% personal data file uvmauvmat_perso.mat' in .matlab
93if exist(profil_perso,'file')
94    h=load (profil_perso);
95    if isfield(h,'MenuFile')
96        for ifile=1:min(length(h.MenuFile),5)
97            eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',h.MenuFile{ifile});'])
98        end
99    end
[273]100end
101
[298]102%% prepare the GUI with parameters from the input file if opened from uvmat
103if exist('fileinput','var')% && isfield(param,'RootName') && ~isempty(param.RootName)
104    errormsg=display_file_name(handles,fileinput);
105    if ~isempty(errormsg)
106        msgbox_uvmat('ERROR',errormsg)
[112]107    end
[2]108end
109
[12]110%------------------------------------------------------------------------
[2]111% --- Outputs from this function are returned to the command line.
112function varargout = civ_OutputFcn(hObject, eventdata, handles)
[12]113%------------------------------------------------------------------------
[2]114% Get default command line output from handles structure
115varargout{1} = handles.output;
116
[307]117%------------------------------------------------------------------------
[309]118% --- Function activated by the Open/Browse... option in the upper menu bar.
[307]119function MenuBrowse_Callback(hObject, eventdata, handles)
120%------------------------------------------------------------------------
121%get the current input root file name to initiate the browser
122filebase=get(handles.RootName,'String');
123oldfile=''; %default
[309]124if isempty(filebase)|| isequal(filebase,'')%loads the previously stored root file name
[307]125    dir_perso=prefdir;
126    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
127    if exist(profil_perso,'file')
128        h=load (profil_perso);
129        if isfield(h,'filebase')&& ischar(h.filebase)
130            oldfile=h.filebase;
131        end
132        if isfield(h,'RootPath') && ischar(h.RootPath)
133            oldfile=h.RootPath;
134        end
135    end
136else
137    oldfile=filebase;
138end
139ind_opening=1;%default
140browse.incr_pair=[0 0]; %default
141menu={'*.xml;*.civ;*.png;*.jpg;*.tif;*.avi;*.AVI;*.nc;', ' (*.xml,*.civ,*.png,*.jpg ,.tif, *.avi,*.nc)';
[309]142    '*.xml',  '.xml files '; ...
143    '*.civ',  '.civ files '; ...
144    '*.png','.png image files'; ...
145    '*.jpg',' jpeg image files'; ...
146    '*.tif','.tif image files'; ...
147    '*.avi;*.AVI','.avi movie files'; ...
148    '*.nc','.netcdf files'; ...
149    '*.*',  'All Files (*.*)'};
[307]150[FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file',oldfile);
151fileinput=[PathName FileName];%complete file name
152sizf=size(fileinput);
153if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
[2]154
[307]155%% prepare the GUI with parameters from the input file if opened from uvmat
156errormsg=display_file_name(handles,fileinput);
[309]157if ~isempty(errormsg)
158    msgbox_uvmat('ERROR',erromsg)
159end
[2]160
[307]161[path,name,ext]=fileparts(fileinput);
162testeditxml=0;
163if isequal(ext,'.xml')
164    testeditxml=1;
165    t_browse=xmltree(fileinput);
166    head_element=get(t_browse,1);
167    if isfield(head_element,'name')&& isequal(head_element.name,'ImaDoc')
168        testeditxml=0;
169    end
170end
171if testeditxml==1 || isequal(ext,'.xls')
172    heditxml=editxml({fileinput});
173    set(heditxml,'Tag','browser')
174    waitfor(heditxml,'Tag','idle')
175    if ~ishandle(heditxml)
176        return
177    end
178    attr=findobj(get(heditxml,'children'),'Tag','CurrentAttributes');
179    set(handles.browse,'UserData',fileinput)% store for future opening with browser
180    fileinput=get(attr,'UserData');
181    if ~exist(fileinput,'file')
182        return
183    end
184end
185[RootPath,RootFile,str1,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput);
[309]186% filebase=fullfile(RootPath,RootFile);
[307]187num_i1=str2double(str1);
188if isnan(num_i1),num_i1=1;end
189num_i2=str2double(str2);
190if isnan(num_i2),num_i2=num_i1;end
191num_j1=stra2num(str_a);
192if isnan(num_j1),num_j1=1;end
193num_j2=stra2num(str_b);
194if isnan(num_j2),num_j2=num_j1;end
195if isequal(get(handles.ListCompareMode,'Value'),1)
196    browse=[];%initialisation
197else
198    browse=get(handlesRootName,'UserData');
199end
200browse.num_i1=num_i1;
201browse.num_i2=num_i2;
202browse.num_j1=num_j1;
203browse.num_j2=num_j2;
204if length(ext)>1 && (~isempty(imformats(ext(2:end)))||strcmpi(ext,'.avi'));%if an image file has been opened by uvmat
205    browse.nom_type_ima=nom_type;
206    browse.ext_ima=ext;
207    set(handles.ImaExt,'String',ext)
208end
209set(handles.ImaDoc,'String',ext);
210
211set(handles.RootName,'UserData',browse);% store information from browser
212
[309]213%------------------------------------------------------------------------
[273]214% --- Open again the file whose name has been recorded in MenuFile_1
215function MenuFile_1_Callback(hObject, eventdata, handles)
[12]216%------------------------------------------------------------------------
[273]217fileinput=get(handles.MenuFile_1,'Label');
[298]218errormsg=display_file_name(handles,fileinput);
219if ~isempty(errormsg)
220    msgbox_uvmat('ERROR',erromsg)
221end
[273]222
223% -----------------------------------------------------------------------
224% --- Open again the file whose name has been recorded in MenuFile_2
225function MenuFile_2_Callback(hObject, eventdata, handles)
226%------------------------------------------------------------------------
227fileinput=get(handles.MenuFile_2,'Label');
[298]228errormsg=display_file_name(handles,fileinput);
229if ~isempty(errormsg)
230    msgbox_uvmat('ERROR',erromsg)
231end
[309]232
[273]233% -----------------------------------------------------------------------
234% --- Open again the file whose name has been recorded in MenuFile_3
235function MenuFile_3_Callback(hObject, eventdata, handles)
236%------------------------------------------------------------------------
237fileinput=get(handles.MenuFile_3,'Label');
[298]238errormsg=display_file_name(handles,fileinput);
239if ~isempty(errormsg)
240    msgbox_uvmat('ERROR',erromsg)
241end
[309]242
[273]243% -----------------------------------------------------------------------
244% --- Open again the file whose name has been recorded in MenuFile_4
245function MenuFile_4_Callback(hObject, eventdata, handles)
246%------------------------------------------------------------------------
247fileinput=get(handles.MenuFile_4,'Label');
[298]248errormsg=display_file_name(handles,fileinput);
249if ~isempty(errormsg)
250    msgbox_uvmat('ERROR',erromsg)
251end
[309]252
[273]253% -----------------------------------------------------------------------
254% --- Open again the file whose name has been recorded in MenuFile_5
255function MenuFile_5_Callback(hObject, eventdata, handles)
256%------------------------------------------------------------------------
257fileinput=get(handles.MenuFile_5,'Label');
[298]258errormsg=display_file_name(handles,fileinput);
259if ~isempty(errormsg)
260    msgbox_uvmat('ERROR',erromsg)
261end
[2]262
[309]263% -----------------------------------------------------------------------
264% --- Prepare the GUI for the compiled CivX program
265function MenuCivX_Callback(hObject, eventdata, handles)
266set(handles.MenuMatlab,'checked','off')
267set(handles.MenuCivX,'checked','on')
268%set(handles.thresh_patch1,'Visible','off')
269% set(handles.thresh_text1,'Visible','off')
270% set(handles.num_MaxDiff,'Visible','off')
271% set(handles.thresh_text2,'Visible','off')
272set(handles.num_Rho,'Style','edit')
273set(handles.num_Rho,'String','1')
274set(handles.BATCH,'Enable','on')
275% -----------------------------------------------------------------------
276
277% -----------------------------------------------------------------------
278% --- Prepare the GUI for the Matlab PIV program
279function MenuMatlab_Callback(hObject, eventdata, handles)
280% -----------------------------------------------------------------------
281set(handles.MenuMatlab,'checked','on')
282set(handles.MenuCivX,'checked','off')
283if get(handles.CheckPatch1,'Value')
284    set(handles.thresh_patch1,'Visible','on')
285    set(handles.thresh_text1,'Visible','on')
286end
287if get(handles.CheckPatch2,'Value')
288    set(handles.num_MaxDiff,'Visible','on')
289    set(handles.thresh_text2,'Visible','on')
290end
291set(handles.num_Rho,'Style','popupmenu')
292set(handles.num_Rho,'Value',1)
293set(handles.num_Rho,'String',{'1';'2'})
294set(handles.BATCH,'Enable','off')
295
296% -----------------------------------------------------------------------
297% --- Open the help html file
298function MenuHelp_Callback(hObject, eventdata, handles)
299% -----------------------------------------------------------------------
300path_civ=fileparts(which ('civ'));
301helpfile=fullfile(path_civ,'uvmat_doc','uvmat_doc.html');
302if isempty(dir(helpfile))
303    msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
304else
305    addpath (fullfile(path_civ,'uvmat_doc'))
306    web([helpfile '#civ'])
307end
308
[12]309%------------------------------------------------------------------------
[309]310% --- Function activated when a new filebase (image series) is introduced
[71]311function RootName_Callback(hObject, eventdata, handles)
[12]312%------------------------------------------------------------------------
[273]313filebase=get(handles.RootName,'String');
[298]314errormsg=display_file_name(handles,filebase);
315if ~isempty(errormsg)
316    msgbox_uvmat('ERROR',erromsg)
317end
[309]318
[273]319%------------------------------------------------------------------------
[309]320% --- general function activated for an input file series
[298]321function errormsg=display_file_name(handles,fileinput)
[273]322%------------------------------------------------------------------------
[282]323set(handles.ListCompareMode,'Visible','on')
[298]324errormsg='';%default empty error message
[273]325
[298]326%% enable RUN, BATCH button and 'status' display
327set(handles.RUN, 'Enable','On')
328set(handles.RUN,'BackgroundColor',[1 0 0])%set RUN button to red color
329set(handles.BATCH,'Enable','On')
330set(handles.BATCH,'BackgroundColor',[1 0 0])%set BATCH button to red color
331if isfield(handles,'status')
332    set(handles.status,'Value',0);       %suppress the 'status' display
333    status_Callback([], [], handles)
[2]334end
335
[298]336%% determine nomenclature types and extension of the input files
337ext_ima='';%default
338nom_type_ima='';%default
339nom_type_nc='';
340[RootPath,FileName,i1_str,i2_str,j1_str,j2_str,ext_input,nom_type_input,subdir]=name2display(fileinput);
341RootName=fullfile(RootPath,FileName);
342set(handles.RootName,'String',RootName)
[309]343set(handles.RootName,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
[300]344num_i1=str2double(i1_str);
345num_i2=str2double(i2_str);
346num_j1=str2double(j1_str);
[301]347num_j2=str2double(j2_str);
348num_ref_i=num_i1;%efaulmt ref index
349num_ref_j=num_j1;
[300]350browse.incr_pair=[0 0];%default
[307]351
352% form=imformats(ext_input(2:end));
353if ~isempty(ext_input)&&(~isempty(imformats(ext_input(2:end)))||strcmpi(ext_input,'.avi'))% if the extension corresponds to an image or movie format recognized by Matlab
[298]354    ext_ima=ext_input;
355    nom_type_ima=nom_type_input;
356else %case of netcdf input file, look for corresponding images
357    nom_type_nc=nom_type_input;
[300]358    if ~isempty(num_i2)
[301]359        num_ref_i=floor((num_ref_i+num_i2)/2);% reference image number corresponding to the file
[300]360        browse.incr_pair(1)=num_i2-num_i1;
361        browse.incr_pair(2)=0;
362    end
[298]363    %TODO: read the image name in the netcdf file (if documented)
364    %look for double image series '_i_j'
365    dirima=dir([RootName '_' i1_str '_' j1_str '.*']);
366    if isempty(dirima)
367        % look for images series  with sub marker '_'
368        dirima=dir([RootName '_*' i1_str  '.*']);
369        if isempty(dirima)
370            % look for other images series
371            dirima=dir([RootName '*' i1_str '.*']);
372            if isempty(dirima)
373                % look for other images series witth letter appendix
374                appendix=char(96+j1_str);
375                dirima=dir([RootName '*' i1_str appendix '.*']);
376            end
377        end
[2]378    end
[298]379    for ilist=1:numel(dirima)
380        [pp,ff,i1,i2,j1,j2,ext_list,nom_type_list]=name2display(dirima(ilist).name);
381        form=imformats(ext_list(2:end));
382        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
383            ext_ima=ext_list;
384            nom_type_ima=nom_type_list;
385            num_i1=str2double(i1);
386            num_j1=str2double(j1);
387            num_i2=str2double(i2);
388            num_j2=str2double(j2);
389           
390            % set the range of fields (1:1 by default) and selected pair
391            if isequal(num_i2,num_i1)||isnan(num_i2)
392                num_ref_i=num_i1;
393            else
394                num_ref_i=floor((num_i1+num_i2)/2);
395                browse.incr_pair(1)=num_i2-num_i1;
396                browse.incr_pair(2)=0;
397            end
398            if isequal(num_j1,num_j2)||isnan(num_j2)
399                if isnan(num_j1)
400                    num_ref_j=1;
401                else
402                    num_ref_j=num_j1;
403                end
404            else
405                num_ref_j=floor((num_j1+num_j2)/2);
406                browse.incr_pair(2)=num_j2-num_j1;
407            end
408            break
409        end
410    end
[2]411end
[300]412
[298]413%% look for an image documentation file
414ext_imadoc='';%default
415if exist([RootName '.xml'],'file')
416    ext_imadoc='.xml';
417elseif exist([RootName '.civxml'],'file')
418    ext_imadoc='.civxml';
419elseif exist([RootName '.civ'],'file')
420    ext_imadoc='.civ';
421elseif exist([RootName '.avi'],'file')
422    ext_imadoc='.avi';
423elseif exist([RootName '.AVI'],'file')
424    ext_imadoc='.AVI';
425end
426set(handles.ImaDoc,'String',ext_imadoc)% display the extension name for the image documentation file used
427set(handles.ImaDoc,'BackgroundColor',[1 1 0])
428drawnow
[2]429%%%%%%%%   read image documentation file  %%%%%%%%%%%%%%%%%%%%%%%%%%%
[84]430mode=''; %default
[298]431time=[];
432TimeUnit='frame'; %default
433CoordUnit='px';%default
434pxcmx_search=[];%default
435pxcmy_search=[];%default
[128]436if isequal(ext_imadoc,'.civxml')%TO ABANDON
[298]437    [nbfield,nbfield2,time]=read_civxml([RootName '.civxml']);
[2]438    mode='pair j1-j2';
439    if isempty(nom_type_ima)% dtermine types by default if not already selected by browser or uvmat
[112]440        nom_type_ima='_i_j';
[2]441    end
[128]442elseif isequal(ext_imadoc,'.xml')
[298]443    [XmlData,warntext]=imadoc2struct([RootName '.xml']);
[2]444    ext_ima_read=[];
445    nom_type_read=[];
[12]446    if isfield(XmlData,'Heading')&&isfield(XmlData.Heading','ImageName')&&ischar(XmlData.Heading.ImageName)% get image nom type and extension from the xml file
[2]447        [PP,FF,fc,str2,str_a,str_b,ext_ima_read,nom_type_read]=name2display(XmlData.Heading.ImageName);
[298]448        fullname=fullfile(fileparts(RootName),XmlData.Heading.ImageName); %full name (including path) of the first image defined by the xmle file,
[45]449        if ~exist(fullname,'file')
[12]450            msgbox_uvmat('WARNING',['FirstImage ' fullname ' defined in the xml file does not exist'])
451        end
[2]452    end
[84]453    if isfield(XmlData,'Time')
[85]454        time=XmlData.Time;
[84]455        nbfield=size(time,1);
[122]456        nbfield2=size(time,2);
[127]457        %transform .Time to a column vector if it is a line vector thenomenclature uses a single index: correct possible bug in xml
[122]458        if isequal(nbfield,1) && ~isequal(nbfield2,1)% .Time is a line vector
[301]459            if numel(nom_type_read)>=2 && isempty(regexp(nom_type_read(2:end),'\D','once'))
[84]460                time=time';
[122]461                nbfield=nbfield2;
462                nbfield2=1;
[84]463            end
464        end
465    end
[71]466    if isfield(XmlData,'TimeUnit')
467        TimeUnit=XmlData.TimeUnit;
[2]468    end
469    pxcmx_search=1;
470    pxcmy_search=1;
471    if isfield(XmlData,'GeometryCalib')
472        tsai=XmlData.GeometryCalib;
[112]473        if isfield(tsai,'f') && isfield(tsai,'Tz') && isfield(tsai,'dpx') && isfield(tsai,'dpy')&& isfield(tsai,'R')
474            rot2D=tsai.R(1:2,[1,2]);
475            pxcmx_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpx);
476            pxcmy_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpy);
[2]477        end
[112]478        if isfield(tsai,'CoordUnit')
479            CoordUnit=tsai.CoordUnit;
[2]480        end
[112]481    end
[128]482elseif strcmp(ext_imadoc,'.civ')% case of .civ image documentation file
[298]483    [error,time,TimeUnit,mode,npx,npy]=read_imatext([RootName '.civ']);
484    if error==2, msgbox_uvmat('WARNING',['no file ' RootName '.civ']);
[112]485    elseif error==1, msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
486    end
[128]487    nom_type_ima='001a';
488elseif strcmpi(ext_imadoc,'.avi')
[112]489    nom_type_ima='*';
[128]490    ext_ima=ext_imadoc;
[282]491    set(handles.ListPairMode,'Value',1);
492    set(handles.ListPairMode,'String',{'series(Di)'})
[112]493    dt=0.04;%default
[298]494    if exist([RootName ext_imadoc],'file')==2
495        info=aviinfo([RootName ext_imadoc]);%read infos on the avi movie
[112]496        dt=1/info.FramesPerSecond;%time interval between successive frames
497        nbfield=info.NumFrames;%number of frames
498    end
499    time=(dt*(0:nbfield-1))';%list of image times
[2]500end
501if isempty(time)
502    set(handles.ImaDoc,'String',''); %xml file not used for timing
503end
[298]504set(handles.ImaDoc,'BackgroundColor',[1 1 1])% set display box to yellow color
[2]505
[120]506
[298]507%% timing display
508%show the reference image edit box if relevant (not needed for movies or in the absence of time information
509if ~isempty(time)
[2]510    if size(time,1)+size(time,2)>=3 % if there are at least two time values to define dt
511        nbfield=size(time,1);
512        nbfield2=size(time,2);
[273]513        set(handles.ImaDoc,'UserData',time); %store the set of times
[71]514        set(handles.dt_unit,'String',['dt in m' TimeUnit]);
515        set(handles.TimeUnit,'String',TimeUnit);
[2]516        set(handles.nb_field,'String',num2str(nbfield));
517        set(handles.nb_field2,'String',num2str(nbfield2));
518    end
519end
[71]520set(handles.CoordUnit,'String',CoordUnit)
[273]521set(handles.SearchRange,'UserData',[pxcmx_search pxcmy_search]);
[71]522set(handles.ImaExt,'String',ext_ima)
[298]523set(handles.ref_i,'String',num2str(num_ref_i))
524set(handles.first_i,'String',num2str(num_ref_i));
525set(handles.last_i,'String',num2str(num_ref_i));%
526set(handles.ref_j,'String',num2str(num_ref_j))
527set(handles.first_j,'String',num2str(num_ref_j));
528set(handles.last_j,'String',num2str(num_ref_j));%
[2]529
[298]530%% set the civ options depending on the input file content
531ind_opening=0;%default
532if isequal(ext_input,'.nc')
533    browse.nom_type_nc=nom_type_input;
534    ind_opening=2;% propose 'fix' as the default option
535    Data=nc2struct(fileinput,'ListGlobalAttribute','CivStage','absolut_time_T0','fix','patch','civ2','fix2');
536    if ~isempty(Data.CivStage)%test for civ files
537        ind_opening=Data.CivStage;
538        set(handles.ListPairMode,'Value',3)
539    end
540end
541ListOptions={'CheckCiv1', 'CheckFix1' 'CheckPatch1', 'CheckCiv2', 'CheckFix2', 'CheckPatch2'};
542for index = 1:ind_opening
543    set(handles.(ListOptions{index}),'value',0)
544end
[300]545for index = ind_opening+1
[298]546    set(handles.(ListOptions{index}),'value',1)
547end
548update_CivOptions(handles)
549
550
[273]551%%  set the menus of image pairs and default selection for civ   %%%%%%%%%%%%%%%%%%%
[177]552test_ima_i=numel(nom_type_ima)>1 && isempty(regexp(nom_type_ima(2:end),'\D','once'));%images with single indexing
[122]553if test_ima_i || isequal(nom_type_nc,'_i1-i2')||~(exist('nbfield2','var')&&(nbfield2~=1))
[282]554    set(handles.ListPairMode,'Value',1)
555    set(handles.ListPairMode,'String',{'series(Di)'})   
[2]556elseif (nbfield==1)% simple series in j
[282]557    set(handles.ListPairMode,'Value',1)
558    set(handles.ListPairMode,'String',{'series(Dj)'})
[2]559else
[282]560    set(handles.ListPairMode,'String',{'pair j1-j2';'series(Dj)';'series(Di)'})%multiple choice
[122]561    if nbfield2 <= 10
[282]562        set(handles.ListPairMode,'Value',1)% advice 'pair j1-j2' for small burst
[2]563    end
564end
565
[298]566%% update the subdirectory display
[300]567listot=dir(RootPath);%directory of RootPath
[273]568idir=0;
569listdir={''};%default
[300]570% get the list of existing civ subdirectories in the path of theinput root  file
[273]571for ilist=1:length(listot)
572    if listot(ilist).isdir
573        name=listot(ilist).name;
574        if ~isequal(name,'.') && ~isequal(name,'..')
575            idir=idir+1;
576            listdir{idir,1}=listot(ilist).name;
577        end
578    end
579end
[298]580Value=find(strcmp(subdir,listdir));%search the index of subdir in the cell listdir
[300]581if isempty(Value)% if the input subdir is not found
582    ValueCiv1=get(handles.ListSubdirCiv1,'Value');%read the currrently selected dir name
[298]583    if ValueCiv1>numel(listdir)
584        ValueCiv1=1;
585    end
[300]586    set(handles.txt_SubdirCiv1,'String',listdir{ValueCiv1})
[298]587    ValueCiv2=get(handles.ListSubdirCiv2,'Value');
588    if ValueCiv2>numel(listdir)
589        ValueCiv2=1;
590    end
[300]591    set(handles.txt_SubdirCiv2,'String',listdir{ValueCiv2})
[298]592else
[301]593    ValueCiv1=Value;
594    ValueCiv2=Value;
[300]595     set(handles.txt_SubdirCiv1,'String',listdir{Value})
596     set(handles.txt_SubdirCiv2,'String',listdir{Value})
[298]597end
[301]598set(handles.ListSubdirCiv1,'Value',ValueCiv1)
599set(handles.ListSubdirCiv2,'Value',ValueCiv2)
[282]600set(handles.ListSubdirCiv1,'String',[listdir;'new...'])
[289]601set(handles.ListSubdirCiv2,'String',[listdir;'new...'])
[273]602if isempty(listdir)
[300]603    set(handles.txt_SubdirCiv1,'String','CIV')
604    set(handles.txt_SubdirCiv2,'String','CIV')
[273]605end
606
[300]607%% store info
608browse.nom_type_ima=nom_type_ima;
609set(handles.RootName,'UserData',browse)% store the nomenclature type
[273]610
[298]611%% list the possible index pairs, depending on the option set in ListPairMode
612ListPairMode_Callback([], [], handles)
613
614%% store the root input filename for future opening
615profil_perso=fullfile(prefdir,'uvmat_perso.mat');
616% RootPath=fileparts(RootName);
617if exist(profil_perso,'file')
618    save (profil_perso,'RootPath','-append'); %store the root name for future opening of uvmat
619else
620    txt=ver('MATLAB');
621    Release=txt.Release;
622    relnumb=str2double(Release(3:4));
623    if relnumb >= 14
624        save (profil_perso,'RootPath','-V6'); %store the root name for future opening of uvmat
625    else
626        save (profil_perso,'RootPath'); %store the root name for future opening of uvmat
627    end
628end
[309]629set(handles.RootName,'BackgroundColor',[1 1 1])
[298]630
[12]631%------------------------------------------------------------------------
[309]632% --- Executes on carriage return on the subdir checkciv1 edit window
633function txt_SubdirCiv1_Callback(hObject, eventdata, handles)
[12]634%------------------------------------------------------------------------
[309]635subdir=get(handles.txt_SubdirCiv1,'String');
636menu_str=get(handles.ListSubdirCiv1,'String');% read the list of subdirectories for update
637ichoice=find(strcmp(subdir,menu_str),1);
638if isempty(ichoice)
639    ilist=numel(menu_str); %select 'new...' in the menu
[2]640else
[309]641    ilist=ichoice;
[2]642end
[309]643set(handles.ListSubdirCiv1,'Value',ilist)% select the selected subdir in the menu
644if get(handles.CheckCiv1,'Value')% if Civ1 is performed
645    set(handles.txt_SubdirCiv2,'String',subdir);% set by default civ2 directory the same as civ1
646    set(handles.ListSubdirCiv2,'Value',ilist)
647else % if Civ1 data already exist
648    find_netcpair_civ1(handles); %update the list of available pairs from netcdf files in the new directory
[112]649end
[2]650
[12]651%------------------------------------------------------------------------
[309]652% --- Executes on carriage return on the subdir checkciv1 edit window
653function txt_SubdirCiv2_Callback(hObject, eventdata, handles)
[12]654%------------------------------------------------------------------------
[309]655subdir=get(handles.txt_SubdirCiv1,'String');
656menu_str=get(handles.ListSubdirCiv2,'String');% read the list of subdirectories for update
657ichoice=find(strcmp(subdir,menu_str),1);
658if isempty(ichoice)
659    ilist=numel(menu_str); %select 'new...' in the menu
[2]660else
[309]661    ilist=ichoice;
[2]662end
[309]663set(handles.ListSubdirCiv2,'Value',ilist)% select the selected subdir in the menu
664%update the list of available pairs from netcdf files in the new directory
665if ~get(handles.CheckCiv2,'Value') && ~get(handles.CheckCiv1,'Value') && ~get(handles.CheckFix1,'Value') && ~get(handles.CheckPatch1,'Value')
666    find_netcpair_civ2(handles);
[2]667end
668
[309]669%------------------------------------------------------------------------
670% --- Executes on button press in CheckCiv1.
671function CheckCiv1_Callback(hObject, eventdata, handles)
672%------------------------------------------------------------------------
673update_CivOptions(handles)
[2]674
[309]675%------------------------------------------------------------------------
676% --- Executes on button press in CheckFix1.
677function CheckFix1_Callback(hObject, eventdata, handles)
678%------------------------------------------------------------------------
679update_CivOptions(handles)
[2]680
[309]681%------------------------------------------------------------------------
682% --- Executes on button press in CheckPatch1.
683function CheckPatch1_Callback(hObject, eventdata, handles)
684%------------------------------------------------------------------------
685update_CivOptions(handles)
[2]686
[309]687%------------------------------------------------------------------------
688% --- Executes on button press in CheckCiv2.
689function CheckCiv2_Callback(hObject, eventdata, handles)
690%------------------------------------------------------------------------
691update_CivOptions(handles)
[301]692
[309]693%------------------------------------------------------------------------
694% --- Executes on button press in CheckFix2.
695function CheckFix2_Callback(hObject, eventdata, handles)
696%------------------------------------------------------------------------
697update_CivOptions(handles)
[301]698
[309]699%------------------------------------------------------------------------
700% --- Executes on button press in CheckPatch2.
701function CheckPatch2_Callback(hObject, eventdata, handles)
702%------------------------------------------------------------------------
703update_CivOptions(handles)
[300]704
[12]705%------------------------------------------------------------------------
[309]706% --- activated by any checkbox controling the selection of Civ1,Fix1,Patch1,Civ2,Fix2,Patch2
707function update_CivOptions(handles)
[12]708%------------------------------------------------------------------------
[309]709checkbox=zeros(1,6);
710checkbox(1)=get(handles.CheckCiv1,'Value');
711checkbox(2)=get(handles.CheckFix1,'Value');
712checkbox(3)=get(handles.CheckPatch1,'Value');
713checkbox(4)=get(handles.CheckCiv2,'Value');
714checkbox(5)=get(handles.CheckFix2,'Value');
715checkbox(6)=get(handles.CheckPatch2,'Value');
716ind_selected=find(checkbox,1);
717if ~isempty(ind_selected)
718  RootName=get(handles.RootName,'String');
719    if isempty(RootName)
720         msgbox_uvmat('ERROR','Please open an image or PIV .nc file with the upper bar menu Open/Browse...')
[270]721        return
722    end
[2]723end
[309]724set(handles.PairIndices,'Visible','on')
725set(handles.txt_SubdirCiv1,'Visible','on')
726set(handles.ListSubdirCiv1,'Visible','on')
727find_netcpair_civ1(handles) % select the available netcdf files
728if max(checkbox(4:6))% case of civ2 pair choice needed
729    set(handles.TitlePairCiv2,'Visible','on')
730    set(handles.TitleSubdirCiv2,'Visible','on')
731    set(handles.txt_SubdirCiv2,'Visible','on')
732    set(handles.ListSubdirCiv2,'Visible','on')
733    set(handles.ListPairCiv2,'Visible','on')
734    find_netcpair_civ2(handles) % select the available netcdf files
735else
736    set(handles.TitleSubdirCiv2,'Visible','off')
737    set(handles.txt_SubdirCiv2,'Visible','off')
738    set(handles.ListSubdirCiv2,'Visible','off')
739    set(handles.ListPairCiv2,'Visible','off')
[2]740end
[309]741options={'Civ1','Fix1','Patch1','Civ2','Fix2','Patch2'};
742for ilist=1:length(options)
743    if checkbox(ilist)
744        set(handles.(options{ilist}),'Visible','on')
[2]745    else
[309]746        set(handles.(options{ilist}),'Visible','off')
[112]747    end
[2]748end
749
[12]750%------------------------------------------------------------------------
[177]751% --- Executes on button press in RUN: processing on local computer
[67]752function RUN_Callback(hObject, eventdata, handles)
753%------------------------------------------------------------------------
[73]754set(handles.RUN, 'Enable','Off')
755set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
[67]756batch=0;
[229]757errormsg=launch_jobs(hObject, eventdata, handles,batch);
[73]758set(handles.RUN, 'Enable','On')
759set(handles.RUN,'BackgroundColor',[1 0 0])
[36]760
[177]761% start status callback to visualise results
[229]762if ~isempty(errormsg)
763    display(errormsg)
764    msgbox_uvmat('ERROR',errormsg)
[282]765elseif  isfield(handles,'status') %&& ~isequal(get(handles.ListPairMode,'Value'),3)
[225]766    set(handles.status,'Value',1);%suppress status display
767    status_Callback(hObject, eventdata, handles)
[178]768end
[177]769
[12]770%------------------------------------------------------------------------
[2]771% --- Executes on button press in BATCH: remote processing
772function BATCH_Callback(hObject, eventdata, handles)
[177]773% -----------------------------------------------------------------------
[73]774set(handles.BATCH, 'Enable','Off')
775set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
[67]776batch=1;
[229]777errormsg=launch_jobs(hObject, eventdata, handles, batch);
[73]778set(handles.BATCH, 'Enable','On')
779set(handles.BATCH,'BackgroundColor',[1 0 0])
[67]780
[177]781% start status callback to visualise results
[229]782if ~isempty(errormsg)
783    display(errormsg)
784    msgbox_uvmat('ERROR',errormsg)
785elseif isfield(handles,'status')
786    set(handles.status,'Value',1);%suppress status display
787    status_Callback(hObject, eventdata, handles)
[178]788end
[227]789
[309]790%-------------------------------------------------------------------
791% --- Executes on button press in status.
792function status_Callback(hObject, eventdata, handles)
793%-------------------------------------------------------------------
794val=get(handles.status,'Value');
795if val==0
796    set(handles.status,'BackgroundColor',[0 1 0])
797    hfig=findobj(allchild(0),'name','civ_status');
798    if ~isempty(hfig)
799        delete(hfig)
800    end
801    return
802end
803set(handles.status,'BackgroundColor',[1 1 0])
804drawnow
805listtype={'civ1','fix1','patch1','civ2','fix2','patch2'};
806Param.CheckCiv1=get(handles.CheckCiv1,'Value');
807Param.CheckFix1=get(handles.CheckFix1,'Value');
808Param.CheckPatch1=get(handles.CheckPatch1,'Value');
809Param.CheckCiv2=get(handles.CheckCiv2,'Value');
810Param.CheckFix2=get(handles.CheckFix2,'Value');
811Param.CheckPatch2=get(handles.CheckPatch2,'Value');
812box_test=[Param.CheckCiv1 Param.CheckFix1 Param.CheckPatch1 Param.CheckCiv2 Param.CheckFix2 Param.CheckPatch2];
813
814option_civ=find(box_test,1,'last');%last selected option (non-zero index of box_test)
815filecell=get(handles.civ,'UserData');%retrieve the list of output files expected for PIV
816test_new=0;
817if ~isfield(filecell,'nc')
818    test_new=1;
819    [ref_i,ref_j,errormsg]=find_ref_indices(handles);
820    if ~isempty(errormsg)
821        msgbox_uvmat('ERROR',errormsg)
822        return
823    end
824    filecell=set_civ_filenames(handles,ref_i,ref_j,box_test);%determine the output file expected from the GUI status
825end
826if ~isequal(box_test(4:6),[0 0 0])
827    civ_files=filecell.nc.civ2;%case of civ2 operations
828else
829    civ_files=filecell.nc.civ1;
830end
831[root,filename,ext]=fileparts(civ_files{1});
832[rootroot,subdir,extdir]=fileparts(root);
833hfig=findobj(allchild(0),'name','civ_status');
834if isempty(hfig)
835    hfig=figure('DeleteFcn',@stop_status);
836    set(hfig,'name','civ_status')
837    hlist=uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.09 0.9 0.71], 'Callback', @open_view_field,'tag','list');
838    uicontrol('Style','edit','Units','normalized', 'Position', [0.05 0.87 0.9 0.1],'tag','msgbox','Max',2,'String','checking files...');
839    uicontrol('Style','frame','Units','normalized', 'Position', [0.05 0.81 0.9 0.05]);
840    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);
841    BarPosition=[0.05 0.81 0.01 0.05];
842    hwaitbar=uicontrol('Style','frame','Units','normalized', 'Position',BarPosition ,'BackgroundColor',[1 0 0],'tag','waitbar');
843    drawnow
844end
845% datnum=[];
846Tabchar={};
847nbfiles=numel(civ_files);
848count=0;
849testrecent=0;
850while count<nbfiles
851    count=0;
852    datnum=zeros(1,nbfiles);
853    for ifile=1:nbfiles
854        detect=exist(civ_files{ifile},'file'); % check the existence of the file
855        option=0;
856        if detect==0
857            option_str='not created';
858        else
859            datfile=dir(civ_files{ifile});
860            if isfield(datfile,'datenum')
861                datnum(ifile)=datfile.datenum;%only available in recent matlab versions
862                testrecent=1;
863            end
864            filefound(ifile)={datfile.name};
865            lastfield='';
866            % check the content  netcdf file
867            Data=nc2struct(civ_files{ifile},'ListGlobalAttribute','patch2','fix2','civ2','patch','fix');
868            if ~isempty(Data.patch2) && isequal(Data.patch2,1)
869                option=6;
870                option_str='patch2';
871            elseif ~isempty(Data.fix2) && isequal(Data.fix2,1)
872                option=5;
873                option_str='fix2';
874            elseif ~isempty(Data.civ2) && isequal(Data.civ2,1);
875                option=4;
876                option_str='civ2';
877            elseif ~isempty(Data.patch) && isequal(Data.patch,1);
878                option=3;
879                option_str='patch1';
880            elseif ~isempty(Data.fix) && isequal(Data.fix,1);
881                option=2;
882                option_str='fix1';
883            else
884                option=1;
885                option_str='civ1';
886            end
887        end
888        if option >= option_civ
889            count=count+1;
890        end
891        [rr,filename,ext]=fileparts(civ_files{ifile});
892        Tabchar{ifile,1}=[fullfile([subdir extdir],filename) ext  '...' option_str];
893    end
894    datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
895    if isempty(datnum)
896        if testrecent
897            message='no civ result created yet';
898        else
899            message='';
900        end
901    else
902        datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
903        [first,ind]=min(datnum);
904        [last,indlast]=max(datnum);
905        if test_new
906            message='existing file status, no processing launched yet';
907        else
908        message={[num2str(count) ' file(s) done over ' num2str(nbfiles)] ;['oldest modification:  ' cell2mat(filefound(ind)) ' : ' datestr(first)];...
909            ['latest modification:  ' cell2mat(filefound(indlast)) ' : ' datestr(last)]};
910        end
911    end
912    hfig=findobj(allchild(0),'name','civ_status');
913    if isempty(hfig)% the status list has been deleted
914        return
915    else
916        hlist=findobj(hfig,'tag','list');
917        hmsgbox=findobj(hfig,'tag','msgbox');
918        hwaitbar=findobj(hfig,'tag','waitbar');
919        set(hlist,'String',Tabchar)
920        set(hmsgbox,'String', message)
921        if count>0 && ~test_new
922            BarPosition(3)=0.9*count/nbfiles;
923            set(hwaitbar,'Position',BarPosition)
924        end
925    end
926    set(hlist,'UserData',rootroot)
[312]927    if count<10
928    pause(.5)% wait 0.5 seconds for next check
929    else
930        pause(10)% wait 10 seconds for next check
931    end
[309]932end
933
[67]934%------------------------------------------------------------------------
[309]935% --- Main lauch command, called by RUN and BATCH
[229]936function errormsg=launch_jobs(hObject, eventdata, handles, batch)
[67]937%-----------------------------------------------------------------------
[229]938errormsg='';%default
[309]939%% read the civ GUI
940Param=read_GUI(handles.civ);
[272]941
[133]942%% check the selected list of operations:
[289]943operations={'Civ1','Fix1','Patch1','Civ2','Fix2','Patch2'};
[282]944box_test=[Param.CheckCiv1 Param.CheckFix1 Param.CheckPatch1 Param.CheckCiv2 Param.CheckFix2 Param.CheckPatch2];
[284]945
[180]946index_first=find(box_test==1,1);
947if isempty(index_first)
[229]948    errormsg='no selected operation';
[2]949    return
950end
[180]951index_last=find(box_test==1,1,'last');
[159]952box_used=box_test(index_first : index_last);
[2]953[box_missing,ind_missing]=min(box_used);
[180]954if isequal(box_missing,0); %there is a missing step in the sequence of operations
[229]955    errormsg=['missing' cell2mat(operations(ind_missing))];
[2]956    return
957end
958
[272]959%% check mask if selecetd
960%could be included in get_mask callback ?
[282]961if isequal(get(handles.CheckMask,'Value'),1)
[276]962    maskname=get(handles.txt_MaskName,'String');
[12]963    if ~exist(maskname,'file')
964        get_mask_civ1_Callback(hObject, eventdata, handles);
965    end
[2]966end
[282]967if isequal(get(handles.CheckMask,'Value'),1)
968    maskname=get(handles.txt_MaskName,'String');
[12]969    if ~exist(maskname,'file')
970        get_mask_fix1_Callback(hObject, eventdata, handles);
971    end
[2]972end
[282]973if isequal(get(handles.CheckMask,'Value'),1)
[276]974    maskname=get(handles.txt_Mask,'String');
[12]975    if ~exist(maskname,'file')
[112]976        get_mask_civ2_Callback(hObject, eventdata, handles);
[12]977    end
[2]978end
[282]979if isequal(get(handles.CheckMask,'Value'),1)
[287]980    maskname=get(handles.txt_MaskName,'String');
[12]981    if ~exist(maskname,'file')
[112]982        get_mask_fix2_Callback(hObject, eventdata, handles);
[12]983    end
[2]984end
985
[177]986%% reinitialise status callback
[178]987if isfield(handles,'status')
[180]988    set(handles.status,'Value',0);%suppress status display
989    status_Callback(hObject, eventdata, handles)
[178]990end
[133]991
992%% set the list of files and check them
993display('checking the files...')
[227]994[ref_i,ref_j,errormsg]=find_ref_indices(handles);
995if ~isempty(errormsg)
996    return
997end
[263]998[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]999    set_civ_filenames(handles,ref_i,ref_j,box_test);
[274]1000% ADDED
1001   [Rootbat,Filebat]=fileparts(filecell.nc.civ1{1,1});%output netcdf file (without extention)
1002%ADDED
[177]1003set(handles.civ,'UserData',filecell);%store for futur use of status callback
[137]1004if isempty(filecell)% (error message displayed in fct set_civ_filenames)
[133]1005    return
1006end
1007nbfield=numel(num1_civ1);
1008nbslice=numel(num_a_civ1);
1009
[272]1010%% read the PARAM.xml file to get the binaries (and batch_mode if batch)
[276]1011path_civ=fileparts(which('civ')); %path to the source directory of uvmat
[112]1012xmlfile='PARAM.xml';
[133]1013if exist(xmlfile,'file')% search parameter xml file in the whole matlab path
[54]1014    t=xmltree(xmlfile);
[67]1015    s=convert(t);
[272]1016else
1017    errormsg=['no file ' xmlfile];
1018    return
[2]1019end
[272]1020test_interp=0; %eviter les variables test_ (LG)
[127]1021if batch
[67]1022    if isfield(s,'BatchParam')
[284]1023        Param.xml=s.BatchParam;
1024        if isfield(Param.xml,'BatchMode')
1025            batch_mode=Param.xml.BatchMode;
[257]1026            if ~ismember(batch_mode,{'sge','oar'})
1027                errormsg=['batch mode ' batch_mode ' not supported by UVMAT'];
1028                return
1029            end
[67]1030        end
1031    else
[229]1032        errormsg='no batch civ binaries defined in PARAM.xml';
[67]1033        return
1034    end
[257]1035else % run
[67]1036    if isfield(s,'RunParam')
[284]1037        Param.xml=s.RunParam;
[67]1038    else
[225]1039        msgbox_uvmat('ERROR','no run civ binaries defined in PARAM.xml')
[67]1040        return
1041    end
[225]1042end
[238]1043
[272]1044%% check batch mode supported
1045if batch
1046    switch batch_mode
1047        case 'sge'
1048            test_command='qstat';
1049        case 'oar'
[290]1050            test_command='oarstat';
[272]1051    end   
1052    [s,w]=system(test_command);
1053    if ~isequal(s,0)
1054        msgbox_uvmat('ERROR',[batch_mode ' batch system not available'])
1055        return
1056    end
1057end
1058
1059%% check if the binaries exist
[309]1060if isequal(get(handles.MenuMatlab,'checked'),'on')
[273]1061    CivMode='Matlab';
1062else
1063    CivMode='CivX';
1064end
[280]1065binary_list={};
[257]1066switch CivMode
[280]1067    case 'CivX'
1068        binary_list={'Civ1Bin','Civ2Bin','PatchBin','FixBin'};
1069    case 'CivAll'
[289]1070        binary_list={'Civ'};
[257]1071    case 'Matlab'
1072        if batch
[309]1073            % vérifier MenuMatlab installé sur le cluster
[272]1074            % difficile a faire a priori
[257]1075        end         
[225]1076end
[309]1077for bin_name=binary_list %loop on the list of binaries
1078    if isfield(Param.xml,bin_name{1})% bin_name{1} =current name in the list
[284]1079        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
[289]1080            fullname=fullfile(path_civ,Param.xml.(bin_name{1}));
[280]1081            if exist(fullname,'file')
[284]1082                Param.xml.(bin_name{1})=fullname;
[280]1083            else
[284]1084                msgbox_uvmat('ERROR',['Binary ' Param.xml.(bin_name{1}) ' defined in PARAM.xml does not exist'])
[280]1085                return
1086            end
1087        else
[284]1088            [path,name,ext]=fileparts(Param.xml.(bin_name{1}));
[280]1089            currentdir=pwd;
1090            cd(path);
1091            binpath=pwd;%path of the binary
[284]1092            Param.xml.(bin_name{1})=fullfile(binpath,[name ext]);
[280]1093            cd(currentdir);
1094        end
1095       
1096    end
1097end
[272]1098display('files OK, processing...')
[2]1099
1100
[133]1101%% MAIN LOOP
[273]1102time=get(handles.ImaDoc,'UserData'); %get the set of times
[134]1103super_cmd=[];
[269]1104batch_file_list=[];
[309]1105 
[2]1106for ifile=1:nbfield
1107    for j=1:nbslice
[257]1108        % initiate system command
1109        switch CivMode
1110            case 'CivX'
1111                if isunix % check: necessaire aussi en RUN?
[272]1112                    cmd=['#!/bin/bash \n '...
1113                        '#$ -cwd \n '...
1114                        'hostname && date \n '...
1115                        'umask 002 \n'];%allow writting access to created files for user group
1116                else
1117                    cmd=[];
[257]1118                end
1119            case 'CivAll'
1120                %         if CivAll
1121                CivAllxml=xmltree;% xml contents,  all parameters
1122                CivAllCmd='';
1123                CivAllxml=set(CivAllxml,1,'name','CivDoc');
[2]1124        end
[272]1125       
1126       
1127        % define output file name
[282]1128        if Param.CheckCiv2==1 || Param.CheckFix2==1 || Param.CheckPatch2==1
[272]1129            OutputFile=filecell.nc.civ2{ifile,j};
1130        else
1131            OutputFile=filecell.nc.civ1{ifile,j};
1132        end
1133        OutputFile=regexprep(OutputFile,'.nc','');
[309]1134       
[282]1135        if Param.CheckCiv1
[272]1136            % read image-dependent parameters
[284]1137            Param.Civ1.filename_ima_a=filecell.ima1.civ1{ifile,j};
1138            Param.Civ1.filename_ima_b=filecell.ima2.civ1{ifile,j};
[309]1139            if size(time,1)>=num2_civ1(ifile) && size(time,2)>=num_b_civ1(ifile)
[301]1140                Param.Civ1.Dt=(time(num2_civ1(ifile),num_b_civ1(j))-time(num1_civ1(ifile),num_a_civ1(j)));
1141                Param.Civ1.T0=((time(num2_civ1(ifile),num_b_civ1(j))+time(num1_civ1(ifile),num_a_civ1(j)))/2);
1142            else
1143                Param.Civ1.Dt=1;
1144                Param.Civ1.T0=0;
1145            end
[284]1146            Param.Civ1.term_a=num2stra(num_a_civ1(j),nom_type_nc);%UTILITE?
1147            Param.Civ1.term_b=num2stra(num_b_civ1(j),nom_type_nc);%
[285]1148            Param.Civ1.pxcmx=1; %velocities are expressed in pixel dispalcement
[309]1149            Param.Civ1.pxcmy=1;     
1150            Param.Civ1.ImageInfo=imfinfo(filecell.ima1.civ1{1,1});%read the first image to get the size
1151           
[285]1152            %TODO : civ should not need npx and npy
[309]1153           
[272]1154            % read mask parameters
[284]1155            if Param.Civ1.CheckMask % the lines below should be changed with the new gui
1156                %matbe they when check_mask the Maskname is read
[285]1157                if exist(Param.Civ1.MaskName,'file')
1158                    Param.Civ1.MaskFlag='y';
[2]1159                else
[285]1160                    maskbase=[filecell.filebase '_' Param.Civ1.MaskName]; %
[137]1161                    nbslice_mask=str2double(maskdispl(1:end-4)); %
[12]1162                    num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
[285]1163                    Param.Civ1.MaskName=name_generator(maskbase,num1_mask,1,'.png','_i');
1164                    if exist(Param.Civ1.MaskName,'file')
[284]1165                        Param.Civ1.maskflag='y';
[12]1166                    else
[285]1167                        Param.Civ1.MaskName='noFile use default';
1168                        Param.Civ1.MaskFlag='n';
[12]1169                    end
[2]1170                end
[272]1171            else
[285]1172                Param.Civ1.MaskName='noFile use default';
1173                Param.Civ1.MaskFlag='n';
[2]1174            end
[272]1175           
[282]1176            % read grid parameters=
[284]1177            if Param.Civ1.CheckGrid
[285]1178                Param.Civ1.GridFlag='y';
1179                if isequal(Param.Civ1.GridName(end-3:end),'grid')
1180                    nbslice_grid=str2double(Param.Civ1.GridName(1:end-4)); %
[137]1181                    if ~isnan(nbslice_grid)
[2]1182                        num1_grid=mod(num1_civ1(ifile)-1,nbslice_grid)+1;
[285]1183                        Param.Civ1.GridName=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
1184                        if ~exist(Param.Civ1.GridName,'file')
[112]1185                            msgbox_uvmat('ERROR','grid file absent for civ1')
[2]1186                        end
[285]1187                    elseif ~exist(Param.Civ1.GridName,'file')
[2]1188                        msgbox_uvmat('ERROR','grid file absent for civ1')
1189                    end
1190                end
1191            else
[285]1192                Param.Civ1.GridName='noFile use default';
1193                Param.Civ1.GridFlag='n';
[2]1194            end
[257]1195           
[285]1196            % send command
[257]1197            switch CivMode
1198                case 'CivX'
[284]1199                    cmd=[cmd...
1200                        cmd_civ1(filecell.nc.civ1{ifile,j},Param) '\n'];
[257]1201                case 'CivAll'
1202                    CivAllCmd=[CivAllCmd ' civ1 '];
[284]1203                    str=CIV1_CMD_Unified(filecell.nc.civ1{ifile,j},'',Param.Civ1);
[257]1204                    fieldnames=fields(str);
1205                    [CivAllxml,uid_civ1]=add(CivAllxml,1,'element','civ1');
1206                    for ilist=1:length(fieldnames)
1207                        val=eval(['str.' fieldnames{ilist}]);
1208                        if ischar(val)
1209                            [CivAllxml,uid_t]=add(CivAllxml,uid_civ1,'element',fieldnames{ilist});
1210                            [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
1211                        end
[112]1212                    end
[2]1213            end
1214        end
1215       
[282]1216        if Param.CheckFix1
[309]1217            switch CivMode
[257]1218                case 'CivX'
[285]1219                    cmd=[cmd...
1220                        cmd_fix(filecell.nc.civ1{ifile,j},Param,'Fix1') '\n'];
[257]1221                case 'CivAll'
1222                    fix1.inputFileName=filecell.nc.civ1{ifile,j} ;
[272]1223                    fix1.fi1=num2str(param.fix1.flagindex1(1));
1224                    fix1.fi2=num2str(param.fix1.flagindex1(2));
1225                    fix1.fi3=num2str(param.fix1.flagindex1(3));
1226                    fix1.threshC=num2str(param.fix1.thresh_vecC1);
1227                    fix1.threshV=num2str(param.fix1.thresh_vel1);
[257]1228                    fieldnames=fields(fix1);
1229                    [CivAllxml,uid_fix1]=add(CivAllxml,1,'element','fix1');
1230                    for ilist=1:length(fieldnames)
1231                        val=eval(['fix1.' fieldnames{ilist}]);
1232                        if ischar(val)
1233                            [CivAllxml,uid_t]=add(CivAllxml,uid_fix1,'element',fieldnames{ilist});
1234                            [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
1235                        end
1236                    end
1237                    CivAllCmd=[CivAllCmd ' fix1 '];
[112]1238            end
1239        end
1240       
[282]1241        %CheckPatch1
1242        if Param.CheckPatch1==1
[257]1243            switch CivMode
1244                case 'CivX'
[286]1245                    cmd=[cmd...
1246                        cmd_patch(filecell.nc.civ1{ifile,j},Param,'Patch1') '\n'];
[257]1247                case 'CivAll'
1248                    patch1.inputFileName=filecell.nc.civ1{ifile,j} ;
1249                    patch1.nopt=subdomain_patch1;
1250                    patch1.maxdiff=thresh_patch1;
1251                    patch1.ro=rho_patch1;
1252                    test_grid=get(handles.get_gridpatch1,'Value');
1253                    if test_grid
1254                        patch1.gridflag='y';
1255                        gridname=get(handles.grid_patch1,'String');
1256                        if isequal(gridname(end-3:end),'grid')
1257                            nbslice_grid=str2double(gridname(1:end-4)); %
1258                            if ~isnan(nbslice_grid)
1259                                num1_grid=mod(num1_civ1(ifile)-1,nbslice_grid)+1;
1260                                patch1.gridPatch=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
1261                                if ~exist(patch1.gridPatch,'file')
1262                                    msgbox_uvmat('ERROR','grid file absent for patch1')
1263                                end
1264                            elseif exist(gridname,'file')
1265                                patch1.gridPatch=gridname;
1266                            else
[112]1267                                msgbox_uvmat('ERROR','grid file absent for patch1')
1268                            end
[2]1269                        end
[257]1270                    else
1271                        patch1.gridPatch='none';
1272                        patch1.gridflag='n';
1273                        patch1.m=nx_patch1;
1274                        patch1.n=ny_patch1;
[2]1275                    end
[257]1276                    patch1.convectFlow='n';
1277                    fieldnames=fields(patch1);
1278                    [CivAllxml,uid_patch1]=add(CivAllxml,1,'element','patch1');
1279                    for ilist=1:length(fieldnames)
1280                        val=eval(['patch1.' fieldnames{ilist}]);
1281                        if ischar(val)
1282                            [CivAllxml,uid_t]=add(CivAllxml,uid_patch1,'element',fieldnames{ilist});
1283                            [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
1284                        end
[112]1285                    end
[257]1286                    CivAllCmd=[CivAllCmd ' patch1 '];
[112]1287            end
[2]1288        end
[282]1289        if Param.CheckCiv2==1
[290]1290            Param.Civ2.filename_ima_a=filecell.ima1.civ2{ifile,j};
[309]1291            Param.Civ2.filename_ima_b=filecell.ima2.civ2{ifile,j};
1292            if size(time,1)>=num2_civ2(ifile) && size(time,2)>=num_b_civ2(ifile)
[301]1293                Param.Civ2.Dt=num2str(time(num2_civ2(ifile),num_b_civ2(j))-time(num1_civ2(ifile),num_a_civ2(j)));
[309]1294                Param.Civ2.T0=num2str((time(num2_civ2(ifile),num_b_civ2(j))+time(num1_civ2(ifile),num_a_civ2(j)))/2);
[301]1295            else
1296                Param.Civ2.Dt=1;
1297                Param.Civ2.T0=0;
[309]1298            end
[290]1299            Param.Civ2.term_a=num2stra(num_a_civ2(j),nom_type_nc);
1300            Param.Civ2.term_b=num2stra(num_b_civ2(j),nom_type_nc);
1301            Param.Civ2.filename_nc1=filecell.nc.civ1{ifile,j};
1302            Param.Civ2.filename_nc1(end-2:end)=[]; % remove '.nc'
1303            Param.Civ2.pxcmx=1; %velocities are expressed in pixel dispalcement
1304            Param.Civ2.pxcmy=1;
[287]1305            if Param.Civ2.CheckMask
[276]1306                maskdispl=get(handles.txt_Mask,'String');
[12]1307                if exist(maskdispl,'file')
[290]1308                    Param.Civ2.MaskName=maskdispl;
1309                    Param.Civ2.MaskFlag='y';
[2]1310                else
[136]1311                    maskbase=[filecell.filebase '_' maskdispl]; %
[137]1312                    nbslice_mask=str2double(maskdispl(1:end-4)); %
[12]1313                    num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
[290]1314                    Param.Civ2.MaskName=name_generator(maskbase,num1_mask,1,'.png','_i');
1315                    if exist(Param.Civ2.MaskName,'file')
1316                        Param.Civ2.MaskFlag='y';
[12]1317                    else
[290]1318                        Param.Civ2.MaskName='noFile use default';
1319                        Param.Civ2.MaskFlag='n';
[12]1320                    end
[2]1321                end
[287]1322            else
[290]1323                Param.Civ2.MaskName='noFile use default';
1324                Param.Civ2.MaskFlag='n';
[2]1325            end
[276]1326            gridname=get(handles.txt_GridName,'String');
[2]1327            if numel(gridname)>=4 && isequal(gridname(end-3:end),'grid')
[137]1328                nbslice_grid=str2double(gridname(1:end-4)); %
1329                if ~isnan(nbslice_grid)
[290]1330                    Param.Civ2.GridFlag='y';
[2]1331                    num1_grid=mod(num1_civ2(ifile)-1,nbslice_grid)+1;
[290]1332                    Param.Civ2.GridName=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
1333                    if exist(Param.Civ2.GridName,'file')
1334                        Param.Civ2.GridFlag='y';
[2]1335                    else
[290]1336                        Param.Civ2.GridName='noFile use default';
1337                        Param.Civ2.GridFlag='n';
[2]1338                    end
1339                elseif exist(gridname,'file')
[290]1340                    Param.Civ2.GridFlag='y';
[2]1341                else
[290]1342                    Param.Civ2.GridName='noFile use default';
1343                    Param.Civ2.GridFlag='n';
[2]1344                end
[290]1345            else
1346                Param.Civ2.GridName='noFile use default';
1347                Param.Civ2.GridFlag='n';
[2]1348            end
[309]1349%             A=imread(filecell.ima1.civ2{1,1});%read the first image to get the size
1350%             sizim=size(A);
1351            Param.Civ2.ImageInfo=imfinfo(filecell.ima1.civ1{1,1});%read the first image to get the size
1352%             Param.Civ2.npx=(sizim(2));
1353%             Param.Civ2.npy=(sizim(1));     
[257]1354            switch CivMode
1355                case 'CivX'
[309]1356                    cmd=[cmd...
[290]1357                        cmd_civ2(filecell.nc.civ2{ifile,j},Param) '\n'];
[257]1358                case 'CivAll'
1359                    CivAllCmd=[CivAllCmd ' civ2 '];
[290]1360                    str=CIV2_CMD_Unified(filecell.nc.civ2{ifile,j},'',Param.Civ2);
[257]1361                    fieldnames=fields(str);
1362                    [CivAllxml,uid_civ2]=add(CivAllxml,1,'element','civ2');
1363                    for ilist=1:length(fieldnames)
1364                        val=eval(['str.' fieldnames{ilist}]);
1365                        if ischar(val)
1366                            [CivAllxml,uid_t]=add(CivAllxml,uid_civ2,'element',fieldnames{ilist});
1367                            [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
1368                        end
[2]1369                    end
1370            end
[112]1371        end
1372       
[282]1373        % CheckFix2
1374        if Param.CheckFix2==1
[257]1375            switch CivMode
1376                case 'CivX'
[291]1377                    cmd=[cmd...
1378                        cmd_fix(filecell.nc.civ2{ifile,j},Param,'Fix2') '\n'];
[257]1379                case 'CivAll'
1380                    fix2.inputFileName=filecell.nc.civ2{ifile,j} ;
1381                    fix2.fi1=num2str(flagindex2(1));
1382                    fix2.fi2=num2str(flagindex2(2));
1383                    fix2.fi3=num2str(flagindex2(3));
1384                    fix2.threshC=num2str(thresh_vec2C);
1385                    fix2.threshV=num2str(thresh_vel2);
1386                    fieldnames=fields(fix2);
1387                    [CivAllxml,uid_fix2]=add(CivAllxml,1,'element','fix2');
1388                    for ilist=1:length(fieldnames)
1389                        val=eval(['fix2.' fieldnames{ilist}]);
1390                        if ischar(val)
1391                            [CivAllxml,uid_t]=add(CivAllxml,uid_fix2,'element',fieldnames{ilist});
1392                            [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
1393                        end
1394                    end
1395                    CivAllCmd=[CivAllCmd ' fix2 '];
[112]1396            end
1397        end
1398       
[282]1399        %CheckPatch2
1400        if Param.CheckPatch2==1
[257]1401            switch CivMode
1402                case 'CivX'
[291]1403                    cmd=[cmd...
1404                        cmd_patch(filecell.nc.civ1{ifile,j},Param,'Patch2') '\n'];
[257]1405                case 'CivAll'
1406                    patch2.inputFileName=filecell.nc.civ1{ifile,j} ;
1407                    patch2.nopt=subdomain_patch2;
1408                    patch2.maxdiff=thresh_patch2;
1409                    patch2.ro=rho_patch2;
1410                    test_grid=get(handles.get_gridpatch2,'Value');
1411                    if test_grid
1412                        patch2.gridflag='y';
1413                        gridname=get(handles.grid_patch2,'String');
1414                        if isequal(gridname(end-3:end),'grid')
1415                            nbslice_grid=str2double(gridname(1:end-4)); %
1416                            if ~isnan(nbslice_grid)
1417                                num1_grid=mod(num1_civ2(ifile)-1,nbslice_grid)+1;
1418                                patch2.gridPatch=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
1419                                if ~exist(patch2.gridPatch,'file')
1420                                    msgbox_uvmat('ERROR','grid file absent for patch2')
1421                                end
1422                            elseif exist(gridname,'file')
1423                                patch2.gridPatch=gridname;
1424                            else
[112]1425                                msgbox_uvmat('ERROR','grid file absent for patch2')
[12]1426                            end
[2]1427                        end
[257]1428                    else
1429                        patch2.gridPatch='none';
1430                        patch2.gridflag='n';
1431                        patch2.m=nx_patch2;
1432                        patch2.n=ny_patch2;
[2]1433                    end
[257]1434                    patch2.convectFlow='n';
1435                    fieldnames=fields(patch2);
1436                    [CivAllxml,uid_patch2]=add(CivAllxml,1,'element','patch2');
1437                    for ilist=1:length(fieldnames)
1438                        val=eval(['patch2.' fieldnames{ilist}]);
1439                        if ischar(val)
1440                            [CivAllxml,uid_t]=add(CivAllxml,uid_patch2,'element',fieldnames{ilist});
1441                            [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
1442                        end
[112]1443                    end
[257]1444                    CivAllCmd=[CivAllCmd ' patch2 '];
[112]1445            end
[12]1446        end
[309]1447       
[257]1448        switch CivMode
1449            case {'CivX','CivAll'}
1450                if isequal(CivMode,'CivAll')
[272]1451                    save(CivAllxml,[OutputFile '.xml']);
1452                    cmd=[cmd sparam.CivBin ' -f ' OutputFile '.xml '  CivAllCmd ' >' OutputFile '.log' '\n'];
[238]1453                end
[272]1454               
1455                % create the .bat file used in run or batch
1456                filename_bat=[OutputFile '.bat'];
[257]1457                [fid,message]=fopen(filename_bat,'w');
1458                if isequal(fid,-1)
1459                    msgbox_uvmat('ERROR', ['creation of .bat file: ' message])
1460                    return
[238]1461                end
[257]1462                fprintf(fid,cmd);
1463                fclose(fid);
[269]1464               
[279]1465                if isunix
1466                    system(['chmod +x ' filename_bat]);
1467                end
1468               
[269]1469                batch_file_list{length(batch_file_list)+1}=filename_bat;
1470               
[257]1471            case 'Matlab'
1472                drawnow
[263]1473                if ~strcmp(compare,'stereo PIV')
[309]1474                    [Data,erromsg]=civ_matlab(Param,filecell.nc.civ1{ifile,j});
[263]1475                    if isempty(errormsg)
1476                        display([filecell.nc.civ1{ifile,j} ' written'])
1477                    else
1478                        msgbox_uvmat('ERROR',errormsg)
[309]1479                    end                 
[263]1480                end
[257]1481        end
[112]1482    end
[2]1483end
[134]1484
[265]1485if batch
[269]1486    switch batch_mode                       
1487        case 'sge'
1488            for p=1:length(batch_file_list)
1489                cmd=['!qsub -p ' pvalue ' -q civ.q -e ' flname '.errors -o ' flname '.log' ' ' batch_file_list{p}];
1490                display(cmd);eval(cmd);
1491            end
[279]1492        case 'oar_old'
1493                for p=1:length(batch_file_list)
1494                    oar_command=['!oarsub -n CIVX -q nicejob '...
1495                   '-E ' regexprep(batch_file_list{p},'.bat','.errors') ' -O ' regexprep(batch_file_list{p},'.bat','.log ')...
1496                    '-l "/core=1+{type = ''smalljob''}/licence=1,walltime=00:60:00"   ' batch_file_list{p}];
1497                display(oar_command);eval(oar_command);
[311]1498                end   
1499       case 'oar' %oar-dispatch.pl
1500           oar_modes={'oar-dispatch','mpilauncher'};
[312]1501           text={'Batch processing on servcalcul3 LEGI';...
1502               'Please choose one of the followint modes';...
1503               '* oar-dispatch : jobs in a container';...
1504               '* mpilauncher : one single job using several cores';...
1505               '**********************************'...
[311]1506               };
1507           [S,v]=listdlg('PromptString',text,'ListString',oar_modes,...
[312]1508               'SelectionMode','single','ListSize',[400 100],'Name','LEGI job mode');
1509           switch oar_modes{S}
[311]1510               
[312]1511               case 'oar-dispatch' %oar-dispatch.pl
[311]1512                   filename_joblist=fullfile(Rootbat,'job_list.txt');
1513                   fid=fopen(filename_joblist,'w');
1514                   walltime_onejob=600;%seconds
1515                   for p=1:length(batch_file_list)
1516                       oar_command=['oarsub -n CIVX '...
1517                           '-E ' regexprep(batch_file_list{p},'\.bat\>','.errors') ' -O ' regexprep(batch_file_list{p},'\.bat\>','.log ')...
1518                           '-l "/core=1,walltime=' datestr(walltime_onejob/86400,13) '"   ' batch_file_list{p}];
1519                       fprintf(fid,[oar_command '\n']);
1520                   end
1521                   fclose(fid);
1522                   ncores=36;
1523                   oar_command=['oarsub -t container -n civx-container '...
1524                       '-l /core=' num2str(ncores)...
1525                       ',walltime=' datestr(1.05*walltime_onejob/86400*max(length(batch_file_list),ncores)/ncores,13)...
1526                       ' "oar-dispatch -f ' filename_joblist '"'];
1527                   filename_oarcommand=fullfile(Rootbat,'oar_command');
1528                   fid=fopen(filename_oarcommand,'w');
1529                   fprintf(fid,[oar_command '\n']);
1530                   fclose(fid);
1531                   display(oar_command);
1532                   eval(['! . ' filename_oarcommand])
1533               case 'mpilauncher'
1534                   filename_joblist=fullfile(Rootbat,'job_list.txt');
1535                   fid=fopen(filename_joblist,'w');
1536                   
1537                   for p=1:length(batch_file_list)
1538                       fprintf(fid,[batch_file_list{p} '\n']);
1539                   end
1540                   fclose(fid)
1541                   text_oarscript=[...
1542                       '#!/bin/bash \n'...
1543                       '#OAR -n Mylauncher \n'...
1544                       '#OAR -l node=4/core=5,walltime=0:15:00 \n'...
1545                       '#OAR -E stderrfile.log \n'...
1546                       '#OAR -O stdoutfile.log \n'...
1547                       '# ========================================================= \n'...
1548                       '# This simple program launch a multinode parallel OpenMPI mpilauncher \n'...
1549                       '# application for coriolis PIV post-processing. \n'...
1550                       '# OAR uses oarshmost wrapper to propagate the user environement. \n'...
1551                       '# This wrapper assert that the user has the same environment on all the \n'...
1552                       '# allocated nodes (basic behavior needed by most MPI applications).  \n'...
1553                       '# \n'...
1554                       '# REQUIREMENT: \n'...
1555                       '# the oarshmost wrapper should be installed in $HOME/bin directory. \n'...
1556                       '# If a different location is used, change the line following the comment "Bidouille" \n'...
1557                       '# ========================================================= \n'...
1558                       '#   USER should only modify these 2 lines  \n'...
1559                       'WORKDIR=' pwd ' \n'...
1560                       'COMMANDE="mpilauncher  -f ' filename_joblist '" \n'...
1561                       '# ========================================================= \n'...
1562                       '# DO NOT MODIFY the FOLOWING LINES. (or be carefull) \n'...
1563                       'echo "job starting on: "`hostname` \n'...
1564                       'MPINODES="-host `tr [\\\\\\n] [,] <$OAR_NODEFILE |sed -e "s/,$/ /"`" \n'...
1565                       'NCPUS=`cat $OAR_NODEFILE |wc -l` \n'...
1566                       '#========== Bidouille ============== \n'...
1567                       'export OMPI_MCA_plm_rsh_agent=oar-envsh \n'...%                     'cd $WORKDIR \n'...
1568                       'CMD="mpirun -np $NCPUS -wdir $WORKDIR $MPINODES $COMMANDE" \n'...
1569                       'echo "I run: $CMD"  \n'...
1570                       '$CMD \n'...
1571                       'echo "job ending" \n'...
1572                       ];
1573                   %                 oarsub -S ./oar.sub
1574                   filename_oarscript=fullfile(Rootbat,'oar_command');
1575                   fid=fopen(filename_oarscript,'w');
1576                   fprintf(fid,[text_oarscript]);
1577                   fclose(fid);
1578                   eval(['!chmod +x  ' filename_oarscript]);
1579                   eval(['!oarsub -S ' filename_oarscript]);
1580           end
[269]1581    end
1582else
1583    if ~isequal(CivMode,'Matlab')
1584        filename_superbat=fullfile(Rootbat,'job_list.bat');
1585        fid=fopen(filename_superbat,'w');
1586        if fid==-1
1587            msgbox_uvmat('ERROR',['cannot create the command file ' filename_superbat])
1588            return
1589        end
1590        for p=1:length(batch_file_list)
1591            if isunix
1592                fprintf(fid,['sh ' batch_file_list{p} '\n']);
1593            else
1594                fprintf(fid,['@call "' regexprep(filename_bat,'\\','\\\\') '"' '\n']);
[265]1595            end
[269]1596        end
1597        fclose(fid);
1598        if(isunix)
1599            system(['chmod +x ' filename_superbat]);
1600        end
1601        system([filename_superbat ' &']);% execute main commmand
[265]1602    end
[269]1603   
[265]1604end
1605
[2]1606
[137]1607%% save interface state
[2]1608if isfield(filecell,'nc')
1609    if isfield(filecell.nc,'civ2')
1610        fileresu=filecell.nc.civ2{1,1};
1611    else
1612        fileresu=filecell.nc.civ1{1,1};
1613    end
1614end
1615[RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileresu);
1616namedoc=fullfile(RootPath,subdir,RootFile);
[112]1617detect=1;
[2]1618while detect==1
1619    namefigfull=[namedoc '.fig'];
1620    hh=dir(namefigfull);
1621    if ~isempty(hh)
1622        detect=1;
1623        namedoc=[namedoc '.0'];
1624    else
1625        detect=0;
1626    end
1627end
1628saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
1629
[273]1630%Save info in personal profile (initiate browser next time) TODO
1631MenuFile={};
1632dir_perso=prefdir;
1633profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1634if exist(profil_perso,'file')
1635    hh=load (profil_perso);
1636      if isfield(hh,'MenuFile')
1637          MenuFile=hh.MenuFile;
1638      end
[289]1639      if isfield(filecell.nc,'civ2')
1640          MenuFile=[filecell.nc.civ2{1,1}; MenuFile];
1641      else
1642           MenuFile=[filecell.nc.civ1{1,1}; MenuFile];
1643      end
[273]1644      save (profil_perso,'MenuFile','-append'); %store the file names for future opening of uvmat
1645else
1646    MenuFile=filecell.ima1.civ1(1,1);
1647    save (profil_perso,'MenuFile')
1648end
1649
[227]1650%------------------------------------------------------------------------
1651% --- determine the list of reference indices of processing file
1652function [ref_i,ref_j,errormsg]=find_ref_indices(handles)
1653%------------------------------------------------------------------------
1654errormsg=''; %default error message
1655first_i=str2double(get(handles.first_i,'String'));%first index i
1656last_i=str2double(get(handles.last_i,'String'));%last index i
1657incr_i=str2double(get(handles.incr_i,'String'));% increment
1658if isequal(get(handles.first_j,'Visible'),'on')
1659    first_j=str2double(get(handles.first_j,'String'));%first index j
1660    last_j=str2double(get(handles.last_j,'String'));%last index j
1661    incr_j=str2double(get(handles.incr_j,'String'));% increment
1662else
1663    first_j=1;
1664    last_j=1;
1665    incr_j=1;
1666end
1667ref_i=first_i:incr_i:last_i;% list of i indices (reference values for each pair)
1668ref_j=first_j:incr_j:last_j;% list of j indices (reference values for each pair)
1669if isnan(first_i)||isnan(first_j)
1670    errormsg='first field number not defined';
1671elseif isnan(last_i)||isnan(last_j)
1672    errormsg='last field number not defined';
1673elseif isnan(incr_i)||isnan(incr_j)
1674    errormsg='increment in field number not defined';
1675elseif last_i < first_i || last_j < first_j
1676    errormsg='last field number must be larger than the first one';
1677end
[134]1678
[227]1679%------------------------------------------------------------------------
1680% --- determine the list of filenames and indices needed for launch_job
[263]1681function [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]1682    set_civ_filenames(handles,ref_i,ref_j,checkbox)
[12]1683%------------------------------------------------------------------------
[85]1684filecell=[];%default
[136]1685
1686%% get the root names nomenclature and numbers
[71]1687filebase=get(handles.RootName,'String');
[136]1688
1689if isempty(filebase)||isequal(filebase,'')
[298]1690    msgbox_uvmat('ERROR','please open an image with the upper menu option Open/Browse...')
[136]1691    return
1692end
1693
[137]1694%filebase=regexprep(filebase,'\.fsnet','fsnet');% temporary fix for cluster Coriolis
[136]1695filecell.filebase=filebase;
1696
[273]1697browse=get(handles.RootName,'UserData');
[282]1698compare_list=get(handles.ListCompareMode,'String');
1699val=get(handles.ListCompareMode,'Value');
[2]1700compare=compare_list{val};
1701if strcmp(compare,'displacement')
1702    mode='displacement';
1703else
[282]1704    mode_list=get(handles.ListPairMode,'String');
1705    mode_value=get(handles.ListPairMode,'Value');
[2]1706    mode=mode_list{mode_value};
1707end
[137]1708%time=get(handles.RootName,'UserData'); %get the set of times
[71]1709ext_ima=get(handles.ImaExt,'String');
[2]1710nom_type_nc=browse.nom_type_nc;
[122]1711if isfield(browse,'nom_type_ima')
1712    nom_type_ima2=browse.nom_type_ima;
1713end
1714if isempty(nom_type_ima2),nom_type_ima2='1';end; %default
1715if isempty(nom_type_nc),nom_type_nc='_i1-i2';end; %default
[2]1716[num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
[227]1717    find_pair_indices(handles,ref_i,ref_j,mode);
[282]1718%determine the new filebase for 'displacement' ListPairMode (comparison of two series)
[2]1719filebase_B=filebase;% root name of the second field series for stereo
1720if strcmp(compare,'displacement') || strcmp(compare,'stereo PIV')
[127]1721%     test_disp=1;
[2]1722    nom_type_ima1=browse.nom_type_ima_1; %nomenclature type of the second file series
1723    [Path2,Name2]=fileparts(filebase_B);
1724    Path1=Path2;
[71]1725    Name1=get(handles.RootName_1,'String');% root name of the first field series for stereo
[2]1726    filebase_A=fullfile(Path1,Name1);
1727    if length(Name1)>6
1728        Name1=Name1(end-5:end);
1729    end
1730    if length(Name2)>6
1731        Name2=Name2(end-5:end);
1732    end
1733    filebase_AB=fullfile(Path2,[Name2 '-' Name1]);
1734else
[127]1735%     test_disp=0;
[2]1736    filebase_A=filebase;
1737    nom_type_ima1=nom_type_ima2;
1738    filebase_AB=filebase;
1739end
1740if strcmp(compare,'displacement')
[112]1741    filebase_ima1=filebase_A;
1742    filebase_ima2=filebase_B;
1743    filebase_nc=filebase_AB; %root name for the result of civ2
[2]1744else
[112]1745    filebase_ima1=filebase_B;
1746    filebase_ima2=filebase_B;
1747    filebase_nc=filebase_B;
1748end
[2]1749
1750%determine reference files for fix:
1751file_ref_fix1={};%default
1752file_ref_fix2={};
1753nbfield=length(num1_civ1);
1754nbslice=length(num_a_civ1);
[282]1755if checkbox(2)==1% fix1 performed
[2]1756    ref=get(handles.ref_fix1,'UserData');%read data on the ref file stored by get_ref_fix1_Callback
1757    if ~isempty(ref)
[137]1758        first_i=str2double(get(handles.first_i,'String'));
1759        last_i=str2double(get(handles.last_i,'String'));
1760        incr_i=str2double(get(handles.incr_i,'String'));
1761        first_j=str2double(get(handles.first_j,'String'));
1762        last_j=str2double(get(handles.last_j,'String'));
1763        incr_j=str2double(get(handles.incr_j,'String'));
[127]1764        num_i_ref=first_i:incr_i:last_i;
1765        num_j_ref=first_j:incr_j:last_j;
[2]1766        if isequal(mode,'displacement')
1767            num_i1=num_i_ref;
1768            num_i2=num_i_ref;
1769            num_j1=num_j_ref;
1770            num_j2=num_j_ref;
1771        elseif isequal(mode,'pair j1-j2')% isequal(mode,'st_pair j1-j2')
1772            num_i1=num_i_ref;
1773            num_i2=num_i1;
1774            num_j1=ref.num_a*ones(size(num_i_ref));
1775            num_j2=ref.num_b*ones(size(num_i_ref));
1776        elseif isequal(mode,'series(Di)') % isequal(mode,'st_series(Di)')
1777            delta1=floor((ref.num2-ref.num1)/2);
1778            delta2=ceil((ref.num2-ref.num1)/2);
1779            num_i1=num_i_ref-delta1*ones(size(num_i_ref));
1780            num_i2=num_i_ref+delta2*ones(size(num_i_ref));
1781            if isempty(ref.num_a)
1782                ref.num_a=1;
1783            end
1784            num_j1=ref.num_a*ones(size(num_i1));
1785            num_j2=num_j1;
1786        elseif isequal(mode,'series(Dj)')%| isequal(mode,'st_series(Dj)')
1787            delta1=floor((ref.num_b-ref.num_a)/2);
1788            delta2=ceil((ref.num_b-ref.num_a)/2);
1789            num_i1=ref.num1*ones(size(num_i_ref));
1790            num_i2=num_i1;
1791            num_j1=num_j_ref-delta1*ones(size(num_j_ref));
1792            num_j2=num_j_ref+delta2*ones(size(num_j_ref));
1793        end
1794        for ifile=1:nbfield
1795            for j=1:nbslice
1796                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);%
1797                file_ref_fix1(ifile,j)={file_ref};
1798                if ~exist(file_ref,'file')
1799                    msgbox_uvmat('ERROR',['reference file ' file_ref ' not found for fix1'])
[12]1800                    filecell=[];
[2]1801                    return
1802                end
1803            end
1804        end
1805    end
1806end
1807
[282]1808%determine reference files for checkfix2:
1809if checkbox(5)==1% fix2 performed
[2]1810    ref=get(handles.ref_fix2,'UserData');
1811    if ~isempty(ref)
[127]1812        first_i=str2double(get(handles.first_i,'String'));
1813        last_i=str2double(get(handles.last_i,'String'));
1814        incr_i=str2double(get(handles.incr_i,'String'));
1815        first_j=str2double(get(handles.first_j,'String'));
1816        last_j=str2double(get(handles.last_j,'String'));
1817        incr_j=str2double(get(handles.incr_j,'String'));
[229]1818        num_i_ref=first_i:incr_i:last_i;
1819        num_j_ref=first_j:incr_j:last_j;
[2]1820        if isequal(mode,'displacement')
1821            num_i1=num_i_ref;
1822            num_i2=num_i_ref;
1823            num_j1=num_j_ref;
1824            num_j2=num_j_ref;
1825        elseif isequal(mode,'pair j1-j2')
1826            num_i1=num_i_ref;
1827            num_i2=num_i1;
1828            num_j1=ref.num_a;
1829            num_j2=ref.num_b;
1830        elseif isequal(mode,'series(Di)')
1831            delta1=floor((ref.num2-ref.num1)/2);
1832            delta2=ceil((ref.num2-ref.num1)/2);
1833            num_i1=num_i_ref-delta1*ones(size(num_i_ref));
1834            num_i2=num_i_ref+delta2*ones(size(num_i_ref));
1835            num_j1=ref.num_a*ones(size(num_i1));
1836            num_j2=num_j1;
1837        elseif isequal(mode,'series(Dj)')
1838            delta1=floor((ref.num_b-ref.num_a)/2);
1839            delta2=ceil((ref.num_b-ref.num_a)/2);
1840            num_i1=ref.num1*ones(size(num_i_ref));
1841            num_i2=num_i1;
1842            num_j1=num_j_ref-delta1*ones(size(num_j_ref));
1843            num_j2=num_j_ref+delta2*ones(size(num_j_ref));
1844        end
1845        for ifile=1:nbfield
1846            for j=1:nbslice
1847                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);%
1848                file_ref_fix2(ifile,j)={file_ref};
1849                if ~exist(file_ref,'file')
1850                    msgbox_uvmat('ERROR',['reference file ' file_ref ' not found for fix2'])
[122]1851                    filecell={};
[2]1852                    return
1853                end
1854            end
1855        end
1856    end
1857end
1858
1859%check dir
[289]1860subdir_civ1=get(handles.txt_SubdirCiv1,'String');%subdirectory subdir_civ1 for the netcdf output data
1861subdir_civ2=get(handles.txt_SubdirCiv2,'String');
[174]1862if isequal(subdir_civ1,''),subdir_civ1='CIV'; end% put default subdir
[2]1863if isequal(subdir_civ2,''),subdir_civ2=subdir_civ1; end% put default subdir
[266]1864% currentdir=pwd;%store the current working directory
[2]1865[Path_ima,Name]=fileparts(filebase);%Path of the image files (.civ)
1866if ~exist(Path_ima,'dir')
[12]1867    msgbox_uvmat('ERROR',['path to images ' Path_ima ' not found'])
[122]1868    filecell={};
[2]1869    return
1870end
[127]1871[xx,message]=fileattrib(Path_ima);
[122]1872if ~isempty(message) && ~isequal(message.UserWrite,1)
[112]1873    msgbox_uvmat('ERROR',['No writting access to ' Path_ima])
[122]1874    filecell={};
[266]1875%     cd(currentdir);
[112]1876    return
[2]1877end
1878
1879%check the existence of the netcdf and image files involved
[282]1880% %%%%%%%%%%%%  case CheckCiv1 activated   %%%%%%%%%%%%%
1881if checkbox(1)==1;
[112]1882    detect=1;
[127]1883    vers=0;
1884    subdir_civ1_new=subdir_civ1;
[153]1885    while detect==1 %create a new subdir if the netcdf files already exist
[122]1886        for ifile=1:nbfield
[112]1887            for j=1:nbslice
[122]1888                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]1889                detect=exist(filename,'file')==2;
1890                if detect% if a netcdf file already exists
[137]1891                    indstr=regexp(subdir_civ1_new,'\D');
1892                    if indstr(end)<length(subdir_civ1_new) %subdir_civ1 ends by a number
1893                        vers=str2double(subdir_civ1_new(indstr(end)+1:end))+1;
1894                        subdir_civ1_new=[subdir_civ1_new(1:indstr(end)) num2str(vers)];
[127]1895                    else
1896                        vers=vers+1;
[137]1897                        subdir_civ1_new=[subdir_civ1_new(1:indstr(end)) '_' num2str(vers)];       
[127]1898                    end
[137]1899                    subdir_civ2=subdir_civ1_new;
[112]1900                    break
1901                end
1902                filecell.nc.civ1(ifile,j)={filename};
1903            end
1904            if detect% if a netcdf file already exists
1905                break
1906            end
1907        end
[134]1908 
[289]1909        %create the new txt_SubdirCiv1
[127]1910        if ~exist(fullfile(Path_ima,subdir_civ1_new),'dir')
[263]1911%             cd(Path_ima);         
1912            [xx,msg1]=mkdir(fullfile(Path_ima,subdir_civ1_new));
[134]1913
[128]1914            if ~strcmp(msg1,'')
1915                msgbox_uvmat('ERROR',['cannot create ' subdir_civ1_new ': ' msg1])%error message for directory creation
[122]1916                filecell={};
1917                return
[163]1918            elseif isunix         
[266]1919                [xx,msg2] = fileattrib(fullfile(Path_ima,subdir_civ1_new),'+w','g'); %yield writing access (+w) to user group (g)
[128]1920                if ~strcmp(msg2,'')
[266]1921                    msgbox_uvmat('ERROR',['pb of permission for  ' fullfile(Path_ima,subdir_civ1_new) ': ' msg2])%error message for directory creation
[128]1922                    filecell={};
1923                    return
1924                end
[112]1925            end
[263]1926%             cd(currentdir);
[112]1927        end
1928        if strcmp(compare,'stereo PIV')&&(strcmp(mode,'pair j1-j2')||strcmp(mode,'series(Dj)')||strcmp(mode,'series(Di)'))%check second nc series
1929            for ifile=1:nbfield
1930                for j=1:nbslice
[122]1931                    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]1932                    detect=exist(filename,'file')==2;
[2]1933                    if detect% if a netcdf file already exists
[137]1934                       indstr=regexp(subdir_civ1_new,'\D');
1935                       if indstr(end)<length(subdir_civ1_new) %subdir_civ1 ends by a number
1936                           vers=str2double(subdir_civ1_new(indstr(end)+1:end))+1;
1937                           subdir_civ1_new=[subdir_civ1_new(1:indstr(end)) num2str(vers)];
[127]1938                       else
1939                           vers=vers+1;
[137]1940                           subdir_civ1_new=[subdir_civ1_new '_' num2str(vers)];
[127]1941                       end
1942                       subdir_civ2=subdir_civ1;
1943                       break
[2]1944                    end
[112]1945                    filecell.ncA.civ1(ifile,j)={filename};
1946                end
1947                if detect% if a netcdf file already exists
1948                    break
1949                end
1950            end
[289]1951            %create the new txt_SubdirCiv1
[263]1952            if ~exist(fullfile(Path_ima,subdir_civ1_new),'dir')
1953%                    cd(Path_ima);         
1954                [xx,msg1]=mkdir(fullfile(Path_ima,subdir_civ1_new));
1955%                             cd(currentdir);
[252]1956                if ~strcmp(msg1,'')
[128]1957                    msgbox_uvmat('ERROR',['cannot create ' subdir_civ1_new ': ' msg1])
[263]1958%                     cd(currentdir)
[122]1959                    filecell={};
1960                    return
[128]1961                else
[266]1962                    [xx,msg2] = fileattrib(fullfile(Path_ima,subdir_civ1_new),'+w','g'); %yield writing access (+w) to user group (g)
[128]1963                    if ~strcmp(msg2,'')
1964                        msgbox_uvmat('ERROR',['pb of permission for ' subdir_civ1_new ': ' msg2])%error message for directory creation
[263]1965%                         cd(currentdir)
[128]1966                        filecell={};
1967                        return
1968                    end
[112]1969                end
1970            end
1971        end
1972    end
[127]1973    subdir_civ1=subdir_civ1_new;
[2]1974    % get image names
1975    for ifile=1:nbfield
[112]1976        for j=1:nbslice
[2]1977            filename=name_generator(filebase_ima1, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
1978            idetect(j)=exist(filename,'file')==2;
1979            filecell.ima1.civ1(ifile,j)={filename}; %first image
1980            filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
1981            idetect_1(j)=exist(filename,'file')==2;
1982            filecell.ima2.civ1(ifile,j)={filename};%second image
[112]1983        end
1984        [idetectmin,indexj]=min(idetect);
1985        if idetectmin==0,
1986            msgbox_uvmat('ERROR',[filecell.ima1.civ1{ifile,indexj} ' not found'])
[122]1987            filecell={};
[266]1988           % cd(currentdir)
[112]1989            return
1990        end
1991        [idetectmin,indexj]=min(idetect_1);
1992        if idetectmin==0,
1993            msgbox_uvmat('ERROR',[filecell.ima2.civ1{ifile,indexj} ' not found'])
[122]1994            filecell={};
[266]1995            %cd(currentdir)
[112]1996            return
1997        end
1998    end
1999    if strcmp(compare,'stereo PIV') && (strcmp(mode,'pair j1-j2') || strcmp(mode,'series(Dj)') || strcmp(mode,'series(Di)'))
2000        for ifile=1:nbfield
2001            for j=1:nbslice
2002                filename=name_generator(filebase_A, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
2003                idetect(j)=exist(filename,'file')==2;
2004                filecell.imaA1.civ1(ifile,j)={filename} ;%first image
2005                filename=name_generator(filebase_A, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
2006                idetect_1(j)=exist(filename,'file')==2;
2007                filecell.imaA2.civ1(ifile,j)={filename};%second image
2008            end
[2]2009            [idetectmin,indexj]=min(idetect);
[112]2010            if idetectmin==0,
2011                msgbox_uvmat('ERROR',[filecell.imaA1.civ1{ifile,indexj} ' not found'])
[122]2012                filecell={};
[266]2013               % cd(currentdir)
[2]2014                return
[112]2015            end
[2]2016            [idetectmin,indexj]=min(idetect_1);
[112]2017            if idetectmin==0,
2018                msgbox_uvmat('ERROR',[filecell.imaA2.civ1{ifile,indexj} ' not found'])
[122]2019                filecell={};
[266]2020               % cd(currentdir)
[2]2021                return
[112]2022            end
2023        end
[2]2024    end
[112]2025   
[282]2026    %%%%%%%%%%%%%  checkfix1 or checkpatch1 activated but no checkciv1   %%%%%%%%%%%%%
2027elseif (checkbox(2)==1 || checkbox(3)==1);
[2]2028    for ifile=1:nbfield
2029        for j=1:nbslice
2030            filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',...
[112]2031                nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2032            detect=exist(filename,'file')==2;
[122]2033            if detect==0
2034                msgbox_uvmat('ERROR',[filename ' not found'])
2035                filecell={};
[266]2036               % cd(currentdir)
[122]2037                return
2038            end
[2]2039            filecell.nc.civ1(ifile,j)={filename};
2040        end
2041    end
2042    if strcmp(compare,'stereo PIV')
[112]2043        for ifile=1:nbfield
2044            for j=1:nbslice
2045                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);%
2046                filecell.ncA.civ1(ifile,j)={filename};
2047                if ~exist(filename,'file')
2048                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
2049                    set(handles.RUN, 'Enable','On')
2050                    set(handles.RUN,'BackgroundColor',[1 0 0])
[122]2051                    filecell={};
[266]2052                    %cd(currentdir)
[112]2053                    return
[2]2054                end
2055            end
[112]2056        end
[2]2057    end
2058end
2059
[282]2060%%%%%%%%%%%%%  if checkciv2 performed with pairs different than checkciv1  %%%%%%%%%%%%%
[2]2061testdiff=0;
[282]2062if (checkbox(4)==1)&&...
2063        ((get(handles.ListPairCiv1,'Value')~=get(handles.ListPairCiv2,'Value'))||~strcmp(subdir_civ2,subdir_civ1))
[2]2064    testdiff=1;
[112]2065    detect=1;
[127]2066    vers=0;
2067    subdir_civ2_new=subdir_civ2;
[2]2068    while detect==1 %create a new subdir if the netcdf files already exist
[112]2069        for ifile=1:nbfield
2070            for j=1:nbslice
[127]2071                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]2072                detect=exist(filename,'file')==2;
2073                if detect% if a netcdf file already exists
[127]2074                    indstr=regexp(subdir_civ2,'\D');
2075                    if indstr(end)<length(subdir_civ2) %subdir_civ1 ends by a number
2076                        vers=str2double(subdir_civ2(indstr(end)+1:end))+1;
2077                        subdir_civ2_new=[subdir_civ2(1:indstr(end)) num2str(vers)];
2078                    else
2079                        vers=vers+1;
2080                        subdir_civ2_new=[subdir_civ1 '_' num2str(vers)];
2081                    end
[112]2082                    break
2083                end
2084                filecell.nc.civ2(ifile,j)={filename};
2085            end
2086            if detect% if a netcdf file already exists
2087                break
2088            end
2089        end
[128]2090        %create the new subdir_civ2_new
2091        if ~exist(fullfile(Path_ima,subdir_civ2_new),'dir')
[174]2092            [xx,m2]=mkdir(fullfile(Path_ima,subdir_civ2_new));
[266]2093            [xx,msg2] = fileattrib(fullfile(Path_ima,subdir_civ2_new),'+w','g'); %yield writing access (+w) to user group (g)
[112]2094            if ~isequal(m2,'')
[266]2095                msgbox_uvmat('ERROR',['cannot create ' fullfile(Path_ima,subdir_civ2_new) ': ' m2])
[122]2096                filecell={};
[266]2097               % cd(currentdir)
[122]2098                return
[112]2099            end
2100        end
2101        if strcmp(compare,'stereo PIV')%check second nc series
2102            for ifile=1:nbfield
2103                for j=1:nbslice
2104                    filename=name_generator(filebase_A,num1_civ2(ifile),num_a_civ2(j),'.nc',...
[122]2105                        nom_type_nc,1,num2_civ2(ifile),num_b_civ1(j),subdir_civ2_new);%
[112]2106                    detect=exist(filename,'file')==2;
[2]2107                    if detect% if a netcdf file already exists
[127]2108                        indstr=regexp(subdir_civ2,'\D');
2109                        if indstr(end)<length(subdir_civ2) %subdir_civ1 ends by a number
2110                           vers=str2double(subdir_civ2(indstr(end)+1:end))+1;
2111                           subdir_civ2_new=[subdir_civ2(1:indstr(end)) num2str(vers)];
2112                        else
2113                           vers=vers+1;
2114                           subdir_civ2_new=[subdir_civ1 '_' num2str(vers)];
2115                        end
[112]2116                        break
[2]2117                    end
[112]2118                    filecell.ncA.civ2(ifile,j)={filename};
2119                end
2120                if detect% if a netcdf file already exists
2121                    break
2122                end
2123            end
[122]2124            subdir_civ2=subdir_civ2_new;
[289]2125            %create the new txt_SubdirCiv1
[127]2126            if ~exist(fullfile(Path_ima,subdir_civ2_new),'dir')
2127                [xx,m2]=mkdir(subdir_civ2_new);
[266]2128                 [xx,msg2] = fileattrib(fullfile(Path_ima,subdir_civ2_new),'+w','g'); %yield writing access (+w) to user group (g)
[112]2129                if ~isequal(m2,'')
[266]2130                    msgbox_uvmat('ERROR', ['cannot create ' fullfile(Path_ima,subdir_civ2_new) ': ' m2])%error message for directory creation
2131                  %  cd(currentdir)
[122]2132                    filecell={};
2133                    return
[112]2134                end
2135            end
2136        end
2137    end
[127]2138    subdir_civ2=subdir_civ2_new;
[2]2139end
[266]2140%cd(currentdir);%come back to the current working directory
[2]2141
[282]2142%%%%%%%%%%%%%  if checkciv2 results are obtained or used  %%%%%%%%%%%%%
2143if checkbox(4)==1 || checkbox(5)==1 || checkbox(6)==1 %civ2
2144    %check source netcdf file of checkciv1 estimates
2145    if checkbox(1)==0; %no civ1 performed
[2]2146        for ifile=1:nbfield
2147            for j=1:nbslice
2148                filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',...
2149                    nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2150                filecell.nc.civ1(ifile,j)={filename};% name of the civ1 file
2151                if ~exist(filename,'file')
2152                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
[122]2153                    filecell={};
[2]2154                    return
2155                end
2156                if ~testdiff % civ2 or patch2 are written in the same file as civ1
[282]2157                    if checkbox(4)==0 ; %check the existence of civ2 if it is not calculated
[248]2158                        Data=nc2struct(filename,'ListGlobalAttribute','CivStage','civ2');
2159                        if ~isempty(Data.CivStage) && Data.CivStage<4 %test for civ files
[2]2160                            msgbox_uvmat('ERROR',['no civ2 data in ' filename])
[12]2161                            filecell=[];
[2]2162                            return
[248]2163                        elseif isempty(Data.civ2)||isequal(Data.civ2,0)
2164                            msgbox_uvmat('ERROR',['no civ2 data in ' filename])
2165                            filecell=[];
2166                            return
[112]2167                        end
[282]2168                    elseif checkbox(3)==0; %check the existence of patch if it is not calculated
[275]2169                        Data=nc2struct(filename,'ListGlobalAttribute','CivStage','patch');
[248]2170                        if ~isempty(Data.CivStage)
2171                            if Data.CivStage<3 %test for civ files
2172                                msgbox_uvmat('ERROR',['no patch data in ' filename])
2173                                filecell=[];
2174                                return
2175                            end
2176                        elseif isempty(Data.patch)||isequal(Data.patch,0)
[2]2177                            msgbox_uvmat('ERROR',['no patch data in ' filename])
[12]2178                            filecell=[];
[2]2179                            return
2180                        end
[112]2181                    end
[2]2182                end
2183            end
2184        end
2185        if strcmp(compare,'stereo PIV')
2186            for ifile=1:nbfield
2187                for j=1:nbslice
2188                    filename=name_generator(filebase_A,num1_civ2(ifile),num_a_civ2(j),'.nc',...
2189                        nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
2190                    filecell.ncA.civ2(ifile,j)={filename};
2191                    if ~exist(filename,'file')
2192                        msgbox_uvmat('ERROR',['input file ' filename ' not found'])
2193                        set(handles.RUN, 'Enable','On')
2194                        set(handles.RUN,'BackgroundColor',[1 0 0])
2195                        return
2196                    end
2197                end
2198            end
2199        end
2200    end
[112]2201   
2202    detect=1;
[282]2203    %     while detect==1%creates a new subdir if the netcdf files already contain checkciv2 data
[112]2204    for ifile=1:nbfield
2205        for j=1:nbslice
2206            filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',...
[2]2207                nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);
[112]2208            detect=exist(filename,'file')==2;
2209            filecell.nc.civ2(ifile,j)={filename};
[2]2210        end
[112]2211    end
[282]2212    %get first image names for checkciv2
2213    if checkbox(1)==1 && isequal(num1_civ1,num1_civ2) && isequal(num_a_civ1,num_a_civ2)
[2]2214        filecell.ima1.civ2=filecell.ima1.civ1;
[282]2215    elseif checkbox(4)==1
[2]2216        for ifile=1:nbfield
2217            for j=1:nbslice
2218                filename=name_generator(filebase_ima1, num1_civ2(ifile),num_a_civ2(j),ext_ima,nom_type_ima1);
2219                idetect_2(j)=exist(filename,'file')==2;
2220                filecell.ima1.civ2(ifile,j)={filename};%first image
2221            end
[112]2222            [idetectmin,indexj]=min(idetect_2);
[2]2223            if idetectmin==0,
[112]2224                msgbox_uvmat('ERROR',['input image ' filecell.ima1.civ2{ifile,indexj} ' not found'])
2225                filecell=[];
2226                return
[2]2227            end
2228        end
2229    end
2230   
[282]2231    %get second image names for checkciv2
2232    if checkbox(1)==1 && isequal(num2_civ1,num2_civ2) && isequal(num_b_civ1,num_b_civ2)
[2]2233        filecell.ima2.civ2=filecell.ima2.civ1;
[282]2234    elseif checkbox(4)==1
[2]2235        for ifile=1:nbfield
2236            for j=1:nbslice
2237                filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),ext_ima,nom_type_ima2);
2238                idetect_3(j)=exist(filename,'file')==2;
2239                filecell.ima2.civ2(ifile,j)={filename};%first image
2240            end
[112]2241            [idetectmin,indexj]=min(idetect_3);
[2]2242            if idetectmin==0,
[112]2243                msgbox_uvmat('ERROR',['input image ' filecell.ima2.civ2{ifile,indexj} ' not found'])
2244                filecell=[];
2245                return
[2]2246            end
2247        end
2248    end
2249end
[282]2250if (checkbox(5) || checkbox(6)) && ~checkbox(4)  % need to read an existing netcdf civ2 file
[2]2251    if ~testdiff
2252        filecell.nc.civ2=filecell.nc.civ1;% file already checked
[112]2253    else     % check the civ2 files
[2]2254        for ifile=1:nbfield
2255            for j=1:nbslice
2256                filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',...
[112]2257                    nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
[2]2258                filecell.nc.civ2(ifile,j)={filename};
2259                if ~exist(filename,'file')
2260                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
[12]2261                    filecell=[];
[2]2262                    return
2263                else
[248]2264                    Data=nc2struct(filename,'ListGlobalAttribute','CivStage','civ2');
2265                    if ~isempty(Data.CivStage) && Data.CivStage<4 %test for civ files
2266                            msgbox_uvmat('ERROR',['no civ2 data in ' filename])
2267                            filecell=[];
2268                            return
2269                    elseif isempty(Data.civ2)||isequal(Data.civ2,0)
[2]2270                        msgbox_uvmat('ERROR',['no civ2 data in ' filename])
[12]2271                        filecell=[];
[2]2272                        return
2273                    end
2274                end
2275            end
2276        end
2277    end
2278end
2279
2280%%%%%%%%%%%%%  if stereo fields are calculated by PATCH %%%%%%%%%%%%%
2281if strcmp(compare,'stereo PIV')
[282]2282    if  checkbox(3) && isequal(get(handles.test_stereo1,'Value'),1)
[2]2283        for ifile=1:nbfield
2284            for j=1:nbslice
2285                filename=name_generator(filebase_AB,num1_civ1(ifile),num_a_civ1(j),'.nc',...
2286                    nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2287                filecell.st(ifile,j)={filename};
2288            end
2289        end
2290    end
[282]2291    if  checkbox(6) && isequal(get(handles.CheckStereo,'Value'),1)
[2]2292        for ifile=1:nbfield
2293            for j=1:nbslice
2294                filename=name_generator(filebase_AB,num1_civ2(ifile),num_a_civ2(j),'.nc',...
2295                    nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
2296                filecell.st(ifile,j)={filename};
2297            end
2298        end
[112]2299    end
[2]2300end
[289]2301set(handles.txt_SubdirCiv1,'String',subdir_civ1);%update the edit box
2302set(handles.txt_SubdirCiv2,'String',subdir_civ2);%update the edit box
[2]2303browse.nom_type_nc=nom_type_nc;
[273]2304set(handles.RootName,'UserData',browse); %update the nomenclature type for uvmat
[2]2305
2306
2307%COPY IMAGES TO THE FORMAT .png IF NEEDED
[45]2308if isequal(nom_type_ima1,'*')%case of movie files
2309    nom_type_imanew1='_i';
[2]2310else
2311    nom_type_imanew1=nom_type_ima1;
2312end
[45]2313if isequal(nom_type_ima2,'*')%case of movie files
2314    nom_type_imanew2='_i';
[2]2315else
2316    nom_type_imanew2=nom_type_ima2;
2317end
2318if ~isequal(ext_ima,'.png')
[45]2319    %%type of image file
2320    type_ima1='none';%default
2321    movieobject1=[];%default
[133]2322    if strcmpi(ext_ima,'.avi')
[45]2323        hhh=which('mmreader');
2324        if ~isequal(hhh,'')&& mmreader.isPlatformSupported()% if the mmreader function is found (recent version of matlab)
2325            type_ima1='movie';
2326            movieobject1=mmreader([filebase_ima2 ext_ima]);
2327        else
2328            type_ima1='avi';
2329        end
[133]2330    elseif ischar(ext_ima) && ~isempty(ext_ima(2:end))
[112]2331        form=imformats(ext_ima(2:end));
2332        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
2333            if isequal(nom_type_ima1,'*');
2334                type_ima1='multimage';%image series in a single image file
2335            else
2336                type_ima1='image';
2337            end
2338        end
[45]2339    end
2340    type_ima2='none';%default
2341    movieobject2=[];
[133]2342    if strcmpi(ext_ima,'.avi')
[45]2343        hhh=which('mmreader');
2344        if ~isequal(hhh,'')&& mmreader.isPlatformSupported()% if the mmreader function is found (recent version of matlab)
2345            type_ima2='movie';
2346            movieobject2=mmreader([filebase_ima2 ext_ima]);
2347        else
2348            type_ima2='avi';
2349        end
[133]2350    elseif ischar(ext_ima) && ~isempty(ext_ima(2:end))
[112]2351        form=imformats(ext_ima(2:end));
2352        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
2353            if isequal(nom_type_ima1,'*');
2354                type_ima2='multimage';%image series in a single image file
2355            else
2356                type_ima2='image';
2357            end
2358        end
[45]2359    end
[71]2360    %npxy=get(handles.ImaExt,'UserData');
[112]2361    % %     if numel(npxy)<2
2362    %
2363    %         filename=name_generator(filebase_ima1,num1_civ1(1),num_a_civ1(1),ImaExt,nom_type_ima1);
2364    %         A=imread(filename);
2365    %         npxy=size(A);
2366    % %     end
2367    %     npy=npxy(1);
2368    %     npx=npxy(2);
[282]2369    if checkbox(1) %if civ1 is performed
[224]2370        h = waitbar(0,'copy images to the .png format for civ1');% display a wait bar
[112]2371        for ifile=1:nbfield
[2]2372            waitbar(ifile/nbfield);
2373            for j=1:nbslice
[112]2374                filename=name_generator(filebase_ima1,num1_civ1(ifile),num_a_civ1(j),'.png',nom_type_imanew1);
2375                if ~exist(filename,'file')
2376                    A=read_image(filecell.ima1.civ1{ifile,j},type_ima1,num1_civ1(ifile),movieobject1);
2377                    imwrite(A,filename,'BitDepth',16);
2378                end
2379                filecell.ima1.civ1(ifile,j)={filename};
2380                filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),'.png',nom_type_imanew2);
2381                if ~exist(filename,'file')
2382                    A=read_image(filecell.ima2.civ1{ifile,j},type_ima2,num2_civ1(ifile),movieobject2);
2383                    imwrite(A,filename,'BitDepth',16);
2384                end
2385                filecell.ima2.civ1(ifile,j)={filename};
[2]2386            end
2387        end
2388        close(h)
2389    end
[282]2390    if checkbox(4) %if civ2 is performed
[229]2391        h = waitbar(0,'copy images to the .png format for civ2');% display a wait bar
[2]2392        for ifile=1:nbfield
2393            waitbar(ifile/nbfield);
2394            for j=1:nbslice
[112]2395                filename=name_generator(filebase_ima1,num1_civ2(ifile),num_a_civ2(j),'.png',nom_type_imanew1);
2396                if ~exist(filename,'file')
2397                    A=read_image(cell2mat(filecell.ima1.civ2(ifile,j)),type_ima2,num1_civ2(ifile));
2398                    imwrite(A,filename,'BitDepth',16);
2399                end
2400                filecell.ima1.civ2(ifile,j)={filename};
2401                filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),'.png',nom_type_imanew2);
2402                if ~exist(filename,'file')
2403                    A=read_image(cell2mat(filecell.ima2.civ2(ifile,j)),type_ima2,num2_civ2(ifile));
2404                    imwrite(A,filename,'BitDepth',16);
2405                end
2406                filecell.ima2.civ2(ifile,j)={filename};
[2]2407            end
2408        end
2409        close(h);
2410    end
2411end
2412
[12]2413%------------------------------------------------------------------------
[227]2414% --- determine the list of index pairs of processing file
2415function [num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
2416    find_pair_indices(handles,ref_i,ref_j,mode)
2417%------------------------------------------------------------------------
2418
[282]2419list_civ1=get(handles.ListPairCiv1,'String');
2420index_civ1=get(handles.ListPairCiv1,'Value');
[227]2421str_civ1=list_civ1{index_civ1};%string defining the image pairs for civ1
2422if isempty(str_civ1)||isequal(str_civ1,'')
2423    msgbox_uvmat('ERROR','no image pair selected for civ1')
2424    return
2425end
[282]2426list_civ2=get(handles.ListPairCiv2,'String');
2427index_civ2=get(handles.ListPairCiv2,'Value');
[227]2428if index_civ2>length(list_civ2)
2429    list_civ2=list_civ1;
2430    index_civ2=index_civ1;
2431end
2432str_civ2=list_civ2{index_civ2};%string defining the image pairs for civ2
2433
2434if isequal (mode,'series(Di)')
2435    lastfield=str2double(get(handles.nb_field,'String'));
2436    num1_civ1=ref_i-floor(index_civ1/2)*ones(size(ref_i));% set of first image numbers
2437    num2_civ1=ref_i+ceil(index_civ1/2)*ones(size(ref_i));
2438    num_a_civ1=ref_j;
2439    num_b_civ1=ref_j;
[229]2440    num1_civ2=ref_i-floor(index_civ2/2)*ones(size(ref_i));
[227]2441    num2_civ2=ref_i+ceil(index_civ2/2)*ones(size(ref_i));
2442    num_a_civ2=ref_j;
2443    num_b_civ2=ref_j;   
2444   
2445    % adjust the first and last field number
2446    lastfield=str2double(get(handles.nb_field,'String'));
2447    if isnan(lastfield)
2448        indsel=find((num1_civ1 >= 1)&(num1_civ2 >= 1));
2449    else
2450        indsel=find((num2_civ1 <= lastfield)&(num2_civ2 <= lastfield)&(num1_civ1 >= 1)&(num1_civ2 >= 1));
2451    end
2452    if length(indsel)>=1
2453        firstind=indsel(1);
2454        lastind=indsel(end);
2455        set(handles.first_i,'String',num2str(ref_i(firstind)))%update the display of first and last fields
2456        set(handles.last_i,'String',num2str(ref_i(lastind)))
2457        ref_i=ref_i(indsel);
2458        num1_civ1=num1_civ1(indsel);
2459        num1_civ2=num1_civ2(indsel);
2460        num2_civ1=num2_civ1(indsel);
2461        num2_civ2=num2_civ2(indsel);
2462    end
2463elseif isequal (mode,'series(Dj)')
2464    lastfield_j=str2double(get(handles.nb_field2,'String'));
2465    num1_civ1=ref_i;% set of first image numbers
2466    num2_civ1=ref_i;
2467    num_a_civ1=ref_j-floor(index_civ1/2)*ones(size(ref_j));
2468    num_b_civ1=ref_j+ceil(index_civ1/2)*ones(size(ref_j));
2469    num1_civ2=ref_i;
2470    num2_civ2=ref_i;
2471    num_a_civ2=ref_j-floor(index_civ2/2)*ones(size(ref_j));
2472    num_b_civ2=ref_j+ceil(index_civ2/2)*ones(size(ref_j));
2473    % adjust the first and last field number
2474    if isnan(lastfield_j)
2475        indsel=find((num_a_civ1 >= 1)&(num_a_civ2 >= 1));
2476    else
2477        indsel=find((num_b_civ1 <= lastfield_j)&(num_b_civ2 <= lastfield_j)&(num_a_civ1 >= 1)&(num_a_civ2 >= 1));
2478    end
2479    if length(indsel)>=1
2480        firstind=indsel(1);
2481        lastind=indsel(end);
2482        set(handles.first_j,'String',num2str(ref_j(firstind)))%update the display of first and last fields
2483        set(handles.last_j,'String',num2str(ref_j(lastind)))
2484        ref_j=ref_j(indsel);
2485        num_a_civ1=num_a_civ1(indsel);
2486        num_b_civ1=num_b_civ1(indsel);
2487        num_a_civ2=num_a_civ2(indsel);
2488        num_b_civ2=num_b_civ2(indsel);
2489    end
2490elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)
[282]2491    displ_num=get(handles.ListPairCiv1,'UserData');
[227]2492    num1_civ1=ref_i;
2493    num2_civ1=ref_i;
2494    num_a_civ1=displ_num(1,index_civ1);
2495    num_b_civ1=displ_num(2,index_civ1);
2496    num1_civ2=ref_i;
2497    num2_civ2=ref_i;
2498    num_a_civ2=displ_num(1,index_civ2);
2499    num_b_civ2=displ_num(2,index_civ2);
2500elseif isequal(mode,'displacement')
2501    num1_civ1=ref_i;
2502    num2_civ1=ref_i;
2503    num_a_civ1=ref_j;
2504    num_b_civ1=ref_j;
2505    num1_civ2=ref_i;
2506    num2_civ2=ref_i;
2507    num_a_civ2=ref_j;
2508    num_b_civ2=ref_j;
2509end
2510
2511%------------------------------------------------------------------------
[309]2512% --- Executes on button press in ListCompareMode.
2513function ListCompareMode_Callback(hObject, eventdata, handles)
[12]2514%------------------------------------------------------------------------
[309]2515test=get(handles.ListCompareMode,'Value');
2516if test==2 || test==3 % case 'dispalcemen' or 'stereo PIV'
2517    filebase=get(handles.RootName,'String');
2518    browse=get(handlesRootName,'Userdata');
2519    browse.nom_type_ima1=browse.nom_type_ima;
2520    set(handlesRootName,'UserData',browse);
2521    set(handles.sub_txt,'Visible','on')
2522    set(handles.RootName_1,'Visible','On');%mkes the second file input window visible
2523    mode_store=get(handles.ListPairMode,'String');%get the present 'mode'
2524    set(handles.ListCompareMode,'UserData',mode_store);%store the mode display
2525    set(handles.ListPairMode,'Visible','off')
2526    if test==2
2527        set(handles.ListPairMode,'Visible','off')
2528        set(handles.ListPairMode,'Value',1) % mode 'civX' selected by default
2529    else
2530        set(handles.ListPairMode,'Visible','on')
2531        set(handles.ListPairMode,'Value',3) % mode 'Matlab' selected for stereo
2532    end
2533   
2534    %% menuopen an image file with the browser
2535    ind_opening=1;%default
2536    browse.incr_pair=[0 0]; %default
2537    oldfile=get(handles.RootName,'String');
2538     menu={'*.xml;*.civ;*.png;*.jpg;*.tif;*.avi;*.AVI;*.nc;', ' (*.xml,*.civ,*.png,*.jpg ,.tif, *.avi,*.nc)';
2539       '*.xml',  '.xml files '; ...
2540        '*.civ',  '.civ files '; ...
2541        '*.png','.png image files'; ...
2542        '*.jpg',' jpeg image files'; ...
2543        '*.tif','.tif image files'; ...
2544        '*.avi;*.AVI','.avi movie files'; ...
2545        '*.nc','.netcdf files'; ...
2546        '*.*',  'All Files (*.*)'};
2547    [FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file of the second series',oldfile);
2548    fileinput=[PathName FileName];%complete file name
2549    sizf=size(fileinput);
2550    if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
2551    [path,name,ext]=fileparts(fileinput);
2552    [path1]=fileparts(filebase);
2553    if isunix
2554        [status,path]=system(['readlink ' path]);
2555        [status,path1]=system(['readlink ' path1]);% look for the true path in case of symbolic paths
2556    end
2557    if ~strcmp(path1,path)
2558        msgbox_uvmat('ERROR','The second image series must be in the same directory as the first one')
2559        return
2560     end
2561%     set(handles.RootName_1,'String',name);
2562    [RootPath,RootFile,field_count,str2,str_a,str_b,xx,nom_type,subdir]=name2display(name);
2563    set(handles.RootName_1,'String',RootFile);
2564    browse=get(handlesRootName,'UserData');
2565    browse.nom_type_ima_1=nom_type;
2566    set(handlesRootName,'UserData',browse)
2567   
2568    %check image extension
2569    if ~strcmp(ext,get(handles.ImaExt,'String'))
2570        msgbox_uvmat('ERROR','The second image series must have the same extension name as the first one')
2571        return
2572    end
2573   
2574    %% check coincidence of image sizes
2575%     ref_i=get(handles.ref_i,'string');
2576%     ref_j=get(handles.ref_j,'string');
2577%     [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]);
2578%     A=imread(filecell.ima1.checkciv1{1});
2579%     A_1=imread(fileinput);
2580%     npxy=size(A);
2581%     npxy_1=size(A_1);
2582%     if ~isequal(size(A),size(A_1))
2583%         msgbox_uvmat('ERROR','The two input image series do not have the same size')
2584%         return
2585%     end
2586else
2587    set(handles.ListPairMode,'Visible','on')
2588    set(handles.RootName_1,'Visible','Off');
2589    set(handles.sub_txt,'Visible','off')
2590    set(handles.RootName_1,'String',[]);
2591    mode_store=get(handles.ListCompareMode,'UserData');
2592    set(handles.ListPairMode,'Value',1)
2593    set(handles.ListPairMode,'String',mode_store)
2594    set(handles.test_stereo1,'Value',0)
2595    set(handles.CheckStereo,'Value',0)
2596    set(handles.ListPairMode,'Value',1) % mode 'civX' selected by default
2597end
2598if test==3 && get(handles.CheckPatch1,'Value')
2599    set(handles.test_stereo1,'Visible','on')
2600else
2601    set(handles.test_stereo1,'Visible','off')
2602end
2603if test==3 && get(handles.CheckPatch2,'Value')
2604    set(handles.CheckStereo,'Visible','on')
2605else
2606    set(handles.CheckStereo,'Visible','off')
2607end
2608mode_Callback(hObject, eventdata, handles)
[2]2609
[309]2610
2611%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2612% Callbacks in the uipanel Pair Indices
2613%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[12]2614%------------------------------------------------------------------------
[309]2615% --- Executes on button press in ListPairMode.
2616function ListPairMode_Callback(hObject, eventdata, handles)
[12]2617%------------------------------------------------------------------------
[309]2618compare_list=get(handles.ListCompareMode,'String');
2619val=get(handles.ListCompareMode,'Value');
2620compare=compare_list{val};
2621if strcmp(compare,'displacement')
2622    mode='displacement';
2623else
2624    mode_list=get(handles.ListPairMode,'String');
2625    if ischar(mode_list)
2626        mode_list={mode_list};
2627    end
2628    mode_value=get(handles.ListPairMode,'Value');
2629    mode=mode_list{mode_value};
2630end
2631displ_num=[];%default
2632ref_i=str2double(get(handles.ref_i,'String'));
2633% last_i=str2num(get(handles.last_i,'String'));
2634time=get(handles.ImaDoc,'UserData'); %get the set of times
2635siztime=size(time);
2636nbfield=siztime(1);
2637nbfield2=siztime(2);
2638indchosen=1;  %%first pair selected by default
2639%displ_num used to define the indices of the civ pairs
2640% in mode 'pair j1-j2', j1 and j2 are the file indices, else the indices
2641% are relative to the reference indices ref_i and ref_j respectively.
2642if isequal(mode,'pair j1-j2')%| isequal(mode,'st_pair j1-j2')
2643    dt=1;
2644    displ='';
2645    index=0;
2646    numlist_a=[];
2647    numlist_B=[];
2648    %get all the time intervals in bursts
2649    displ_dt=1;%default
2650    nbfield2=min(nbfield2,10);%limitate the number of pairs to 10x10
2651    for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'pair j1-j2' mode
2652        for numod_b=(numod_a+1):nbfield2
2653            index=index+1;
2654            numlist_a(index)=numod_a;
2655            numlist_b(index)=numod_b;
2656            if ~isempty(time)
2657                dt(numod_a,numod_b)=time(ref_i,numod_b)-time(ref_i,numod_a);%first time interval dt
2658                displ_dt(index)=dt(numod_a,numod_b);
2659            else
2660                displ_dt(index)=1;
2661            end
2662        end
2663    end
2664    [dtsort,indsort]=sort(displ_dt);
2665    if ~isempty(numlist_a)
2666        displ_num(1,:)=numlist_a(indsort);
2667        displ_num(2,:)=numlist_b(indsort);
2668    end
2669    displ_num(3,:)=0;
2670    displ_num(4,:)=0;
2671    set(handles.jtext,'Visible','Off')
2672    set(handles.first_j,'Visible','Off')
2673    set(handles.last_j,'Visible','Off')
2674    set(handles.incr_j,'Visible','Off')
2675    set(handles.nb_field2,'Visible','Off')
2676    set(handles.ref_j,'Visible','Off')
2677elseif isequal(mode,'series(Dj)') %| isequal(mode,'st_series(Dj)')
2678    index=1:200;
2679    displ_num(1,index)=-floor(index/2);
2680    displ_num(2,index)=ceil(index/2);
2681    displ_num(3:4,index)=zeros(2,200);
2682%     for index=1:min(nbfield2-1,200)
2683%         displ_num(1,index)=-floor(index/2);
2684%         displ_num(2,index)=ceil(index/2);
2685%         displ_num(3,index)=0;
2686%         displ_num(4,index)=0;
2687%     end
2688    set(handles.jtext,'Visible','On')
2689    set(handles.first_j,'Visible','On')
2690    set(handles.last_j,'Visible','On')
2691    set(handles.incr_j,'Visible','On')
2692    set(handles.nb_field2,'Visible','On')
2693    set(handles.ref_j,'Visible','On')
2694    if nbfield > 1
2695        set(handles.itext,'Visible','On')
2696        set(handles.first_i,'Visible','On')
2697        set(handles.last_i,'Visible','On')
2698        set(handles.incr_i,'Visible','On')
2699        set(handles.nb_field,'Visible','On')
2700        set(handles.ref_i,'Visible','On')
2701    else
2702        set(handles.itext,'Visible','Off')
2703        set(handles.first_i,'Visible','Off')
2704        set(handles.last_i,'Visible','Off')
2705        set(handles.incr_i,'Visible','Off')
2706        set(handles.nb_field,'Visible','Off')
2707        set(handles.ref_i,'Visible','Off')
2708    end
2709elseif isequal(mode,'series(Di)') %| isequal(mode,'st_series(Di)')
2710    index=1:200;
2711    displ_num(1:2,index)=zeros(2,200);
2712    displ_num(3,index)=-floor(index/2);
2713    displ_num(4,index)=ceil(index/2);
2714%     for index=1:200%min(nbfield-1,200)
2715%         displ_num(1,index)=0;
2716%         displ_num(2,index)=0;
2717%         displ_num(3,index)=-floor(index/2);
2718%         displ_num(4,index)=ceil(index/2);
2719%     end
2720    set(handles.itext,'Visible','On')
2721    set(handles.first_i,'Visible','On')
2722    set(handles.last_i,'Visible','On')
2723    set(handles.incr_i,'Visible','On')
2724    set(handles.nb_field,'Visible','On')
2725    set(handles.ref_i,'Visible','On')
2726    if nbfield2 > 1
2727        set(handles.jtext,'Visible','On')
2728        set(handles.first_j,'Visible','On')
2729        set(handles.last_j,'Visible','On')
2730        set(handles.incr_j,'Visible','On')
2731        set(handles.nb_field2,'Visible','On')
2732        set(handles.ref_j,'Visible','On')
2733    else
2734        set(handles.jtext,'Visible','Off')
2735        set(handles.first_j,'Visible','Off')
2736        set(handles.last_j,'Visible','Off')
2737        set(handles.incr_j,'Visible','Off')
2738        set(handles.nb_field2,'Visible','Off')
2739        set(handles.ref_j,'Visible','Off')
2740    end
2741elseif isequal(mode,'displacement')%the pairs have the same indices
2742    displ_num(1,1)=0;
2743    displ_num(2,1)=0;
2744    displ_num(3,1)=0;
2745    displ_num(4,1)=0;
2746    if nbfield > 1
2747        set(handles.itext,'Visible','On')
2748        set(handles.first_i,'Visible','On')
2749        set(handles.last_i,'Visible','On')
2750        set(handles.incr_i,'Visible','On')
2751        set(handles.nb_field,'Visible','On')
2752        set(handles.ref_i,'Visible','On')
2753    else
2754        set(handles.itext,'Visible','Off')
2755        set(handles.first_i,'Visible','Off')
2756        set(handles.last_i,'Visible','Off')
2757        set(handles.incr_i,'Visible','Off')
2758        set(handles.nb_field,'Visible','Off')
2759        set(handles.ref_i,'Visible','Off')
2760    end
2761    if nbfield2 > 1
2762        set(handles.jtext,'Visible','On')
2763        set(handles.first_j,'Visible','On')
2764        set(handles.last_j,'Visible','On')
2765        set(handles.incr_j,'Visible','On')
2766        set(handles.nb_field2,'Visible','On')
2767        set(handles.ref_j,'Visible','On')
2768    else
2769        set(handles.jtext,'Visible','Off')
2770        set(handles.first_j,'Visible','Off')
2771        set(handles.last_j,'Visible','Off')
2772        set(handles.incr_j,'Visible','Off')
2773        set(handles.nb_field2,'Visible','Off')
2774        set(handles.ref_j,'Visible','Off')
2775    end
2776end
2777set(handles.ListPairCiv1,'UserData',displ_num);
2778find_netcpair_civ1( handles)
2779find_netcpair_civ2(handles)
[2]2780
[12]2781%------------------------------------------------------------------------
[309]2782% --- Executes on selection change in ListPairCiv1.
2783function ListPairCiv1_Callback(hObject, eventdata, handles)
[12]2784%------------------------------------------------------------------------
[309]2785%reproduce by default the chosen pair in the checkciv2 menu
2786list_pair=get(handles.ListPairCiv1,'String');%get the menu of image pairs
2787index_pair=get(handles.ListPairCiv1,'Value');
2788displ_num=get(handles.ListPairCiv1,'UserData');
2789% num_a=displ_num(1,index_pair);
2790% num_b=displ_num(2,index_pair);
2791list_pair2=get(handles.ListPairCiv2,'String');%get the menu of image pairs
2792if index_pair<=length(list_pair2)
2793    set(handles.ListPairCiv2,'Value',index_pair);
2794end
[2]2795
[309]2796%update first_i and last_i according to the chosen image pairs
2797mode_list=get(handles.ListPairMode,'String');
2798mode_value=get(handles.ListPairMode,'Value');
2799mode=mode_list{mode_value};
2800if isequal(mode,'series(Di)')
2801    first_i=str2double(get(handles.first_i,'String'));
2802    last_i=str2double(get(handles.last_i,'String'));
2803    incr_i=str2double(get(handles.incr_i,'String'));
2804    num1=first_i:incr_i:last_i;
2805    lastfield=str2double(get(handles.nb_field,'String'));
2806    if ~isnan(lastfield)
2807        test_find=(num1-floor(index_pair/2)*ones(size(num1))>0)& ...
2808            (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield);
2809        num1=num1(test_find);
2810    end
2811    set(handles.first_i,'String',num2str(num1(1)));
2812    set(handles.last_i,'String',num2str(num1(end)));
2813elseif isequal(mode,'series(Dj)')
2814    first_j=str2double(get(handles.first_j,'String'));
2815    last_j=str2double(get(handles.last_j,'String'));
2816    incr_j=str2double(get(handles.incr_j,'String'));
2817    num_j=first_j:incr_j:last_j;
2818    lastfield2=str2double(get(handles.nb_field2,'String'));
2819    if ~isnan(lastfield2)
2820        test_find=(num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
2821            (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2);
2822        num1=num_j(test_find);
2823    end
2824    set(handles.first_j,'String',num2str(num1(1)));
2825    set(handles.last_j,'String',num2str(num1(end)));
2826end
2827
[12]2828%------------------------------------------------------------------------
[309]2829% --- Executes on selection change in ListPairCiv2.
2830function ListPairCiv2_Callback(hObject, eventdata, handles)
[12]2831%------------------------------------------------------------------------
[309]2832index_pair=get(handles.ListPairCiv2,'Value');%get the selected position index in the menu
[2]2833
[309]2834%update first_i and last_i according to the chosen image pairs
2835mode_list=get(handles.ListPairMode,'String');
2836mode_value=get(handles.ListPairMode,'Value');
2837mode=mode_list{mode_value};
2838if isequal(mode,'series(Di)')
2839    first_i=str2double(get(handles.first_i,'String'));
2840    last_i=str2double(get(handles.last_i,'String'));
2841    incr_i=str2double(get(handles.incr_i,'String'));
2842    num1=first_i:incr_i:last_i;
2843    lastfield=str2double(get(handles.nb_field,'String'));
2844    if ~isnan(lastfield)
2845        test_find=(num1-floor(index_pair/2)*ones(size(num1))>0)& ...
2846            (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield);
2847        num1=num1(test_find);
2848    end
2849    set(handles.first_i,'String',num2str(num1(1)));
2850    set(handles.last_i,'String',num2str(num1(end)));
2851elseif isequal(mode,'series(Dj)')
2852    first_j=str2double(get(handles.first_j,'String'));
2853    last_j=str2double(get(handles.last_j,'String'));
2854    incr_j=str2double(get(handles.incr_j,'String'));
2855    num_j=first_j:incr_j:last_j;
2856    lastfield2=str2double(get(handles.nb_field2,'String'));
2857    if ~isnan(lastfield2)
2858        test_find=(num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
2859            (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2);
2860        num1=num_j(test_find);
2861    end
2862    set(handles.first_j,'String',num2str(num1(1)));
2863    set(handles.last_j,'String',num2str(num1(end)));
2864end
2865
[12]2866%------------------------------------------------------------------------
[309]2867function ref_i_Callback(hObject, eventdata, handles)
[12]2868%------------------------------------------------------------------------
[309]2869mode_list=get(handles.ListPairMode,'String');
2870mode_value=get(handles.ListPairMode,'Value');
2871mode=mode_list{mode_value};
2872find_netcpair_civ1(handles);% update the menu of pairs depending on the available netcdf files
2873if isequal(mode,'series(Di)') || ...% we do patch2 only
2874        (get(handles.CheckCiv2,'Value')==0 && get(handles.CheckCiv1,'Value')==0 && get(handles.CheckFix1,'Value')==0 && get(handles.CheckPatch1,'Value')==0)
2875    find_netcpair_civ2( handles);
2876end
[2]2877
[12]2878%------------------------------------------------------------------------
[309]2879function ref_j_Callback(hObject, eventdata, handles)
[12]2880%------------------------------------------------------------------------
[309]2881mode_list=get(handles.ListPairMode,'String');
2882mode_value=get(handles.ListPairMode,'Value');
2883mode=mode_list{mode_value};
2884if isequal(get(handles.CheckCiv1,'Value'),0)|| isequal(mode,'series(Dj)')
2885    find_netcpair_civ1(handles);% update the menu of pairs depending on the available netcdf files
2886end
2887if isequal(mode,'series(Dj)') || ...
2888        (get(handles.CheckCiv2,'Value')==0 && get(handles.CheckCiv1,'Value')==0 && get(handles.CheckFix1,'Value')==0 && get(handles.CheckPatch1,'Value')==0)
2889    find_netcpair_civ2(handles);
2890end
2891%
[12]2892%------------------------------------------------------------------------
[309]2893% determine the menu for checkciv1 pairs depending on existing netcdf file at the middle of
2894% the field series set by first_i, incr, last_i
2895function find_netcpair_civ1(handles)
[12]2896%------------------------------------------------------------------------
[309]2897set(gcf,'Pointer','watch')
2898%nomenclature types
2899filebase=get(handles.RootName,'String');
2900[filepath,Nme,ext_dir]=fileparts(filebase);
2901browse=get(handles.RootName,'UserData');
2902compare_list=get(handles.ListCompareMode,'String');
2903val=get(handles.ListCompareMode,'Value');
2904compare=compare_list{val};
2905if strcmp(compare,'displacement')
2906    mode='displacement';
2907else
2908    mode_list=get(handles.ListPairMode,'String');
2909    mode_value=get(handles.ListPairMode,'Value');
2910    if isempty(mode_list)
2911        return
2912    end
2913    mode=mode_list{mode_value};
2914end
[289]2915
[309]2916% nomenclature type of the .nc files
2917nom_type_ima=[];%default
2918if isfield(browse,'nom_type_ima')
2919    nom_type_ima=browse.nom_type_ima;
2920end
2921
2922%determine nom_type_nc:
2923nom_type_nc=[];%default
2924if isfield(browse,'nom_type_nc')
2925    nom_type_nc=browse.nom_type_nc;
2926end
2927if isempty(nom_type_nc)
2928    [nom_type_nc]=nomtype2pair(nom_type_ima,isequal(mode,'series(Di)'),isequal(mode,'series(Dj)'));
2929end
2930browse.nom_type_nc=nom_type_nc;
2931set(handles.RootName,'UserData',browse)
2932
2933%reads .nc subdirectoy and image numbers from the interface
2934subdir_civ1=get(handles.txt_SubdirCiv1,'String');%subdirectory subdir_civ1 for the netcdf data
2935ref_i=str2double(get(handles.ref_i,'String'));
2936if isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
2937    ref_j=0;
2938else
2939    ref_j=str2double(get(handles.ref_j,'String'));
2940end
2941time=get(handles.ImaDoc,'UserData');%get the set of times
2942if isempty(time)
2943    time=[0 1];
2944end
2945dt_unit=1000;%default
2946displ_num=get(handles.ListPairCiv1,'UserData');
2947
2948%eliminate the first pairs inconsistent with the position
2949if isempty(displ_num)
2950    nbpair=0;
2951else
2952    nbpair=length(displ_num(1,:));%nbre of displayed pairs
2953    if  isequal(mode,'series(Di)')  %| isequal(mode,'st_series(Di)')
2954        nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
2955    elseif  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
2956        nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
2957    end
2958end
2959nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
2960
2961%look for existing processed pairs involving the field at the middle of the series if checkciv1 will not
2962% be performed, while the result is needed for next steps.
2963displ_pair={''};
2964select=ones(size(1:nbpair));%flag for displayed pairs =1 for display
2965testpair=0;
2966
2967%% case with no Civ1 operation, netcdf files need to exist for reading
2968if ~get(handles.CheckCiv1,'Value') %
2969    if ~exist(fullfile(filepath,subdir_civ1,ext_dir),'dir')
2970        msgbox_uvmat('ERROR',['no civ1 file available: subdirectory ' subdir_civ1 ' does not exist']);
2971        set(handles.ListPairCiv1,'String',{});
2972        return
2973    end
2974    for ipair=1:nbpair
2975        filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
2976            ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
2977        select(ipair)=exist(filename,'file')==2;% put flag to 0 if the file does not exist
2978    end   
2979    % case of no displayed pair
2980    if isequal(select,zeros(size(1:nbpair)))
2981        if isfield(browse,'incr_pair') && ~isequal(browse.incr_pair,[0 0])
2982            num_i1=ref_i-floor(browse.incr_pair(1)/2);
2983            num_i2=ref_i+ceil(browse.incr_pair(1)/2);
2984            num_j1=ref_j-floor(browse.incr_pair(2)/2);
2985            num_j2=ref_j+ceil(browse.incr_pair(2)/2);
2986            filename=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ1);
2987            select(1)=exist(filename,'file')==2;
2988            testpair=1;
2989        else
2990            if  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
2991                msgbox_uvmat('ERROR',['no civ1 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ1]);
2992            else
2993                msgbox_uvmat('ERROR',['no civ1 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ1]);
2994            end
2995            set(handles.ListPairCiv1,'String',{''});
2996            %COMPLETER CAS STEREO
2997            return
2998        end
2999    end
3000end
3001
3002%% determine the menu display in .ListPairCiv1
3003% the menu depends on the mode defined in ListPairMode_callback through the array displ_num:
3004% displ_num(1,:)=indices j1
3005% displ_num(2,:)=indices j2
3006% displ_num(3,:)=indices i1
3007% displ_num(4,:)=indices i2
3008% in mode 'pair j1-j2', j1 and j2 are the file indices, else the indices
3009% are relative to the reference indices ref_i and ref_j respectively.
3010if isequal(mode,'series(Di)')
3011    if testpair
3012        displ_pair{1}=['Di= ' num2str(-floor(browse.incr_pair(1)/2)) '|' num2str(ceil(browse.incr_pair(1)/2))];
3013    else
3014        for ipair=1:nbpair
3015            if select(ipair)
3016                displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2))];
3017                if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
3018                    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
3019                    displ_pair{ipair}=[displ_pair{ipair} ' :dt= ' num2str(dt*1000)];
3020                end
3021            else
3022                displ_pair{ipair}='...'; %pair not displayed in the menu
3023            end
3024        end
3025    end
3026elseif isequal(mode,'series(Dj)')
3027    if testpair
3028        displ_pair{1}=['Dj= ' num2str(-floor(browse.incr_pair(1)/2)) '|' num2str(ceil(browse.incr_pair(1)/2))];
3029    else
3030        for ipair=1:nbpair
3031            if select(ipair)
3032                displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2))];
3033                if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
3034                    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
3035                    displ_pair{ipair}=[displ_pair{ipair} ' :dt= ' num2str(dt*1000)];
3036                end
3037            else
3038                displ_pair{ipair}='...'; %pair not displayed in the menu
3039            end
3040        end
3041    end
3042elseif isequal(mode,'pair j1-j2')%case of pairs
3043    for ipair=1:nbpair
3044        if select(ipair)
3045            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
3046            displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
3047                ' :dt= ' num2str(dt*1000)];
3048        else
3049            displ_pair{ipair}='...'; %pair not displayed in the menu
3050        end
3051    end
3052elseif isequal(mode,'displacement')
3053    displ_pair={'Di=Dj=0'};
3054end
3055set(handles.ListPairCiv1,'String',displ_pair');
3056
3057%% determine the default selection in the pair menu
3058ichoice=find(select,1);% index of selected pair
3059if (isempty(ichoice) || ichoice < 1); ichoice=1; end;
3060initial=get(handles.ListPairCiv1,'Value');%initial choice of pair
3061if initial>nbpair || (numel(select)>=initial && ~isequal(select(initial),1))
3062    set(handles.ListPairCiv1,'Value',ichoice);% first valid pair proposed by default in the menu
3063end
3064initial=get(handles.ListPairCiv2,'Value');
3065if initial>length(displ_pair')%|~isequal(select(initial),1)
3066    if ichoice <= length(displ_pair')
3067        set(handles.ListPairCiv2,'Value',ichoice);% same pair proposed by default for civ2
3068    else
3069        set(handles.ListPairCiv2,'Value',1);% same pair proposed by default for civ2
3070    end
3071end
3072set(handles.ListPairCiv2,'String',displ_pair');
3073set(gcf,'Pointer','arrow')
3074
[289]3075%------------------------------------------------------------------------
[309]3076% determine the menu for checkciv2 pairs depending on the existing netcdf file at the
3077%middle of the series set by first_i, incr, last_i
3078function find_netcpair_civ2(handles)
[289]3079%------------------------------------------------------------------------
[309]3080set(gcf,'Pointer','watch')
3081%nomenclature types
3082filebase=get(handles.RootName,'String');
3083[filepath,Nme,ext_dir]=fileparts(filebase);
3084browse=get(handles.RootName,'UserData');
3085compare_list=get(handles.ListCompareMode,'String');
3086val=get(handles.ListCompareMode,'Value');
3087compare=compare_list{val};
3088if strcmp(compare,'displacement')
3089    mode='displacement';
3090else
3091    mode_list=get(handles.ListPairMode,'String');
3092    if isempty(mode_list)
3093        msgbox_uvmat('ERROR','please enter an input image or netcdf file')
[289]3094        return
3095    end
[309]3096    mode_value=get(handles.ListPairMode,'Value');
3097    mode=mode_list{mode_value};
[2]3098end
[309]3099
3100% nomenclature type of the .nc files
3101nom_type_ima='ima_num';%default
3102if isfield(browse,'nom_type_ima')
3103    nom_type_ima=browse.nom_type_ima;
3104end
3105nom_type_nc='_i1-i2';%default
3106if isfield(browse,'nom_type_nc')
3107    nom_type_nc=browse.nom_type_nc;
3108end
3109if isequal(nom_type_ima,'png_old') || isequal(nom_type_ima,'netc_old')|| isequal(nom_type_ima,'raw_SMD')|| isequal(nom_type_nc,'netc_old')
3110    nom_type_nc='netc_old';%nom_type for the netcdf files
3111elseif isequal(nom_type_ima,'none')||isequal(nom_type_nc,'none')
3112    nom_type_nc='none';
3113elseif isequal(nom_type_ima,'avi')||isequal(nom_type_ima,'_i')||isequal(nom_type_ima,'ima_num')||isequal(nom_type_nc,'_i1-i2')
3114    nom_type_nc='_i1-i2';
[289]3115else
[309]3116    if  isequal(mode,'series(Di)')%|isequal(mode,'st_series(Di)')
3117        nom_type_nc='_i1-i2_j'; % PIV in volume
[289]3118    else
[309]3119        nom_type_nc='_i_j1-j2';
[289]3120    end
3121end
[309]3122browse.nom_type_nc=nom_type_nc;
3123set(handles.RootName,'UserData',browse)
[2]3124
[309]3125%reads .nc subdirectory and image numbers from the interface
3126subdir_civ1=get(handles.txt_SubdirCiv1,'String');%subdirectory subdir_civ1 for the netcdf data
3127subdir_civ2=get(handles.txt_SubdirCiv2,'String');%subdirectory subdir_civ2 for the netcdf data
3128ref_i=str2double(get(handles.ref_i,'String'));
3129if isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
3130    ref_j=0;
3131else
3132    ref_j=str2double(get(handles.ref_j,'String'));
3133end
3134time=get(handles.ImaDoc,'UserData'); %get the set of times
3135if isempty(time)
3136    time=[0 1];%default
3137end
3138displ_num=get(handles.ListPairCiv1,'UserData');
3139
3140%eliminate the first pairs inconsistent with the position
3141if isempty(displ_num)
3142    nbpair=0;
3143else
3144    nbpair=length(displ_num(1,:));%nbre of displayed pairs
3145    if  isequal(mode,'series(Di)')% | isequal(mode,'st_series(Di)')
3146        nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
3147    elseif  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
3148        nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
3149    end
3150end
3151nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
3152
3153%% look for existing processed pairs at the reference indices if Civ1 will not
3154% be performed, while the result is needed for next steps.
3155displ_pair={''}; %default
3156select=ones(size(1:nbpair));%default =1 for numbers of displayed pairs
3157if ~get(handles.CheckCiv2,'Value') && ~get(handles.CheckCiv1,'Value') && ~get(handles.CheckFix1,'Value') && ~get(handles.CheckPatch1,'Value')
3158    if ~exist(fullfile(filepath,subdir_civ2,ext_dir),'dir')
3159        errordlg(['no civ2 file available: subdirectory ' subdir_civ2 ' does not exist'])
3160        set(handles.ListPairCiv2,'Value',1);
3161        set(handles.ListPairCiv2,'String',{''});
3162        return
3163    end
3164    for ipair=1:nbpair
3165        filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
3166            ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
3167        select(ipair)=exist(filename,'file')==2;
3168    end
3169    if  isequal(select,zeros(size(1:nbpair)))
3170        if isfield(browse,'incr_pair')
3171            num_i1=ref_i-floor(browse.incr_pair(1)/2);
3172            num_i2=ref_i+floor((browse.incr_pair(1)+1)/2);
3173            num_j1=ref_j-floor(browse.incr_pair(2)/2);
3174            num_j2=ref_j+floor((browse.incr_pair(2)+1)/2);
3175            filename=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ2);
3176            select(1)=exist(filename,'file')==2;
3177        else
3178            if  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
3179                errordlg(['no civ2 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ2])
3180            else
3181                errordlg(['no civ2 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ2])
3182            end
3183            set(handles.ListPairCiv2,'Value',1);
3184            set(handles.ListPairCiv2,'String',{''});
3185            return
3186        end
3187    end
3188end
3189if isequal(mode,'series(Di)')
3190    for ipair=1:nbpair
3191        if select(ipair)
3192            displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
3193            if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
3194                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
3195                displ_pair{ipair}=[displ_pair{ipair} ' :dt= ' num2str(dt*1000)];
3196            end
3197        else
3198            displ_pair{ipair}='...'; %pair not displayed in the menu
3199        end
3200    end
3201elseif isequal(mode,'series(Dj)') %| isequal(mode,'st_series(Dj)') % series on the j index
3202    for ipair=1:nbpair
3203        if select(ipair)
3204            displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
3205            if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
3206                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
3207                displ_pair{ipair}=[displ_pair{ipair} ' :dt= ' num2str(dt*1000)];
3208            end
3209        else
3210            displ_pair{ipair}='...'; %pair not displayed in the menu
3211        end
3212    end
3213elseif isequal(mode,'pair j1-j2')% | isequal(mode,'st_pair j1-j2') %case of pairs
3214    for ipair=1:nbpair
3215        if select(ipair)
3216            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
3217            displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
3218                ' :dt= ' num2str(dt*1000)];
3219        else
3220            displ_pair{ipair}='...'; %pair not displayed in the menu
3221        end
3222    end
3223elseif isequal(mode,'displacement')
3224    displ_pair={'Di=Dj=0'};
3225end
3226val=get(handles.ListPairCiv2,'Value');
3227ichoice=find(select,1);
3228if (isempty(ichoice) || ichoice < 1); ichoice=1; end;
3229if get(handles.CheckCiv2,'Value')==0 && get(handles.CheckCiv1,'Value')==0 && get(handles.CheckFix1,'Value')==0 && get(handles.CheckPatch1,'Value')==0
3230    val=ichoice;% first valid pair proposed by default in the menu
3231end
3232if val>length(displ_pair')
3233    set(handles.ListPairCiv2,'Value',1);% first valid pair proposed by default in the menu
3234else
3235    set(handles.ListPairCiv2,'Value',val);
3236end
3237set(handles.ListPairCiv2,'String',displ_pair');
3238set(gcf,'Pointer','arrow')
3239
3240
3241
3242
3243%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3244% Callbacks in the uipanel Reference Indices
3245%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[12]3246%------------------------------------------------------------------------
3247function first_i_Callback(hObject, eventdata, handles)
3248%------------------------------------------------------------------------
[137]3249first_i=str2double(get(handles.first_i,'String'));
[12]3250set(handles.ref_i,'String', num2str(first_i))% reference index for pair dt = first index
3251ref_i_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
[2]3252
[12]3253%------------------------------------------------------------------------
3254function first_j_Callback(hObject, eventdata, handles)
3255%------------------------------------------------------------------------
3256first_j=str2num(get(handles.first_j,'String'));
3257set(handles.ref_j,'String', num2str(first_j))% reference index for pair dt = first index
3258ref_j_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
[2]3259
[309]3260%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3261% Callbacks in the uipanel Civ1
3262%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[12]3263%------------------------------------------------------------------------
[287]3264% --- Executes on button press in SearchRange: determine the search range num_Searchx,num_Searchy
[273]3265function SearchRange_Callback(hObject, eventdata, handles)
[12]3266%------------------------------------------------------------------------
[2]3267%determine pair numbers
[273]3268if strcmp(get(handles.umin,'Visible'),'off')
3269    set(handles.u_title,'Visible','on')
3270    set(handles.v_title,'Visible','on')
3271    set(handles.umin,'Visible','on')
3272    set(handles.umax,'Visible','on')
3273    set(handles.vmin,'Visible','on')
3274    set(handles.vmax,'Visible','on')
3275    set(handles.CoordUnit,'Visible','on')
3276    set(handles.TimeUnit,'Visible','on')
3277    set(handles.slash_title,'Visible','on')
3278    set(handles.min_title,'Visible','on')
3279    set(handles.max_title,'Visible','on')
3280    set(handles.unit_title,'Visible','on')
3281else
3282    get_search_range(hObject, eventdata, handles)
[2]3283end
3284
[12]3285%------------------------------------------------------------------------
[287]3286% ---  determine the search range num_Searchx,num_Searchy and shift
[273]3287function get_search_range(hObject, eventdata, handles)
3288umin=str2double(get(handles.umin,'String'));
3289umax=str2double(get(handles.umax,'String'));
3290vmin=str2double(get(handles.umin,'String'));
3291vmax=str2double(get(handles.vmax,'String'));
3292%switch min_title and max_title in case of error
3293if umax<=umin
3294    umin_old=umin;
3295    umin=umax;
3296    umax=umin_old;
3297    set(handles.umin,'String', num2str(umin))
3298    set(handles.umax,'String', num2str(umax))
3299end
3300if vmax<=vmin
3301    vmin_old=vmin;
3302    vmin=vmax;
3303    vmax=vmin_old;
3304    set(handles.vmin,'String', num2str(vmin))
3305    set(handles.vmax,'String', num2str(vmax))
3306end   
3307if ~(isnan(umin)||isnan(umax)||isnan(vmin)||isnan(vmax))
[282]3308    list_pair=get(handles.ListPairCiv1,'String');%get the menu of image pairs
3309    index=get(handles.ListPairCiv1,'Value');
3310    displ_num=get(handles.ListPairCiv1,'UserData');
[273]3311    time=get(handles.ImaDoc,'UserData'); %get the set of times
3312    pxcm_xy=get(handles.SearchRange,'UserData');
3313    pxcmx=pxcm_xy(1);
3314    pxcmy=pxcm_xy(2);
[282]3315    mode_list=get(handles.ListPairMode,'String');
3316    mode_value=get(handles.ListPairMode,'Value');
[273]3317    mode=mode_list{mode_value};
3318    if isequal (mode, 'series(Di)' )
3319        ref_i=str2double(get(handles.ref_i,'String'));
3320        num1=ref_i-floor(index/2);%  first image numbers
3321        num2=ref_i+ceil(index/2);
3322        num_a=1;
3323        num_b=1;
3324    elseif isequal (mode, 'series(Dj)')
3325        num1=1;
3326        num2=1;
3327        ref_j=str2double(get(handles.ref_j,'String'));
3328        num_a=ref_j-floor(index/2);%  first image numbers
3329        num_b=ref_j+ceil(index/2);
3330    elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)
3331        ref_i=str2double(get(handles.ref_i,'String'));
3332        num1=ref_i;
3333        num2=ref_i;
3334        num_a=displ_num(1,index);
3335        num_b=displ_num(2,index);
3336    end
3337    dt=time(num2,num_b)-time(num1,num_a);
[282]3338    ibx=str2double(get(handles.num_Bx,'String'));
3339    iby=str2double(get(handles.num_By,'String'));
[273]3340    umin=dt*pxcmx*umin;
3341    umax=dt*pxcmx*umax;
3342    vmin=dt*pxcmy*vmin;
3343    vmax=dt*pxcmy*vmax;
3344    shiftx=round((umin+umax)/2);
3345    shifty=round((vmin+vmax)/2);
3346    isx=(umax+2-shiftx)*2+ibx;
3347    isx=2*ceil(isx/2)+1;
3348    isy=(vmax+2-shifty)*2+iby;
3349    isy=2*ceil(isy/2)+1;
[282]3350    set(handles.num_Shiftx,'String',num2str(shiftx));
3351    set(handles.num_Shifty,'String',num2str(shifty));
[287]3352    set(handles.num_Searchx,'String',num2str(isx));
3353    set(handles.num_Searchy,'String',num2str(isy));
[273]3354end
3355
[2]3356
[12]3357%------------------------------------------------------------------------
[282]3358% --- Executes on button press in CheckMask.
[2]3359function get_mask_fix1_Callback(hObject, eventdata, handles)
[12]3360%------------------------------------------------------------------------
[282]3361maskval=get(handles.CheckMask,'Value');
[2]3362if isequal(maskval,0)
[282]3363    set(handles.txt_MaskName,'String','')
[2]3364else
[112]3365    mask_displ='no mask'; %default
3366    filebase=get(handles.RootName,'String');
3367    [nbslice, flag_mask]=get_mask(filebase,handles);
3368    if isequal(flag_mask,1)
3369        mask_displ=[num2str(nbslice) 'mask'];
[282]3370    elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[71]3371        filebase_a=get(handles.RootName_1,'String');
[2]3372        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
[229]3373        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
[2]3374            mask_displ='no mask';
3375        end
[112]3376    end
3377    if isequal(mask_displ,'no mask')
3378        [FileName, PathName, filterindex] = uigetfile( ...
3379            {'*.png', ' (*.png)';
[12]3380            '*.png',  '.png files '; ...
3381            '*.*', 'All Files (*.*)'}, ...
3382            'Pick a mask file *.png',filebase);
[112]3383        mask_displ=fullfile(PathName,FileName);
3384        if ~exist(mask_displ,'file')
3385            mask_displ='no mask';
3386        end
[12]3387    end
[112]3388    if isequal(mask_displ,'no mask')
[282]3389        set(handles.CheckMask,'Value',0)
3390        set(handles.CheckMask,'Value',0)
3391        set(handles.CheckMask,'Value',0)
[112]3392    else
[282]3393        %set(handles.CheckMask,'Value',1)
3394        set(handles.CheckMask,'Value',1)
[112]3395    end
[282]3396    set(handles.txt_MaskName,'String',mask_displ)
[276]3397    set(handles.txt_Mask,'String',mask_displ)
[287]3398    set(handles.txt_MaskName,'String',mask_displ)
[12]3399end
3400
3401%------------------------------------------------------------------------
[282]3402% --- Executes on button press in CheckMask: select box for mask option
[2]3403function get_mask_civ2_Callback(hObject, eventdata, handles)
[12]3404%------------------------------------------------------------------------
[282]3405maskval=get(handles.CheckMask,'Value');
[2]3406if isequal(maskval,0)
[276]3407    set(handles.txt_Mask,'String','')
[2]3408else
[112]3409    mask_displ='no mask'; %default
3410    filebase=get(handles.RootName,'String');
3411    [nbslice, flag_mask]=get_mask(filebase,handles);
3412    if isequal(flag_mask,1)
3413        mask_displ=[num2str(nbslice) 'mask'];
[282]3414    elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[71]3415        filebase_a=get(handles.RootName_1,'String');
[2]3416        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
[229]3417        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
[2]3418            mask_displ='no mask';
3419        end
[112]3420    end
3421    if isequal(mask_displ,'no mask')
3422        [FileName, PathName, filterindex] = uigetfile( ...
3423            {'*.png', ' (*.png)';
[12]3424            '*.png',  '.png files '; ...
3425            '*.*', 'All Files (*.*)'}, ...
3426            'Pick a mask file *.png',filebase);
[112]3427        mask_displ=fullfile(PathName,FileName);
3428        if ~exist(mask_displ,'file')
3429            mask_displ='no mask';
3430        end
[12]3431    end
[112]3432    if isequal(mask_displ,'no mask')
[282]3433        set(handles.CheckMask,'Value',0)
3434        set(handles.CheckMask,'Value',0)
[112]3435    else
[282]3436        set(handles.CheckMask,'Value',1)
[112]3437    end
[276]3438    set(handles.txt_Mask,'String',mask_displ)
[287]3439    set(handles.txt_MaskName,'String',mask_displ)
[12]3440end
3441
3442%------------------------------------------------------------------------
[282]3443% --- Executes on button press in CheckMask.
[2]3444function get_mask_fix2_Callback(hObject, eventdata, handles)
[12]3445%------------------------------------------------------------------------
[282]3446maskval=get(handles.CheckMask,'Value');
[2]3447if isequal(maskval,0)
[287]3448    set(handles.txt_MaskName,'String','')
[2]3449else
[12]3450    mask_displ='no mask'; %default
[71]3451    filebase=get(handles.RootName,'String');
[12]3452    [nbslice, flag_mask]=get_mask(filebase,handles);
3453    if isequal(flag_mask,1)
[112]3454        mask_displ=[num2str(nbslice) 'mask'];
[282]3455    elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[112]3456        filebase_a=get(handles.RootName_1,'String');
3457        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
[229]3458        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
[112]3459            mask_displ='no mask';
3460        end
[12]3461    end
3462    if isequal(mask_displ,'no mask')
3463        [FileName, PathName, filterindex] = uigetfile( ...
[112]3464            {'*.png', ' (*.png)';
3465            '*.png',  '.png files '; ...
3466            '*.*', 'All Files (*.*)'}, ...
3467            'Pick a mask file *.png',filebase);
3468        mask_displ=fullfile(PathName,FileName);
[12]3469        if ~exist(mask_displ,'file')
[2]3470            mask_displ='no mask';
3471        end
[12]3472    end
3473    if isequal(mask_displ,'no mask')
[282]3474        set(handles.CheckMask,'Value',0)
[112]3475    end
[287]3476    set(handles.txt_MaskName,'String',mask_displ)
[2]3477end
3478
[12]3479%------------------------------------------------------------------------
3480% --- function called to look for mask files
[2]3481function [nbslice, flag_mask]=get_mask(filebase,handles)
[12]3482%------------------------------------------------------------------------
[112]3483%detect mask files, images with appropriate file base
[2]3484%[filebase '_' xx 'mask'], xx=nbslice
3485%flag_mask=1 indicates detection
3486
3487flag_mask=0;%default
3488nbslice=1;
3489
[289]3490% subdir=get(handles.txt_SubdirCiv1,'String');
[2]3491[Path,Name]=fileparts(filebase);
[12]3492if ~isdir(Path)
3493    msgbox_uvmat('ERROR','no path for input files')
3494    return
3495end
[272]3496% currentdir=pwd;
3497% cd(Path);%move in the dir of the root name filebase
3498maskfiles=dir(fullfile(Path,[Name '_*mask_*.png']));%look for mask files
3499% cd(currentdir);%come back to the current working directory
[12]3500if ~isempty(maskfiles)
[112]3501    %     msgbox_uvmat('ERROR','no mask available, to create it use Tools/Make mask in the upper menu bar of uvmat')
3502    % else
[2]3503    flag_mask=1;
3504    maskname=maskfiles(1).name;% take the first mask file in the list
3505    [Path2,Name,ext]=fileparts(maskname);
3506    Namedouble=double(Name);
3507    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
3508    ind_mask=findstr('mask',Name);
3509    i=ind_mask-1;
[137]3510    while val(i)==0 && i>0
[112]3511        i=i-1;
[2]3512    end
[137]3513    nbslice=str2double(Name(i+1:ind_mask-1));
3514    if ~isnan(nbslice) && Name(i)=='_'
[112]3515        flag_mask=1;
[2]3516    else
[112]3517        msgbox_uvmat('ERROR',['bad mask file ' Name ext ' found in ' Path2])
3518        return
3519        nbslice=1;
[2]3520    end
[112]3521end
[2]3522
[12]3523%------------------------------------------------------------------------
3524% --- function called to look for grid files
[2]3525function [nbslice, flag_mask]=get_grid(filebase,handles)
[12]3526%------------------------------------------------------------------------
[2]3527flag_mask=0;%default
3528nbslice=1;
3529[Path,Name]=fileparts(filebase);
3530currentdir=pwd;
3531cd(Path);%move in the dir of the root name filebase
3532maskfiles=dir([Name '_*grid_*.grid']);%look for mask files
3533cd(currentdir);%come back to the current working directory
3534if ~isempty(maskfiles)
3535    flag_mask=1;
3536    maskname=maskfiles(1).name;% take the first mask file in the list
3537    [Path2,Name,ext]=fileparts(maskname);
3538    Namedouble=double(Name);
3539    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
3540    ind_mask=findstr('grid',Name);
3541    i=ind_mask-1;
[137]3542    while val(i)==0 && i>0
[112]3543        i=i-1;
[2]3544    end
[137]3545    nbslice=str2double(Name(i+1:ind_mask-1));
3546    if ~isnan(nbslice) && Name(i)=='_'
[112]3547        flag_mask=1;
[2]3548    else
[112]3549        msgbox_uvmat('ERROR',['bad grid file ' Name ext ' found in ' Path2])
3550        return
3551        nbslice=1;
[2]3552    end
[12]3553end
[2]3554
[12]3555%------------------------------------------------------------------------
3556% --- transform numbers to letters
[122]3557function str=num2stra(num,nom_type)
[12]3558%------------------------------------------------------------------------
[122]3559if isempty(nom_type)
3560    str='';
3561elseif strcmp(nom_type(end),'a')
[2]3562    str=char(96+num);
[122]3563elseif strcmp(nom_type(end),'A')
3564    str=char(96+num);
3565elseif isempty(nom_type(2:end))%a single index
[2]3566    str='';
3567else
3568    str=num2str(num);
3569end
[12]3570
3571%------------------------------------------------------------------------
[282]3572% --- Executes on button press in ListSubdirCiv1.
3573function ListSubdirCiv1_Callback(hObject, eventdata, handles)
[12]3574%------------------------------------------------------------------------
[282]3575list_subdir_civ1=get(handles.ListSubdirCiv1,'String');
3576val=get(handles.ListSubdirCiv1,'Value');
[273]3577subdir=list_subdir_civ1{val};
3578if strcmp(subdir,'new...')
[301]3579    if get(handles.CheckCiv1,'Value')
3580        subdir='CIV'; %default subdirectory
3581    else
3582        msgbox_uvmat('ERROR','select CheckCiv1 to perform a new Civ operation')
3583        return
3584    end   
[2]3585end
[289]3586set(handles.txt_SubdirCiv1,'String',subdir);
[301]3587find_netcpair_civ1(handles)
[2]3588
[12]3589%------------------------------------------------------------------------
[289]3590% --- Executes on button press in ListSubdirCiv2.
3591function ListSubdirCiv2_Callback(hObject, eventdata, handles)
[12]3592%------------------------------------------------------------------------
[289]3593list_subdir_civ2=get(handles.ListSubdirCiv2,'String');
3594val=get(handles.ListSubdirCiv2,'Value');
[273]3595subdir=list_subdir_civ2{val};
3596if strcmp(subdir,'new...')
[301]3597    if get(handles.CheckCiv2,'Value')
3598        subdir='CIV'; %default subdirectory
3599    else
3600        msgbox_uvmat('ERROR','select CheckCiv2 to perform a new Civ operation')
3601        return
3602    end
[2]3603end
[289]3604set(handles.txt_SubdirCiv2,'String',subdir);
[2]3605
[12]3606%------------------------------------------------------------------------
[282]3607% --- Executes on button press in CheckGrid.
3608function CheckGrid_Callback(hObject, eventdata, handles)
[12]3609%------------------------------------------------------------------------
[276]3610value=get(hObject,'Value');
3611hparent=get(hObject,'parent');
3612hchildren=get(hparent,'children');
3613handle_txtbox=findobj(hchildren,'tag','txt_GridName');
3614handle_dx=findobj(hchildren,'tag','num_Dx');
3615handle_dy=findobj(hchildren,'tag','num_Dy');
[2]3616testgrid=0;
[276]3617filegrid='';
[2]3618if value
[112]3619    filebase=get(handles.RootName,'String');
[276]3620    [nbslice, flag_grid]=get_grid(filebase,handles);% look for a grid with appropriate name
[2]3621    if isequal(flag_grid,1)
[112]3622        filegrid=[num2str(nbslice) 'grid'];
3623        testgrid=1;
[276]3624    else % browse for a grid
3625        filegrid=get(hObject,'UserData');%look for previous grid name stored as UserData
3626        if exist(filegrid,'file')
3627            filebase=filegrid;
3628        end
[2]3629        [FileName, PathName, filterindex] = uigetfile( ...
[112]3630            {'*.grid', ' (*.grid)';
3631            '*.grid',  '.grid files '; ...
3632            '*.*', 'All Files (*.*)'}, ...
3633            'Pick a file',filebase);
[2]3634        filegrid=fullfile(PathName,FileName);
[276]3635        set(hObject,'UserData',filegrid);%store for future use
[2]3636        if ~(isempty(FileName)||isempty(PathName)||isequal(FileName,0)||~exist(filegrid,'file'))
3637            testgrid=1;
3638        end
[112]3639    end
[2]3640end
3641if testgrid
[276]3642    set(handle_dx,'Visible','off');
3643    set(handle_dy,'Visible','off');
3644    set(handle_txtbox,'Visible','on')
3645    set(handle_txtbox,'String',filegrid)
[112]3646else
[276]3647    set(hObject,'Value',0);
3648    set(handle_dx,'Visible','on');
3649    set(handle_dy,'Visible','on');
3650    set(handle_txtbox,'Visible','off')
[2]3651end
3652
[282]3653%% if hObject is on the checkciv1 frame, duplicate action for checkciv2 frame
[276]3654PanelName=get(hparent,'tag');
3655if strcmp(PanelName,'panel_Civ1')
[282]3656    hchildren=get(handles.Civ2,'children');
[276]3657    handle_checkbox=findobj(hchildren,'tag','check_Grid');
3658    handle_txtbox=findobj(hchildren,'tag','txt_GridName');
3659    handle_dx=findobj(hchildren,'tag','num_Dx');
3660    handle_dy=findobj(hchildren,'tag','num_Dy');
3661    set(handle_checkbox,'UserData',filegrid);%store for future use
3662    if testgrid
3663        set(handle_checkbox,'Value',1);
3664        set(handle_dx,'Visible','off');
3665        set(handle_dy,'Visible','off');
3666        set(handle_txtbox,'Visible','on')
3667        set(handle_txtbox,'String',filegrid)
3668    else
3669        set(handle_checkbox,'Value',0);
[282]3670        set(handles.CheckGrid,'Value',0);
[276]3671        set(handle_dx,'Visible','on');
3672        set(handle_dy,'Visible','on');
3673        set(handle_txtbox,'Visible','off')
3674    end
3675end
[12]3676%------------------------------------------------------------------------
[282]3677% --- Executes on button press in CheckMask.
3678function CheckMask_Callback(hObject, eventdata, handles)
[276]3679%------------------------------------------------------------------------
3680value=get(hObject,'Value');
3681testmask=0;
3682if value
3683    filebase=get(handles.RootName,'String');
3684    [nbslice, flag_mask]=get_mask(filebase,handles);% look for a mask with appropriate name
3685    if isequal(flag_mask,1)
3686        filemask=[num2str(nbslice) 'mask'];
3687        testmask=1;
3688    else % browse for a mask
[282]3689        filemask=get(handles.CheckMask,'UserData');%look for previous mask name stored as UserData
[276]3690        if exist(filemask,'file')
3691            filebase=filemask;
3692        end
3693        [FileName, PathName, filterindex] = uigetfile( ...
3694            {'*.png', ' (*.png)';
3695            '*.png',  '.png files '; ...
3696            '*.*', 'All Files (*.*)'}, ...
3697            'Pick a mask file *.png',filebase);
3698        filemask=fullfile(PathName,FileName);
[282]3699        set(handles.CheckMask,'UserData',filemask);%store for future use
[276]3700        if ~(isempty(FileName)||isempty(PathName)||isequal(FileName,0)||~exist(filemask,'file'))
3701            testmask=1;
3702        end
3703    end
3704end
3705if testmask
3706    set(handles.num_Dx,'Visible','off');
3707    set(handles.num_Dy,'Visible','off');
3708    set(handles.num_Dx,'Visible','off');
3709    set(handles.num_Dy,'Visible','off');
3710    set(handles.txt_MaskName,'Visible','on')
3711    set(handles.txt_MaskName,'String',filemask)
3712else
[282]3713    set(handles.CheckMask,'Value',0);
3714    set(handles.CheckGrid,'Value',0);
[276]3715    set(handles.num_Dx,'Visible','on');
3716    set(handles.num_Dy,'Visible','on');
3717    set(handles.num_Dx,'Visible','on');
3718    set(handles.num_Dy,'Visible','on');
3719    set(handles.txt_MaskName,'Visible','off')
3720end
3721
[2]3722
3723% --- Executes on button press in get_gridpatch1.
3724function get_gridpatch1_Callback(hObject, eventdata, handles)
3725% hObject    handle to get_gridpatch1 (see GCBO)
[309]3726% eventdata  reserved - to be defined in a future version of MENUMATLAB
[2]3727% handles    structure with handles and user data (see GUIDATA)
3728
[71]3729filebase=get(handles.RootName,'String');
[2]3730[FileName, PathName, filterindex] = uigetfile( ...
[112]3731    {'*.grid', ' (*.grid)';
3732    '*.grid',  '.grid files '; ...
3733    '*.*', 'All Files (*.*)'}, ...
3734    'Pick a file',filebase);
[2]3735filegrid=fullfile(PathName,FileName);
3736set(handles.grid_patch1,'string',filegrid);
3737% set(handles.grid_patch2,'string',filegrid
3738
[12]3739%------------------------------------------------------------------------
[2]3740% --- Executes on button press in get_gridpatch2.
3741function get_gridpatch2_Callback(hObject, eventdata, handles)
[12]3742%------------------------------------------------------------------------
[2]3743
3744
[12]3745%------------------------------------------------------------------------
[309]3746% --- STEREO Interp
3747function 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]3748%------------------------------------------------------------------------
[309]3749namelog=[filename_nc(1:end-3) '_stinterp.log'];
3750cmd=[stinterpBin ' -f1 ' filename_A_nc  ' -f2 ' filename_B_nc ' -f  ' filename_nc ...
3751    ' -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
[273]3752
[12]3753%------------------------------------------------------------------------
[2]3754%--read images and convert them to the uint16 format used for PIV
[45]3755function A=read_image(filename,type_ima,num,movieobject)
[12]3756%------------------------------------------------------------------------
[2]3757%num is the view number needed for an avi movie
[45]3758switch type_ima
3759    case 'movie'
3760        A=read(movieobject,num);
3761    case 'avi'
[112]3762        mov=aviread(filename,num);
3763        A=frame2im(mov(1));
[45]3764    case 'multimage'
3765        A=imread(filename,num);
[112]3766    case 'image'
[45]3767        A=imread(filename);
3768end
3769siz=size(A);
3770if length(siz)==3;%color images
[2]3771    A=sum(double(A),3);
3772    A=uint16(A);
3773end
3774
3775
[12]3776%------------------------------------------------------------------------
[2]3777% --- Executes on button press in get_ref_fix1.
3778function get_ref_fix1_Callback(hObject, eventdata, handles)
[12]3779%------------------------------------------------------------------------
[71]3780filebase=get(handles.RootName,'String');
[2]3781[FileName, PathName, filterindex] = uigetfile( ...
[112]3782    {'*.nc', ' (*.nc)';
3783    '*.nc',  'netcdf files '; ...
3784    '*.*', 'All Files (*.*)'}, ...
3785    'Pick a file',filebase);
3786
[2]3787fileinput=[PathName FileName];
3788sizf=size(fileinput);
[122]3789if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
[2]3790[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
3791ref.filebase=fullfile(Path,File);
3792ref.num_a=stra2num(str_a);
3793ref.num_b=stra2num(str_b);
[89]3794ref.num1=str2double(field_count);
3795ref.num2=str2double(str2);
[2]3796browse=[];%initialisation
3797if ~isequal(ref.ext,'.nc')
3798    msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
3799    return
3800end
3801set(handles.ref_fix1,'String',[fullfile(ref.subdir,File) '....nc']);
3802set(handles.ref_fix1,'UserData',ref)
3803menu_field{1}='civ1';
3804Data=nc2struct(fileinput,[]);
[45]3805if isfield(Data,'patch') && isequal(Data.patch,1)
[2]3806    menu_field{2}='filter1';
3807end
[45]3808if isfield(Data,'civ2') && isequal(Data.civ2,1)
[2]3809    menu_field{3}='civ2';
3810end
[45]3811if isfield(Data,'patch2') && isequal(Data.patch2,1)
[2]3812    menu_field{4}='filter2';
3813end
3814set(handles.field_ref1,'String',menu_field);
3815set(handles.field_ref1,'Value',length(menu_field));
[287]3816set(handles.num_MinVel,'Value',2);
3817set(handles.num_MinVel,'String','1');%default threshold
[2]3818set(handles.ref_fix1,'Enable','on')
[12]3819
3820%------------------------------------------------------------------------
[2]3821% --- Executes on button press in get_ref_fix2.
3822function get_ref_fix2_Callback(hObject, eventdata, handles)
[12]3823%------------------------------------------------------------------------
[2]3824if isequal(get(handles.get_ref_fix2,'Value'),1)
[71]3825    filebase=get(handles.RootName,'String');
[2]3826    [FileName, PathName, filterindex] = uigetfile( ...
[112]3827        {'*.nc', ' (*.nc)';
3828        '*.nc',  'netcdf files '; ...
3829        '*.*', 'All Files (*.*)'}, ...
3830        'Pick a file',filebase);
[2]3831    fileinput=[PathName FileName];
3832    sizf=size(fileinput);
[45]3833    if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
[2]3834    [Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
3835    ref.filebase=fullfile(Path,File);
3836    ref.num_a=stra2num(str_a);
3837    ref.num_b=stra2num(str_b);
3838    ref.num1=str2num(field_count);
3839    ref.num2=str2num(str2);
3840    browse=[];%initialisation
3841    if ~isequal(ref.ext,'.nc')
3842        msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
3843        return
3844    end
3845    set(handles.ref_fix2,'String',[fullfile(ref.subdir,File) '....nc']);
[112]3846    set(handles.ref_fix2,'UserData',ref)
[2]3847    menu_field{1}='civ1';
3848    Data=nc2struct(fileinput,[]);
[301]3849    if isfield(Data,'patch') && isequal(Data.patch,1)
[2]3850        menu_field{2}='filter1';
3851    end
[301]3852    if isfield(Data,'civ2') && isequal(Data.civ2,1)
[2]3853        menu_field{3}='civ2';
3854    end
[301]3855    if isfield(Data,'patch2') && isequal(Data.patch2,1)
[2]3856        menu_field{4}='filter2';
3857    end
3858    set(handles.field_ref2,'String',menu_field);
3859    set(handles.field_ref2,'Value',length(menu_field));
[287]3860    set(handles.num_MinVel,'Value',2);
3861    set(handles.num_MinVel,'String','1');%default threshold
[2]3862    set(handles.ref_fix2,'Enable','on')
3863    set(handles.ref_fix2,'Visible','on')
3864    set(handles.field_ref2,'Visible','on')
3865else
3866    set(handles.ref_fix2,'Visible','off')
3867    set(handles.field_ref2,'Visible','off')
3868end
3869
[12]3870%------------------------------------------------------------------------
[2]3871function ref_fix1_Callback(hObject, eventdata, handles)
[12]3872%------------------------------------------------------------------------
[287]3873set(handles.num_MinVel,'Value',1);
[12]3874set(handles.field_ref1,'Value',1)
3875set(handles.field_ref1,'String',{' '})
3876set(handles.ref_fix1,'UserData',[]);
3877set(handles.ref_fix1,'String','');
3878set(handles.thresh_vel1,'String','0');
[112]3879
[12]3880%------------------------------------------------------------------------
[2]3881function ref_fix2_Callback(hObject, eventdata, handles)
[12]3882%------------------------------------------------------------------------
[287]3883set(handles.num_MinVel,'Value',1);
[12]3884set(handles.field_ref2,'Value',1)
3885set(handles.field_ref2,'String',{' '})
3886set(handles.ref_fix2,'UserData',[]);
3887set(handles.ref_fix2,'String','');
[287]3888set(handles.num_MinVel,'String','0');
[2]3889
[12]3890%------------------------------------------------------------------------
[2]3891% --- Executes on button press in test_stereo1.
3892function test_stereo1_Callback(hObject, eventdata, handles)
[12]3893%------------------------------------------------------------------------
[2]3894if isequal(get(handles.test_stereo1,'Value'),0)
3895    set(handles.subdomain_patch1,'Visible','on')
3896    set(handles.rho_patch1,'Visible','on')
3897else
3898    set(handles.subdomain_patch1,'Visible','off')
3899    set(handles.rho_patch1,'Visible','off')
3900end
3901
[12]3902%------------------------------------------------------------------------
[282]3903% --- Executes on button press in CheckStereo.
[273]3904function StereoCheck_Callback(hObject, eventdata, handles)
[12]3905%------------------------------------------------------------------------
[282]3906if isequal(get(handles.CheckStereo,'Value'),0)
[274]3907    set(handles.num_SubdomainSize,'Visible','on')
[292]3908    set(handles.num_SmoothingParam,'Visible','on')
[2]3909else
[274]3910    set(handles.num_SubdomainSize,'Visible','off')
[292]3911    set(handles.num_SmoothingParam,'Visible','off')
[2]3912end
3913
[12]3914%------------------------------------------------------------------------
[225]3915% --- Executes on button press in TestCiv1: display image correlation function
[150]3916function TestCiv1_Callback(hObject, eventdata, handles)
[224]3917%------------------------------------------------------------------------
[233]3918set(handles.TestCiv1,'BackgroundColor',[1 1 0])
3919drawnow
[309]3920if get(handles.TestCiv1,'Value')
[227]3921    ref_i=str2double(get(handles.ref_i,'String'));
3922    if strcmp(get(handles.ref_j,'Visible'),'on')
3923        ref_j=str2double(get(handles.ref_j,'String'));
3924    else
3925        ref_j=1;%default
3926    end
[224]3927    [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]3928        set_civ_filenames(handles,ref_i,ref_j,[1 0 0 0 0 0]);
[224]3929    Data.ListVarName={'ny','nx','A'};
3930    Data.VarDimName={'ny','nx',{'ny','nx'}};
3931    Data.A=imread(filecell.ima1.civ1{1});
3932    Data.ny=[size(Data.A,1) 1];
3933    Data.nx=[1 size(Data.A,2)];
[309]3934    par_civ1=read_GUI(handles.Civ1);
[231]3935    par_civ1.filename_ima_a=filecell.ima1.civ1{1};
3936    par_civ1.filename_ima_b=filecell.ima2.civ1{1};
3937    par_civ1.T0=0;
3938    par_civ1.Dt=1;
[246]3939    Param.Civ1=par_civ1;
3940    Data=civ_uvmat(Param);
[231]3941    Data.ListVarName=[Data.ListVarName {'ny','nx','A'}];
3942    Data.VarDimName=[Data.VarDimName {'ny','nx',{'ny','nx'}}];
3943    Data.A=imread(filecell.ima1.civ1{1});
3944    Data.ny=[size(Data.A,1) 1];
3945    Data.nx=[1 size(Data.A,2)];
3946    hview_field=view_field(Data);
3947    set(0,'CurrentFigure',hview_field)
3948    hhview_field=guihandles(hview_field);
3949    set(hview_field,'CurrentAxes',hhview_field.axes3)
3950    ViewData=get(hview_field,'UserData');
3951    ViewData.CivHandle=handles.civ;% indicate the handle of the civ GUI in view_field
[224]3952    ViewData.axes3.B=imread(filecell.ima2.civ1{1});%store the second image in the UserData of the GUI view_field
[236]3953    ViewData.axes3.X=Data.Civ1_X; %keep the set of points in memeory
3954    ViewData.axes3.Y=Data.Civ1_Y;
[231]3955    set(hview_field,'UserData',ViewData)
[224]3956    corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
3957    if isempty(corrfig)
3958        corrfig=figure;
3959        set(corrfig,'tag','corrfig')
3960        set(corrfig,'name','image correlation')
3961        set(corrfig,'DeleteFcn',{@closeview_field})%
3962    end
[233]3963    set(handles.TestCiv1,'BackgroundColor',[1 0 0])
[224]3964else
3965    corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
3966    if ~isempty(corrfig)
3967        delete(corrfig)
3968    end
3969    hview_field=findobj(allchild(0),'tag','view_field');% look for view_field   
3970    if ~isempty(hview_field)
3971        delete(hview_field)
3972    end
[150]3973end
[71]3974
[309]3975%-------------------------------------------------------------------
3976% ---
[224]3977function closeview_field(gcbo,eventdata)
3978hview_field=findobj(allchild(0),'tag','view_field');% look for view_field   
3979    if ~isempty(hview_field)
3980        delete(hview_field)
3981    end
[177]3982   
[309]3983   
[252]3984%------------------------------------------------------------------------   
3985% call 'view_field.fig' to display the  field selected in the list of 'status'
[177]3986function open_view_field(hObject, eventdata)
[252]3987%------------------------------------------------------------------------
3988list=get(hObject,'String');
3989index=get(hObject,'Value');
3990rootroot=get(hObject,'UserData');
3991filename=list{index};
3992ind_dot=findstr(filename,'...');
3993filename=filename(1:ind_dot-1);
3994filename=fullfile(rootroot,filename);
3995delete(get(hObject,'parent'))%delete the display figure to stop the check process
3996if exist(filename,'file')%visualise the vel field if it exists
3997    uvmat(filename)
3998    set(gcbo,'Value',1)
3999end
[150]4000
[252]4001%------------------------------------------------------------------------   
4002% launched by pressing OK on the status figure
[182]4003function close_GUI(hObject, eventdata)
[252]4004%------------------------------------------------------------------------
4005    delete(gcbf)
4006   
4007%------------------------------------------------------------------------   
4008% launched by deleting the status figure
4009function stop_status(hObject, eventdata)
4010%------------------------------------------------------------------------
4011hciv=findobj(allchild(0),'tag','civ');
4012hhciv=guidata(hciv);
4013set(hhciv.status,'value',0) %reset the status uicontrol in the GUI civ
4014set(hhciv.status,'BackgroundColor',[0 1 0])
[220]4015
[252]4016%------------------------------------------------------------------------
[282]4017% % --- Executes on button press in ListPairMode.
[273]4018% function CivMode_Callback(hObject, eventdata, handles)
4019% %------------------------------------------------------------------------
[282]4020% Listprog=get(handles.ListPairMode,'String');
4021% index=get(handles.ListPairMode,'Value');
[273]4022% prog=Listprog{index};
4023% switch prog
[309]4024%     case 'MenuCivX'
[273]4025%         set(handles.thresh_patch1,'Visible','off')
4026%         set(handles.thresh_text1,'Visible','off')
[274]4027%         set(handles.num_MaxDiff,'Visible','off')
[273]4028%         set(handles.thresh_text2,'Visible','off')
[282]4029%         set(handles.num_Rho,'Style','edit')
4030%         set(handles.num_Rho,'String','1')
[273]4031%         set(handles.BATCH,'Enable','on')
4032%     case 'CivAll'
[282]4033%         if get(handles.CheckPatch1,'Value')
[273]4034%             set(handles.thresh_patch1,'Visible','on')
4035%             set(handles.thresh_text1,'Visible','on')
4036%         end
[282]4037%         set(handles.num_Rho,'Style','edit')
4038%         set(handles.num_Rho,'String','1')
[273]4039%         set(handles.BATCH,'Enable','on')
4040%     case 'CivUvmat'
4041%       
4042% end
4043
4044
4045
4046
[309]4047%------------------------------------------------------------------------
[284]4048function cmd=cmd_civ1(filename,Param)
4049%------------------------------------------------------------------------
4050%pixels per cm and matrix of the image times, read from the .civ file by uvmat
4051%changes : filename_cmx -> filename ( no extension )
[309]4052filename=regexprep(filename,'.nc',''); %file name for the result
4053Param.Civ1
[284]4054if isequal(Param.Civ1.Dt,'0')
4055    Param.Civ1.Dt='1' ;%case of 'displacement' mode
4056end
4057Param.Civ1.filename_ima_a=regexprep(Param.Civ1.filename_ima_a,'.png','');
4058Param.Civ1.filename_ima_b=regexprep(Param.Civ1.filename_ima_b,'.png','');
4059fid=fopen([filename '.civ1.cmx'],'w');
4060fprintf(fid,['##############   CMX file' '\n' ]);
4061fprintf(fid,   ['FirstImage ' regexprep(Param.Civ1.filename_ima_a,'\\','\\\\') '\n' ]);% for windows compatibility
4062fprintf(fid,   ['LastImage  ' regexprep(Param.Civ1.filename_ima_b,'\\','\\\\') '\n' ]);% for windows compatibility
4063fprintf(fid,  ['XX' '\n' ]);
[285]4064fprintf(fid,  ['Mask ' Param.Civ1.MaskFlag '\n' ]);
4065fprintf(fid,  ['MaskName ' regexprep(Param.Civ1.MaskName,'\\','\\\\') '\n' ]);
[309]4066fprintf(fid,   ['ImageSize ' num2str(Param.Civ1.ImageInfo.Width) ' ' num2str(Param.Civ1.ImageInfo.Height) '\n' ]);   %VERIFIER CAS GENERAL ?
[284]4067fprintf(fid,   ['CorrelationBoxesSize ' num2str(Param.Civ1.Bx) ' ' num2str(Param.Civ1.By) '\n' ]);
[287]4068fprintf(fid,   ['SearchBoxeSize ' num2str(Param.Civ1.Searchx) ' ' num2str(Param.Civ1.Searchy) '\n' ]);
[284]4069fprintf(fid,   ['RO ' num2str(Param.Civ1.Rho) '\n' ]);
4070fprintf(fid,   ['GridSpacing ' num2str(Param.Civ1.Dx) ' ' num2str(Param.Civ1.Dy) '\n' ]);
4071fprintf(fid,   ['XX 1.0' '\n' ]);
4072fprintf(fid,   ['Dt_TO ' num2str(Param.Civ1.Dt) ' ' num2str(Param.Civ1.T0) '\n' ]);
4073fprintf(fid,  ['PixCmXY ' num2str(Param.Civ1.pxcmx) ' ' num2str(Param.Civ1.pxcmy) '\n' ]);
4074fprintf(fid,  ['XX 1' '\n' ]);
4075fprintf(fid,   ['ShiftXY ' num2str(Param.Civ1.Shiftx) ' '  num2str(Param.Civ1.Shifty) '\n' ]);
[285]4076fprintf(fid,  ['Grid ' Param.Civ1.GridFlag '\n' ]);
4077fprintf(fid,   ['GridName ' regexprep(Param.Civ1.GridName,'\\','\\\\') '\n' ]);
[284]4078fprintf(fid,   ['XX 85' '\n' ]);
4079fprintf(fid,   ['XX 1.0' '\n' ]);
4080fprintf(fid,   ['XX 1.0' '\n' ]);
4081fprintf(fid,   ['Hart 1' '\n' ]);
4082fprintf(fid,  [ 'DecimalShift 0' '\n' ]);
4083fprintf(fid,   ['Deformation 0' '\n' ]);
4084fprintf(fid,  ['CorrelationMin 0' '\n' ]);
4085fprintf(fid,   ['IntensityMin 0' '\n' ]);
[309]4086if ~isfield(Param.Civ1,'MinIma')% Image threshold not activated
4087    fprintf(fid,  ['SeuilImage n' '\n' ]);
4088    fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);%not used in principle
4089else% Image threshold  activated
4090    if isempty(Param.Civ1.MaxIma)||isnan(Param.Civ1.MaxIma)
4091        Param.Civ1.MaxIma=2^Param.Civ1.ImageInfo.BitDepth;%take the max image value as upper bound by default
4092    end
4093    fprintf(fid,  ['SeuilImage y' '\n' ]);
4094    fprintf(fid,   ['SeuilImageValues ' num2str(Param.Civ1.MinIma) ' ' num2str(Param.Civ1.MaxIma) '\n' ]);
4095end
[284]4096fprintf(fid,   ['ImageToUse ' Param.Civ1.term_a ' ' Param.Civ1.term_b '\n' ]); % VERIFIER ?
4097fprintf(fid,   ['ImageUsedBefore null null' '\n' ]);
4098fclose(fid);
4099
[309]4100if(isunix) %unix (or Mac) system
[284]4101    cmd=['cp -f ' filename '.civ1.cmx ' filename '.cmx \n '];% the cmx file gives the name to the nc file
4102    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
4103    cmd=[cmd 'rm ' filename '.cmx'];
4104else %Windows system
4105    filename=regexprep(filename,'\\','\\\\');
4106    cmd=['copy /Y "' filename '.civ1.cmx" "' filename '.cmx" \n '];
4107    cmd=[cmd '"' regexprep(Param.xml.Civ1Bin,'\\','\\\\')...
4108        '" -f "' filename '.cmx" >"' filename '.civ1.log" \n ' ]; % redirect standard output to the log file
[290]4109    cmd=[cmd 'del "' filename '.cmx"'];
[284]4110end
[285]4111
4112
4113function cmd=cmd_fix(filename,Param,fixname)
4114%%
[291]4115switch fixname
4116    case 'Fix1'
4117        fi2_value=num2str(Param.(fixname).CheckF2);
4118    case 'Fix2'
4119        fi2_value=num2str(Param.(fixname).CheckF4);%need to understand why...
4120end
[285]4121filename=regexprep(filename,'.nc','');
[287]4122MaskName_string='';%default
4123if Param.(fixname).CheckMask
[288]4124    MaskName_string=[' -maskName "' Param.(fixname).MaskName '"'];
[287]4125end
4126MaxVel_string='';%default
4127if ~isempty(Param.(fixname).MaxVel)
[289]4128    MaxVel_string=[' -threshV ' num2str(Param.(fixname).MaxVel)];
[287]4129end
[285]4130if isunix
[287]4131    cmd=[Param.xml.FixBin ' -f ' filename '.nc -fi1 ' num2str(Param.(fixname).CheckFmin2) ...
[291]4132        ' -fi2 ' fi2_value ' -fi3 ' num2str(Param.(fixname).CheckF3) ...
[287]4133        ' -threshC ' num2str(Param.(fixname).MinCorr) MaxVel_string MaskName_string...
4134        ' >' filename '.' lower(fixname) '.log 2>&1'];
[285]4135else
4136    cmd=['"' Param.xml.FixBin '" -f "' filename '.nc" -fi1 ' num2str(Param.(fixname).CheckFmin2)...
[291]4137        ' -fi2 ' fi2_value ' -fi3 ' num2str(Param.(fixname).CheckF3) ...
[288]4138        ' -threshC ' num2str(Param.(fixname).MinCorr) MaxVel_string MaskName_string...
4139        ' > "' filename '.' lower(fixname) '.log"'];
[285]4140    cmd=regexprep(cmd,'\\','\\\\');
4141end
[286]4142
4143
4144function cmd=cmd_patch(filename,Param,patchname)
4145%% ------------------------------------------------------------------------
4146filename=regexprep(filename,'.nc','');
4147if isunix
4148    cmd=[Param.xml.PatchBin...
4149        ' -f ' filename '.nc -m ' num2str(Param.(patchname).Nx)...
[292]4150        ' -n ' num2str(Param.(patchname).Ny) ' -ro ' num2str(Param.(patchname).SmoothingParam)...
[286]4151        ' -nopt ' num2str(Param.(patchname).SubdomainSize) ...
4152        '  > ' filename '.' lower(patchname) '.log 2>&1']; % redirect standard output to the log file
4153else
4154    cmd=['"' Param.xml.PatchBin...
4155        '" -f "' filename '.nc" -m ' num2str(Param.(patchname).Nx)...
[292]4156        ' -n ' num2str(Param.(patchname).Ny) ' -ro ' num2str(Param.(patchname).SmoothingParam)...
[286]4157        ' -nopt ' num2str(Param.(patchname).SubdomainSize)...
4158        '  > "' filename '.' lower(patchname) '.log" 2>&1']; % redirect standard output to the log file
4159    cmd=regexprep(cmd,'\\','\\\\');
4160end
[290]4161
4162%------------------------------------------------------------------------
4163% --- CheckCiv2  CheckCiv2  CheckCiv2 CheckCiv2
4164function cmd=cmd_civ2(filename,Param)
4165%------------------------------------------------------------------------
4166%pixels per cm and matrix of the image times, read from the .civ file by uvmat
4167% global civ2Bin sge%name of the executable for checkciv1 calculation
4168filename=regexprep(filename,'.nc','');
4169if isequal(Param.Civ2.Dt,'0')
4170    Param.Civ2.Dt='1' ;%case of 'displacement' mode
4171end
4172Param.Civ2.filename_ima_a=regexprep(Param.Civ2.filename_ima_a,'.png','');
4173Param.Civ2.filename_ima_b=regexprep(Param.Civ2.filename_ima_b,'.png','');% bug : .png appears two times ?
4174[fid,errormsg]=fopen([filename '.civ2.cmx'],'w');
4175if isequal(fid,-1)
4176    msgbox_uvmat('ERROR',errormsg)
4177    cmd='';
4178    return
4179end
4180fprintf(fid,['##############   CMX file' '\n' ]);
4181fprintf(fid,   ['FirstImage ' regexprep(Param.Civ2.filename_ima_a,'\\','\\\\') '\n' ]);% for windows compatibility
4182fprintf(fid,   ['LastImage  ' regexprep(Param.Civ2.filename_ima_b,'\\','\\\\') '\n' ]);% for windows compatibility
4183fprintf(fid,  ['XX' '\n' ]);
4184fprintf(fid, ['Mask ' Param.Civ2.MaskFlag '\n' ]);
4185fprintf(fid, ['MaskName ' regexprep(Param.Civ2.MaskName,'\\','\\\\') '\n' ]);% for windows compatibility
[309]4186fprintf(fid,   ['ImageSize ' num2str(Param.Civ2.ImageInfo.Width) ' ' num2str(Param.Civ2.ImageInfo.Height) '\n' ]); 
4187% fprintf(fid, ['ImageSize ' num2str(Param.Civ2.npx) ' ' num2str(Param.Civ2.npy) '\n' ]);   %VERIFIER CAS GENERAL ?
[290]4188fprintf(fid, ['CorrelationBoxesSize ' num2str(Param.Civ2.Bx) ' ' num2str(Param.Civ2.By) '\n' ]);
4189fprintf(fid, ['SearchBoxeSize ' num2str(Param.Civ2.Bx) ' ' num2str(Param.Civ2.By) '\n']);
4190fprintf(fid, ['RO ' num2str(Param.Civ2.Rho) '\n']);
4191fprintf(fid, ['GridSpacing ' num2str(Param.Civ2.Dx) ' ' num2str(Param.Civ2.Dy) '\n']);
4192fprintf(fid, ['XX 1.0' '\n' ]);
4193fprintf(fid, ['Dt_TO ' num2str(Param.Civ2.Dt) ' ' num2str(Param.Civ2.T0) '\n' ]);
4194fprintf(fid, ['PixCmXY ' num2str(Param.Civ2.pxcmx) ' ' num2str(Param.Civ2.pxcmy) '\n' ]);
4195fprintf(fid, ['XX 1' '\n' ]);
4196fprintf(fid, 'ShiftXY 0 0\n');
4197fprintf(fid, ['Grid ' Param.Civ2.GridFlag '\n' ]);
4198fprintf(fid, ['GridName ' regexprep(Param.Civ2.GridName,'\\','\\\\') '\n']);
4199fprintf(fid, ['XX 85' '\n' ]);
4200fprintf(fid, ['XX 1.0' '\n' ]);
4201fprintf(fid, ['XX 1.0' '\n' ]);
4202fprintf(fid, ['Hart 1' '\n' ]);
4203fprintf(fid, ['DecimalShift ' num2str(Param.Civ2.CheckDecimal) '\n']);
4204fprintf(fid, ['Deformation ' num2str(Param.Civ2.CheckDeformation) '\n']);
4205fprintf(fid,  ['CorrelationMin 0' '\n' ]);
4206fprintf(fid,   ['IntensityMin 0' '\n' ]);
[309]4207
4208if ~isfield(Param.Civ2,'MinIma')% Image threshold not activated
4209    fprintf(fid,  ['SeuilImage n' '\n' ]);
4210    fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);%not used in principle
4211else% Image threshold  activated
4212    if isempty(Param.Civ2.MaxIma)||isnan(Param.Civ2.MaxIma)
4213        Param.Civ2.MaxIma=2^Param.Civ2.ImageInfo.BitDepth;%take the max image value as upper bound by default
4214    end
4215    fprintf(fid,  ['SeuilImage y' '\n' ]);
4216    fprintf(fid,   ['SeuilImageValues ' num2str(Param.Civ2.MinIma) ' ' num2str(Param.Civ2.MaxIma) '\n' ]);
4217end
[290]4218fprintf(fid,   ['ImageToUse ' Param.Civ2.term_a ' ' Param.Civ2.term_b '\n' ]); % VERIFIER ?
4219fprintf(fid, ['ImageUsedBefore ' regexprep(Param.Civ2.filename_nc1,'\\','\\\\') '\n']);
4220fclose(fid);
4221
4222if(isunix)
4223    cmd=['cp -f ' filename '.civ2.cmx ' filename '.cmx\n'...
4224        Param.xml.Civ2Bin ' -f ' filename  '.cmx >' filename '.civ2.log \n '... % redirect standard output to the log file, the result file is named [filename '.nc'] by CIVx
4225        'rm ' filename '.cmx \n'];%rename .cmx as .checkciv2.cmx, the result file is named [filename '.nc'] by CIVx
4226else
4227    filename=regexprep(filename,'\\','\\\\');
4228    cmd=['copy /Y "' filename '.civ2.cmx" "' filename '.cmx" \n'...
4229        '"' regexprep(Param.xml.Civ2Bin,'\\','\\\\') '" -f "' filename  '.cmx" >"' filename '.civ2.log" \n'...
4230        'del "' filename '.cmx" \n'];
4231end
[309]4232
4233%------------------------------------------------------------------------
4234% --- Executes on button press in CheckThreshold.
4235function CheckThreshold_Callback(hObject, eventdata, handles)
4236%------------------------------------------------------------------------
4237huipanel=get(hObject,'parent');
4238obj(1)=findobj(huipanel,'Tag','num_MinIma');
4239obj(2)=findobj(huipanel,'Tag','num_MaxIma');
4240obj(3)=findobj(huipanel,'Tag','title_Threshold');
4241if get(hObject,'Value')
4242    set(obj,'Visible','on')
4243else
4244    set(obj,'Visible','off')
4245end
4246
4247%------------------------------------------------------------------------
4248% --- CheckCiv1  Unified: TO ABADON
4249function xml_civ1_parameters=CIV1_CMD_Unified(filename,namelog,par)
4250%------------------------------------------------------------------------
4251%pixels per cm and matrix of the image times, read from the .civ file by uvmat
4252%global CivBin%name of the executable for checkciv1 calculation
4253
4254civ1.image1=par.filename_ima_a;
4255civ1.image2=par.filename_ima_b;
4256civ1.imageSize_X=par.npx;
4257civ1.imageSize_Y=par.npy;
4258civ1.outputFileName=[filename '.nc'];
4259civ1.correlationBoxesSize_X=par.ibx;
4260civ1.correlationBoxesSize_Y=par.iby;
4261civ1.searchBoxesSize_X=par.isx;
4262civ1.searchBoxesSize_Y=par.isy;
4263civ1.globalShift_X=par.shiftx;
4264civ1.globalShift_Y=par.shifty;
4265civ1.ro=par.rho;
4266civ1.hart='y';
4267if isequal(par.gridflag,'y')
4268    civ1.grid=par.gridname;
4269else
4270    civ1.grid='n';
4271    civ1.gridSpacing_X=par.dx;
4272    civ1.gridSpacing_Y=par.dy;
4273end
4274if isequal(par.maskflag,'y')
4275    civ1.mask=par.maskname;
4276end
4277civ1.dt=par.Dt;
4278civ1.unit='pixel';
4279civ1.absolut_time_T0=par.T0;
4280civ1.pixcmx=par.pxcmx;
4281civ1.pixcmy=par.pxcmy;
4282civ1.convectFlow='n';
4283
4284xml_civ1_parameters=civ1;
4285
4286%------------------------------------------------------------------------
4287% --- CheckCiv2  Unified: TO ABADON
4288function civ2=CIV2_CMD_Unified(filename,namelog,par)
4289%------------------------------------------------------------------------
4290%pixels per cm and matrix of the image times, read from the .civ file by uvmat
4291%global CivBin%name of the executable for checkciv1 calculation
4292
4293filename=regexprep(filename,'.nc','');
4294
4295civ2.image1=par.filename_ima_a;
4296civ2.image2=par.filename_ima_b;
4297civ2.imageSize_X=par.npx;
4298civ2.imageSize_Y=par.npy;
4299civ2.inputFileName=[par.filename_nc1 '.nc'];
4300civ2.outputFileName=[filename '.nc'];
4301civ2.correlationBoxesSize_X=par.ibx;
4302civ2.correlationBoxesSize_Y=par.iby;
4303civ2.ro=par.rho;
4304%checkciv2.decimalShift=par.CheckDecimal;
4305%checkciv2.CheckDeformation=par.CheckDeformation;
4306if isequal(par.decimal,'1')
4307    civ2.decimalShift='y';
4308else
4309    civ2.decimalShift='n';
4310end
4311if isequal(par.deformation,'1')
4312    civ2.deformation='y';
4313else
4314    civ2.deformation='n';
4315end
4316if isequal(par.gridflag,'y')
4317    civ2.grid=par.gridname;
4318else
4319    civ2.grid='n';
4320    civ2.gridSpacing_X=par.dx;
4321    civ2.gridSpacing_Y=par.dy;
4322end
4323civ2.gridSpacing_X='10';
4324civ2.gridSpacing_Y='10';%NOTE: faut mettre gridSpacing pourque ca tourne, meme si c'est la grille qui est utilisee
4325if isequal(par.maskflag,'y')
4326    civ2.mask=par.maskname;
4327else
4328    civ2.mask='n';
4329end
4330civ2.dt=par.Dt;
4331civ2.unit='pixel';
4332civ2.absolut_time_T0=par.T0;
4333civ2.pixcmx=par.pxcmx;
4334civ2.pixcmy=par.pxcmy;
4335civ2.convectFlow='n';
4336civ2.pixcmx=par.pxcmx;
4337civ2.pixcmy=par.pxcmy;
4338civ2.convectFlow='n';
Note: See TracBrowser for help on using the repository browser.