source: trunk/src/civ.m @ 332

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

NomType? changed from _i1-i2 ... to _1-2 ... (bugs to be expected!)
bug corrected in geometry_calib
series changed by introducing a from FileIndices?, introduction of find_file_series to detect the file series corresponding to an input file

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