Changeset 67 for trunk/src/civ.m


Ignore:
Timestamp:
Mar 25, 2010, 6:48:48 PM (14 years ago)
Author:
sommeria
Message:

civ: RUN civ lounched out of the Matlab work space. RUN and BATCH now runned by a unique sub-function lounch.m.
FiLE PARAM.xml modified to provide different paths for Batch and Run !!!!!
RUN_FIX: minor error message modif
geometry_calib: calib point editing by the mouse
improvement of the interactions between the different GUIs. Close function...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/civ.m

    r66 r67  
    5151% handles    structure with handles and user data (see GUIDATA)
    5252% varargin   command line arguments to civ (see VARARGIN)
    53 global test_batch patch_new_exe%=1 if patch processing available
     53global test_batch patch_newBin%=1 if patch processing available
    5454%filebase: root name
    5555%nom_type: nomencalture used ('png_old','_i_j'...)
     
    132132       msgbox_uvmat('ERROR',errormsg);
    133133end
    134 patch_new_exe='';
     134patch_newBin='';
    135135% todo_patch='';
    136136sge=0;
    137137
    138 if isfield(sparam,'PatchNew_exe')
    139     patch_new_exe=sparam.PatchNew_exe;
     138if isfield(sparam,'PatchNewBin')
     139    patch_newBin=sparam.PatchNewBin;
    140140end
    141141
     
    15571557%------------------------------------------------------------------------
    15581558% --- Executes on button press in RUN.
     1559
     1560
     1561
     1562% compare=get(handles.compare,'Value');%test for usual PIV (compare=1) or displacement (=2) or stereo PIV (=3)
     1563% %check the list of operations:
     1564% operations={'CIV1','FIX1','PATCH1','CIV2','FIX2','PATCH2'};
     1565% run_flag=1;
     1566% box_test(1)=get(handles.CIV1,'Value');
     1567% box_test(2)=get(handles.FIX1,'Value');
     1568% box_test(3)=get(handles.PATCH1,'Value');
     1569% box_test(4)=get(handles.CIV2,'Value');
     1570% box_test(5)=get(handles.FIX2,'Value');
     1571% box_test(6)=get(handles.PATCH2,'Value');
     1572% index=find(box_test==1);
     1573% if isempty(index)
     1574%     msgbox_uvmat('ERROR','no selected operation')
     1575%     return
     1576% end
     1577% index_first=min(index);
     1578% index_last=max(index);
     1579% box_used=box_test([index_first : index_last]);
     1580% [box_missing,ind_missing]=min(box_used);
     1581% if isequal(box_missing,0)
     1582%     msgbox_uvmat('ERROR',['missing' cell2mat(operations(ind_missing))]);
     1583%     return
     1584% end
     1585%
     1586% %root name
     1587% filebase=get(handles.displ_filebase,'String');
     1588% if isempty(filebase)||isequal(filebase,'')
     1589%     msgbox_uvmat('ERROR','no input files')
     1590%     return
     1591% end
     1592% %check mask if selecetd
     1593% if isequal(get(handles.get_mask_civ1,'Value'),1)
     1594%     maskname=get(handles.mask_civ1,'String');
     1595%     if ~exist(maskname,'file')
     1596%         get_mask_civ1_Callback(hObject, eventdata, handles);
     1597%     end
     1598% end
     1599% if isequal(get(handles.get_mask_fix1,'Value'),1)
     1600%     maskname=get(handles.mask_fix1,'String');
     1601%     if ~exist(maskname,'file')
     1602%      get_mask_fix1_Callback(hObject, eventdata, handles);
     1603%     end
     1604% end
     1605% if isequal(get(handles.get_mask_civ2,'Value'),1)
     1606%     maskname=get(handles.mask_civ2,'String');
     1607%     if ~exist(maskname,'file')
     1608%      get_mask_civ2_Callback(hObject, eventdata, handles);
     1609%     end
     1610% end
     1611% if isequal(get(handles.get_mask_fix2,'Value'),1)
     1612%     maskname=get(handles.mask_fix2,'String');
     1613%     if ~exist(maskname,'file')
     1614%      get_mask_fix2_Callback(hObject, eventdata, handles);
     1615%     end
     1616% end
     1617%
     1618% %read names of the .exe file
     1619% if box_test(1)==1 || box_test(3)==1 || box_test(4)==1 || box_test(6)==1
     1620%     path_uvmat=which('uvmat');% check the path detected for source file uvmat
     1621%     path_UVMAT=fileparts(path_uvmat); %path to UVMAT
     1622%     %fid = fopen(fullfile(path_UVMAT,'PARAM_LINUX.txt'),'r');%open the file with civ binary names
     1623%     xmlfile=fullfile(path_UVMAT,'PARAM.xml');
     1624%     if exist(xmlfile,'file')
     1625%         t=xmltree(xmlfile);
     1626%         sparam=convert(t);
     1627%     end
     1628%     if isfield(sparam,'Civ1Bin')
     1629%         civ1Bin=sparam.Civ1Bin;
     1630%         if ~exist(civ1Bin,'file')
     1631%             civ1Bin=fullfile(path_UVMAT,civ1Bin);
     1632%         end
     1633%     end
     1634%     if isfield(sparam,'Civ2Bin')
     1635%         civ2Bin=sparam.Civ2Bin;
     1636%         if ~exist(civ2_exe,'file')%the binary is defined in /bin, default setting
     1637%             civ2_exe=fullfile(path_UVMAT,civ2_exe);
     1638%         end
     1639%     end
     1640%     if isfield(sparam,'Patch_exe')
     1641%         patch_exe=sparam.Patch_exe;
     1642%         if ~exist(patch_exe,'file')%the binary is defined in /bin, default setting
     1643%             patch_exe=fullfile(path_UVMAT,patch_exe);
     1644%         end
     1645%     end
     1646%     if isfield(sparam,'Stinterp_exe')
     1647%         stinterp_exe=sparam.Stinterp_exe;
     1648%     end
     1649%     if isfield(sparam,'SGE')
     1650%         sge=str2double(sparam.SGE);
     1651%     end
     1652%     if ~isunix % for windows system, check whether the Matlab working dir is a UBC name
     1653%         dircur=pwd;
     1654%         if ~isequal(dircur([2 3]),':\')
     1655%             msgbox_uvmat('ERROR','move to a Matlab current working directory with a Windows name, e.g. m:/...')
     1656%             return;
     1657%         end
     1658%     end
     1659% end
     1660%
     1661% %initialize the waitbars
     1662% set(handles.waitbar_1,'Position',[0.946 0.877 0.03 0.001])
     1663% set(handles.waitbar_patch1,'Position',[0.946 0.626 0.03 0.001])
     1664% set(handles.waitbar_civ2,'Position',[0.946 0.406 0.03 0.001])
     1665% set(handles.waitbar_patch2,'Position',[0.946 0.187 0.03 0.001])
     1666% set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
     1667% set(handles.RUN, 'Enable','Off')
     1668% drawnow
     1669%
     1670% % get the list of file names and check the files
     1671% display('checking the files...')
     1672% [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]=...
     1673%        set_civ_filenames(handles,compare,box_test);
     1674% nbfield=numel(num1_civ1);
     1675% nbslice=size(num_a_civ1);
     1676%
     1677% if isempty(filecell)
     1678%    set(handles.RUN, 'Enable','On')
     1679%     set(handles.RUN,'BackgroundColor',[1 0 0])
     1680%     set(handles.BATCH, 'Enable','On')
     1681%     set(handles.BATCH,'BackgroundColor',[1 0 0])
     1682%    return
     1683% end
     1684% display('files OK, processing...')   
     1685% nbfield=size(num1_civ1,2);
     1686% nbslice=size(num1_civ1,1);
     1687%
     1688% %RUN CIV1
     1689% if box_test(1)==1
     1690%       RUN_CIV1(handles,filecell.ima1.civ1,filecell.ima2.civ1,filecell.nc.civ1,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,nom_type_nc)
     1691%       if compare==3
     1692%             RUN_CIV1(handles,filecell.imaA1.civ1,filecell.imaA2.civ1,filecell.ncA.civ1,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,nom_type_nc)
     1693%      end
     1694% end
     1695%
     1696% %RUN FIX1
     1697% if box_test(2)==1
     1698%     filebase=get(handles.displ_filebase,'String');
     1699%     %names of the civ1 fields
     1700%     field1.vel_type='civ1';
     1701%     field1.nb='nb_vectors';
     1702% %     field1.X='vec_X';
     1703% %     field1.Y='vec_Y';
     1704% %     field1.U='vec_U';
     1705% %     field1.V='vec_V';
     1706%     field1.fixflag='vec_FixFlag';
     1707%     flagindex(1)=get(handles.vec_Fmin2, 'Value');
     1708%     flagindex(2)=get(handles.vec_F3, 'Value');
     1709%     flagindex(3)=get(handles.vec_F2, 'Value');
     1710%     thresh_vecC=str2double(get(handles.thresh_vecC,'String'));%threshold on image correlation vec_C
     1711%     thresh_vel=str2double(get(handles.thresh_vel,'String'));%threshold on velocity modulus
     1712%     inf_sup=get(handles.inf_sup1,'Value');
     1713%     menu=get(handles.field_ref1,'String');
     1714%     index=get(handles.field_ref1,'Value');
     1715%     if isempty(menu)
     1716%         fieldchoice='';
     1717%     else
     1718%         fieldchoice=menu{index};
     1719%     end   
     1720%     h = waitbar(0,'removing velocity vectors, fix1');% display a wait bar
     1721%     test_mask=get(handles.get_mask_fix1,'Value');   
     1722%     if test_mask
     1723%         maskdispl=get(handles.mask_fix1,'String');
     1724%         if exist(maskdispl,'file')
     1725%             test_mask=2;
     1726%             maskname=maskdispl;
     1727%         else
     1728%             maskbase=[get(handles.displ_filebase,'String') '_' maskdispl]; % mask root name
     1729%         end
     1730%     end
     1731%     for ifile=1:nbfield
     1732%         waitbar(ifile/nbfield); %update the waitbar
     1733%         for j=1:nbslice
     1734%             if test_mask==0
     1735%                 maskname='noFile use default';
     1736%                 maskflag=0;
     1737%             elseif test_mask==1
     1738%                 nbslice_mask=str2double(maskdispl(1:end-4)); %
     1739%                 num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
     1740%                 maskname=name_generator(maskbase,num1_mask,1,'.png','_i');% mask corresponding to the first image of the pair
     1741%                 maskflag= exist(maskname,'file')==2;
     1742%                 if ~maskflag;
     1743%                     maskname='noFile use default';
     1744%                 end             
     1745%             end
     1746%             if ~isempty(file_ref_fix1)
     1747%                 file_ref=file_ref_fix1{ifile,j};
     1748%             else
     1749%                 file_ref='';
     1750%             end
     1751%             error=RUN_FIX(filecell.nc.civ1{ifile,j},field1,flagindex,1,thresh_vecC,maskflag,maskname,...
     1752%                                     thresh_vel,inf_sup,file_ref,fieldchoice);
     1753%
     1754%             if compare==3 &&(isequal(mode,'pair j1-j2') || isequal(mode,'series(Dj)') || isequal(mode,'series(Di)'))
     1755%                  if test_mask==0 
     1756%                       maskname='noFile use default';
     1757%                       maskflag=0;
     1758%                  else
     1759%                      maskbase=[get(handles.displ_filebase2,'String') '_' maskdispl]; % mask root name
     1760%                      nbslice_mask=str2num(maskdispl(1:end-4)); %
     1761%                      num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;               
     1762%                      maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
     1763%                      maskflag= exist(maskname,'file')==2;
     1764%                      if ~maskflag;
     1765%                         maskname='noFile use default';
     1766%                      end
     1767%                  end
     1768%                  error=RUN_FIX(filecell.ncA.civ1{ifile,j},field1,flagindex,1,thresh_vecC,maskflag,maskname,...
     1769%                                     thresh_vel,inf_sup,file_ref,fieldchoice);
     1770%                  if ~isempty(error)
     1771%                     msgbox_uvmat('ERROR',error)
     1772%                     return
     1773%                  end             
     1774%             end
     1775%         end
     1776%     end
     1777%     close(h)
     1778% end
     1779%
     1780% % RUN PATCH1
     1781% if box_test(3)==1
     1782%     rho_patch1=str2num(get(handles.rho_patch1,'String'));
     1783%     if isempty(rho_patch1)
     1784%         rho_patch1='1000';
     1785%         set(handles.rho_patch1,'String','1')
     1786%     else
     1787%         rho_patch1=num2str(1000*rho_patch1);
     1788%     end
     1789%     nx_patch1=get(handles.nx_patch1,'String');
     1790%     if isequal(str2num(nx_patch1),[])
     1791%          nx_patch1='50' ;%default
     1792%          set(handles.nx_patch1,'String','50');
     1793%     end
     1794%     ny_patch1=get(handles.ny_patch1,'String');
     1795%     if isequal(str2num(ny_patch1),[])
     1796%          ny_patch1='50' ;%default
     1797%          set(handles.ny_patch1,'String','50');
     1798%     end
     1799%     subdomain_patch1=get(handles.subdomain_patch1,'String');
     1800%     thresh_patch1=get(handles.thresh_patch1,'String');
     1801%     test_interp=get(handles.test_interp,'Value');
     1802%     icount=0;
     1803%     for ifile=1:nbfield
     1804%         for j=1:nbslice
     1805%             icount=icount+1;
     1806%             barlength=0.188*icount/(nbfield*nbslice);
     1807%             set(handles.waitbar_patch1,'Position',[0.946 0.627-barlength 0.03 barlength])
     1808%             drawnow
     1809%             if  isequal(get(handles.test_stereo1,'Value'),0)
     1810%                 cmd=RUN_PATCH(filecell.nc.civ1{ifile,j},nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,test_interp);
     1811%                 s=-1;
     1812%                 if sge
     1813%                     [s,w]=unix(['qrsh -q -fast.q ' cmd]);
     1814%                 end
     1815%                 if s~=0
     1816%                     display(['!' cmd])
     1817%                     eval(['!' cmd]);                 
     1818%                 end
     1819%
     1820%                 %stereo case:
     1821%             elseif  isequal(get(handles.test_stereo1,'Value'),1)
     1822%                 if exist('stinterp_exe','var')%Prog Gauthier
     1823%                     cmd=RUN_STINTERP(stinterp_exe,filecell.ncA.civ1{ifile,j},filecell.nc.civ1{ifile,j},filecell.st{ifile,j},...
     1824%                           nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,[filebase_A '.xml'],[filebase_B '.xml']);
     1825%                     display(['!' cmd])
     1826%                     eval(['!' cmd]);       
     1827%                 else
     1828%                     RUN_STLIN(filecell.ncA.civ1{ifile,j},filecell.nc.civ1{ifile,j},'civ1',filecell.st{ifile,j},...
     1829%                         str2num(nx_patch1),str2num(ny_patch1),str2num(thresh_patch1),[filebase_A '.xml'],[filebase_B '.xml']);
     1830%                 end
     1831%             end
     1832%             if compare==3 && isequal(get(handles.test_stereo1,'Value'),0)
     1833%                 cmd=RUN_PATCH(filecell.ncA.civ1{ifile,j},nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,test_interp);
     1834%                 s=-1;
     1835%                 if sge
     1836%                     [s,w]=unix(['qrsh -q -fast.q ' cmd]);
     1837%                 end
     1838%                 if s~=0
     1839%                    display(['!' cmd])
     1840%                    eval(['!' cmd]);
     1841%                 end
     1842%             end
     1843%         end
     1844%     end
     1845% end
     1846%
     1847% % CIV2
     1848% if box_test(4)==1
     1849%     RUN_CIV2(handles,filecell.ima1.civ2,filecell.ima2.civ2,filecell.nc.civ1,filecell.nc.civ2,num1_civ2,num2_civ2,...
     1850%         num_a_civ2,num_b_civ2,nom_type_nc)
     1851% end
     1852%
     1853% % FIX2
     1854% if box_test(5)==1
     1855%     %names of the civ2 fields
     1856%     field2.vel_type='civ2';
     1857%     field2.nb='nb_vectors2';
     1858%     field2.X='vec2_X';
     1859%     field2.Y='vec2_Y';
     1860%     field2.U='vec2_U';
     1861%     field2.V='vec2_V';
     1862%     field2.fixflag='vec2_FixFlag';
     1863%     flagindex(1)=get(handles.vec_Fmin2_2, 'Value');
     1864%     flagindex(2)=get(handles.vec_F3_2, 'Value');
     1865%     flagindex(3)=get(handles.vec_F4, 'Value');
     1866%     thresh_vec2C=str2num(get(handles.thresh_vec2C,'String'));%threshold on image correlation vec_C
     1867%     thresh_vel2=str2num(get(handles.thresh_vel2,'String'));%threshold on velocity modulus
     1868%     inf_sup=get(handles.inf_sup2,'Value');
     1869%     menu=get(handles.field_ref2,'String');
     1870%     index=get(handles.field_ref2,'Value');
     1871%     if isempty(menu)
     1872%         fieldchoice='';
     1873%     else
     1874%         fieldchoice=menu{index};
     1875%     end   
     1876%     h = waitbar(0,['removing velocity vectors, fix2']);% display a wait bar
     1877%     test_mask=get(handles.get_mask_fix2,'Value');
     1878%     if test_mask
     1879%         maskdispl=get(handles.mask_fix2,'String');
     1880%         if exist(maskdispl,'file')
     1881%             test_mask=2;
     1882%             maskname=maskdispl;
     1883%         else
     1884%             maskbase=[get(handles.displ_filebase,'String') '_' maskdispl]; % mask root name
     1885%         end
     1886%     end
     1887%     for ifile=1:nbfield
     1888%         waitbar(ifile/nbfield); %update the waitbar
     1889%         for j=1:nbslice       
     1890%            if test_mask==0
     1891%                 maskname='noFile use default';
     1892%                 maskflag=0;
     1893%            elseif test_mask==1
     1894%                 nbslice_mask=str2num(maskdispl(1:end-4)); %
     1895%                 num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
     1896%                 maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
     1897%                 maskflag= exist(maskname,'file')==2;
     1898%                 if ~maskflag;
     1899%                       maskname='noFile use default';
     1900%                 end
     1901%             end
     1902%             if ~isempty(file_ref_fix2)
     1903%                 file_ref=file_ref_fix2{ifile,j};
     1904%             else
     1905%                 file_ref='';
     1906%             end
     1907%             error=RUN_FIX(filecell.nc.civ2{ifile,j},field2,flagindex,2,thresh_vec2C,maskflag,maskname,...
     1908%                                     thresh_vel2,inf_sup,file_ref,fieldchoice);
     1909%             if ~isempty(error)
     1910%                 msgbox_uvmat('ERROR',error)
     1911%                 return
     1912%             end 
     1913%             if compare==3
     1914%                  if test_mask==0 
     1915%                       maskname='noFile use default';
     1916%                       maskflag=0;
     1917%                  else
     1918%                       maskbase=[get(handles.displ_filebase2,'String') '_' maskdispl]; % mask root name
     1919%                       nbslice_mask=str2num(maskdispl(1:end-4)); %
     1920%                       num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
     1921%                       maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
     1922%                       maskflag= exist(maskname,'file')==2;
     1923%                       if ~maskflag;
     1924%                          maskname='noFile use default';
     1925%                       end
     1926%                  end
     1927%                  error=RUN_FIX(filecell.ncA.civ2{ifile,j},field2,flagindex,1,thresh_vec2C,maskflag,maskname,...
     1928%                                     thresh_vel2,inf_sup,file_ref,fieldchoice);
     1929%                  if ~isempty(error)
     1930%                     msgbox_uvmat('ERROR',error)
     1931%                     return
     1932%                  end 
     1933%             end
     1934%         end
     1935%     end
     1936%     close(h)
     1937% end
     1938%
     1939% %PATCH 2
     1940% if box_test(6)==1
     1941%     rho_patch2=str2num(get(handles.rho_patch2,'String'));
     1942%     if isempty(rho_patch2)
     1943%         rho_patch2='1000';
     1944%         set(handles.rho_patch2,'String','1')
     1945%     else
     1946%         rho_patch2=num2str(1000*rho_patch2);
     1947%     end
     1948%     nx_patch2=get(handles.nx_patch2,'String');
     1949%     ny_patch2=get(handles.ny_patch2,'String');
     1950%     thresh_patch2=get(handles.thresh_patch2,'String');
     1951%     if isequal(str2num(nx_patch2),[])
     1952%          nx_patch2='50' ;%default
     1953%          set(handles.nx_patch2,'String','50');
     1954%     end
     1955%     if isequal(str2num(ny_patch2),[])
     1956%          ny_patch2='50' ;%default
     1957%          set(handles.ny_patch2,'String','50');
     1958%     end
     1959%     subdomain_patch2=get(handles.subdomain_patch2,'String');
     1960%     icount=0;
     1961%     for ifile=1:nbfield
     1962%         for j=1:nbslice
     1963%             icount=icount+1;
     1964%             barlength=0.188*icount/(nbfield*nbslice);
     1965%             set(handles.waitbar_patch2,'Position',[0.946 0.188-barlength 0.03 barlength])
     1966%             drawnow
     1967%             if compare~=3 | isequal(get(handles.test_stereo2,'Value'),0)
     1968%                 cmd=RUN_PATCH(filecell.nc.civ2{ifile,j},nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,1,0);
     1969%                 s=-1;
     1970%                 if sge
     1971%                     [s,w]=unix(['qrsh -q -fast.q ' cmd]);
     1972%                 end
     1973%                 if s~=0
     1974%                     display(['!' cmd])
     1975%                     eval(['!' cmd]);
     1976%                 end
     1977%             elseif compare==3 &&  isequal(get(handles.test_stereo2,'Value'),1)
     1978%                if exist('stinterp_exe','var')%Prog Gauthier 
     1979%                    cmd=RUN_STINTERP(stinterp_exe,filecell.ncA.civ2{ifile,j},filecell.nc.civ2{ifile,j},filecell.st{ifile,j},...
     1980%                    nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,thresh_patch2,[filebase_A '.xml'],[filebase_B '.xml']);
     1981%                    display(['!' cmd])
     1982%                    eval(['!' cmd])
     1983%                else
     1984%                    RUN_STLIN(filecell.ncA.civ2{ifile,j},filecell.nc.civ2{ifile,j},'civ2',filecell.st{ifile,j},...
     1985%                    str2num(nx_patch2),str2num(ny_patch2),str2num(thresh_patch2),[filebase_A '.xml'],[filebase_B '.xml'])
     1986%                end
     1987%             end   
     1988%             if compare==3 && isequal(get(handles.test_stereo2,'Value'),0)
     1989%                 cmd=RUN_PATCH(filecell.ncA.civ2{ifile,j},nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,1,0);
     1990%                 s=-1;
     1991%                 if sge
     1992%                     [s,w]=unix(['qrsh -q -fast.q ' cmd]);
     1993%                 end
     1994%                 if s~=0
     1995%                     display(['!' cmd])
     1996%                     eval(['!' cmd]);
     1997%                 end
     1998%             end
     1999%         end
     2000%     end
     2001% end
     2002%
     2003% set(handles.RUN, 'Enable','On')
     2004% set(handles.RUN,'BackgroundColor',[1 0 0])
     2005%
     2006% %save the current interface setting as figure namefig, append .0 to the name if it already exists
     2007% if isfield(filecell,'st')
     2008%     fileresu=filecell.st{1,1};
     2009% elseif isfield(filecell,'nc')
     2010%     if isfield(filecell.nc,'civ2')
     2011%         fileresu=filecell.nc.civ2{1,1};
     2012%     else
     2013%         fileresu=filecell.nc.civ1{1,1};
     2014%     end
     2015% end
     2016% [RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileresu);
     2017% namedoc=fullfile(RootPath,subdir,RootFile);
     2018% detect=1;
     2019% while detect==1
     2020%     namefigfull=[namedoc '.fig'];
     2021%     hh=dir(namefigfull);
     2022%     if ~isempty(hh)
     2023%         detect=1;
     2024%         namedoc=[namedoc '.0'];
     2025%     else
     2026%         detect=0;
     2027%     end
     2028% end
     2029% saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
     2030
    15592031function RUN_Callback(hObject, eventdata, handles)
    15602032%------------------------------------------------------------------------
    1561 global civ1_exe civ2_exe patch_exe patch_new_exe sge
     2033% global civ1_exe civ2_exe patch_exe patch_new_exe sge
     2034
     2035batch=0;
     2036launch_jobs(hObject, eventdata, handles,batch);
     2037
     2038
     2039%------------------------------------------------------------------------
     2040% --- Executes on button press in BATCH: remote processing
     2041function BATCH_Callback(hObject, eventdata, handles)
     2042%------------------------------------------------------------------------
     2043%global civ1_exe civ2_exe patch_exe patch_new_exe fix_exe todo_path sge Civ_exe % probabely to remove
     2044batch=1;
     2045launch_jobs(hObject, eventdata, handles, batch)
     2046
     2047%------------------------------------------------------------------------
     2048% --- Executes on button press in BATCH: remote processing
     2049function launch_jobs(hObject, eventdata, handles, batch)
     2050%-----------------------------------------------------------------------
     2051% global civ2Bin patchBin patch_newBin fixBin CivBin % probabely to remove
    15622052
    15632053compare=get(handles.compare,'Value');%test for usual PIV (compare=1) or displacement (=2) or stereo PIV (=3)
     2054
    15642055%check the list of operations:
    15652056operations={'CIV1','FIX1','PATCH1','CIV2','FIX2','PATCH2'};
     
    15912082    return
    15922083end
    1593 %check mask if selecetd
    1594 if isequal(get(handles.get_mask_civ1,'Value'),1)
    1595     maskname=get(handles.mask_civ1,'String');
    1596     if ~exist(maskname,'file')
    1597         get_mask_civ1_Callback(hObject, eventdata, handles);
    1598     end
    1599 end
    1600 if isequal(get(handles.get_mask_fix1,'Value'),1)
    1601     maskname=get(handles.mask_fix1,'String');
    1602     if ~exist(maskname,'file')
    1603      get_mask_fix1_Callback(hObject, eventdata, handles);
    1604     end
    1605 end
    1606 if isequal(get(handles.get_mask_civ2,'Value'),1)
    1607     maskname=get(handles.mask_civ2,'String');
    1608     if ~exist(maskname,'file')
    1609      get_mask_civ2_Callback(hObject, eventdata, handles);
    1610     end
    1611 end
    1612 if isequal(get(handles.get_mask_fix2,'Value'),1)
    1613     maskname=get(handles.mask_fix2,'String');
    1614     if ~exist(maskname,'file')
    1615      get_mask_fix2_Callback(hObject, eventdata, handles);
    1616     end
    1617 end
    1618 
    1619 %read names of the .exe file
    1620 if box_test(1)==1 || box_test(3)==1 || box_test(4)==1 || box_test(6)==1
    1621     path_uvmat=which('uvmat');% check the path detected for source file uvmat
    1622     path_UVMAT=fileparts(path_uvmat); %path to UVMAT
    1623     %fid = fopen(fullfile(path_UVMAT,'PARAM_LINUX.txt'),'r');%open the file with civ binary names
    1624     xmlfile=fullfile(path_UVMAT,'PARAM.xml');
    1625     if exist(xmlfile,'file')
    1626         t=xmltree(xmlfile);
    1627         sparam=convert(t);
    1628     end
    1629     if isfield(sparam,'Civ1_exe')
    1630         civ1_exe=sparam.Civ1_exe;
    1631         if ~exist(civ1_exe,'file')
    1632             civ1_exe=fullfile(path_UVMAT,civ1_exe);
    1633         end
    1634     end
    1635     if isfield(sparam,'Civ2_exe')
    1636         civ2_exe=sparam.Civ2_exe;
    1637         if ~exist(civ2_exe,'file')%the binary is defined in /bin, default setting
    1638             civ2_exe=fullfile(path_UVMAT,civ2_exe);
    1639         end
    1640     end
    1641     if isfield(sparam,'Patch_exe')
    1642         patch_exe=sparam.Patch_exe;
    1643         if ~exist(patch_exe,'file')%the binary is defined in /bin, default setting
    1644             patch_exe=fullfile(path_UVMAT,patch_exe);
    1645         end
    1646     end
    1647     if isfield(sparam,'Stinterp_exe')
    1648         stinterp_exe=sparam.Stinterp_exe;
    1649     end
    1650     if isfield(sparam,'SGE')
    1651         sge=str2double(sparam.SGE);
    1652     end
    1653     if ~isunix % for windows system, check whether the Matlab working dir is a UBC name
    1654         dircur=pwd;
    1655         if ~isequal(dircur([2 3]),':\')
    1656             msgbox_uvmat('ERROR','move to a Matlab current working directory with a Windows name, e.g. m:/...')
    1657             return;
    1658         end
    1659     end
    1660 end
    1661 
    1662 %initialize the waitbars
    1663 set(handles.waitbar_1,'Position',[0.946 0.877 0.03 0.001])
    1664 set(handles.waitbar_patch1,'Position',[0.946 0.626 0.03 0.001])
    1665 set(handles.waitbar_civ2,'Position',[0.946 0.406 0.03 0.001])
    1666 set(handles.waitbar_patch2,'Position',[0.946 0.187 0.03 0.001])
    1667 set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
    1668 set(handles.RUN, 'Enable','Off')
    1669 drawnow
    1670 
    1671 % get the list of file names and check the files
    1672 display('checking the files...')
    1673 [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]=...
    1674        set_civ_filenames(handles,compare,box_test);
    1675 nbfield=numel(num1_civ1);
    1676 nbslice=size(num_a_civ1);
    1677 
    1678 if isempty(filecell)
    1679    set(handles.RUN, 'Enable','On')
    1680     set(handles.RUN,'BackgroundColor',[1 0 0])
    1681     set(handles.BATCH, 'Enable','On')
    1682     set(handles.BATCH,'BackgroundColor',[1 0 0])
    1683    return
    1684 end
    1685 display('files OK, processing...')   
    1686 nbfield=size(num1_civ1,2);
    1687 nbslice=size(num1_civ1,1);
    1688 
    1689 %RUN CIV1
    1690 if box_test(1)==1
    1691       RUN_CIV1(handles,filecell.ima1.civ1,filecell.ima2.civ1,filecell.nc.civ1,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,nom_type_nc)
    1692       if compare==3
    1693             RUN_CIV1(handles,filecell.imaA1.civ1,filecell.imaA2.civ1,filecell.ncA.civ1,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,nom_type_nc)
    1694      end
    1695 end
    1696 
    1697 %RUN FIX1
    1698 if box_test(2)==1
    1699     filebase=get(handles.displ_filebase,'String');
    1700     %names of the civ1 fields
    1701     field1.vel_type='civ1';
    1702     field1.nb='nb_vectors';
    1703 %     field1.X='vec_X';
    1704 %     field1.Y='vec_Y';
    1705 %     field1.U='vec_U';
    1706 %     field1.V='vec_V';
    1707     field1.fixflag='vec_FixFlag';
    1708     flagindex(1)=get(handles.vec_Fmin2, 'Value');
    1709     flagindex(2)=get(handles.vec_F3, 'Value');
    1710     flagindex(3)=get(handles.vec_F2, 'Value');
    1711     thresh_vecC=str2double(get(handles.thresh_vecC,'String'));%threshold on image correlation vec_C
    1712     thresh_vel=str2double(get(handles.thresh_vel,'String'));%threshold on velocity modulus
    1713     inf_sup=get(handles.inf_sup1,'Value');
    1714     menu=get(handles.field_ref1,'String');
    1715     index=get(handles.field_ref1,'Value');
    1716     if isempty(menu)
    1717         fieldchoice='';
    1718     else
    1719         fieldchoice=menu{index};
    1720     end   
    1721     h = waitbar(0,'removing velocity vectors, fix1');% display a wait bar
    1722     test_mask=get(handles.get_mask_fix1,'Value');   
    1723     if test_mask
    1724         maskdispl=get(handles.mask_fix1,'String');
    1725         if exist(maskdispl,'file')
    1726             test_mask=2;
    1727             maskname=maskdispl;
    1728         else
    1729             maskbase=[get(handles.displ_filebase,'String') '_' maskdispl]; % mask root name
    1730         end
    1731     end
    1732     for ifile=1:nbfield
    1733         waitbar(ifile/nbfield); %update the waitbar
    1734         for j=1:nbslice
    1735             if test_mask==0
    1736                 maskname='noFile use default';
    1737                 maskflag=0;
    1738             elseif test_mask==1
    1739                 nbslice_mask=str2double(maskdispl(1:end-4)); %
    1740                 num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
    1741                 maskname=name_generator(maskbase,num1_mask,1,'.png','_i');% mask corresponding to the first image of the pair
    1742                 maskflag= exist(maskname,'file')==2;
    1743                 if ~maskflag;
    1744                     maskname='noFile use default';
    1745                 end             
    1746             end
    1747             if ~isempty(file_ref_fix1)
    1748                 file_ref=file_ref_fix1{ifile,j};
    1749             else
    1750                 file_ref='';
    1751             end
    1752             error=RUN_FIX(filecell.nc.civ1{ifile,j},field1,flagindex,1,thresh_vecC,maskflag,maskname,...
    1753                                     thresh_vel,inf_sup,file_ref,fieldchoice);
    1754 
    1755             if compare==3 &&(isequal(mode,'pair j1-j2') || isequal(mode,'series(Dj)') || isequal(mode,'series(Di)'))
    1756                  if test_mask==0 
    1757                       maskname='noFile use default';
    1758                       maskflag=0;
    1759                  else
    1760                      maskbase=[get(handles.displ_filebase2,'String') '_' maskdispl]; % mask root name
    1761                      nbslice_mask=str2num(maskdispl(1:end-4)); %
    1762                      num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;               
    1763                      maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
    1764                      maskflag= exist(maskname,'file')==2;
    1765                      if ~maskflag;
    1766                         maskname='noFile use default';
    1767                      end
    1768                  end
    1769                  error=RUN_FIX(filecell.ncA.civ1{ifile,j},field1,flagindex,1,thresh_vecC,maskflag,maskname,...
    1770                                     thresh_vel,inf_sup,file_ref,fieldchoice);
    1771                  if ~isempty(error)
    1772                     msgbox_uvmat('ERROR',error)
    1773                     return
    1774                  end             
    1775             end
    1776         end
    1777     end
    1778     close(h)
    1779 end
    1780 
    1781 % RUN PATCH1
    1782 if box_test(3)==1
    1783     rho_patch1=str2num(get(handles.rho_patch1,'String'));
    1784     if isempty(rho_patch1)
    1785         rho_patch1='1000';
    1786         set(handles.rho_patch1,'String','1')
    1787     else
    1788         rho_patch1=num2str(1000*rho_patch1);
    1789     end
    1790     nx_patch1=get(handles.nx_patch1,'String');
    1791     if isequal(str2num(nx_patch1),[])
    1792          nx_patch1='50' ;%default
    1793          set(handles.nx_patch1,'String','50');
    1794     end
    1795     ny_patch1=get(handles.ny_patch1,'String');
    1796     if isequal(str2num(ny_patch1),[])
    1797          ny_patch1='50' ;%default
    1798          set(handles.ny_patch1,'String','50');
    1799     end
    1800     subdomain_patch1=get(handles.subdomain_patch1,'String');
    1801     thresh_patch1=get(handles.thresh_patch1,'String');
    1802     test_interp=get(handles.test_interp,'Value');
    1803     icount=0;
    1804     for ifile=1:nbfield
    1805         for j=1:nbslice
    1806             icount=icount+1;
    1807             barlength=0.188*icount/(nbfield*nbslice);
    1808             set(handles.waitbar_patch1,'Position',[0.946 0.627-barlength 0.03 barlength])
    1809             drawnow
    1810             if  isequal(get(handles.test_stereo1,'Value'),0)
    1811                 cmd=RUN_PATCH(filecell.nc.civ1{ifile,j},nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,test_interp);
    1812                 s=-1;
    1813                 if sge
    1814                     [s,w]=unix(['qrsh -q -fast.q ' cmd]);
    1815                 end
    1816                 if s~=0
    1817                     display(['!' cmd])
    1818                     eval(['!' cmd]);                 
    1819                 end
    1820 
    1821                 %stereo case:
    1822             elseif  isequal(get(handles.test_stereo1,'Value'),1)
    1823                 if exist('stinterp_exe','var')%Prog Gauthier
    1824                     cmd=RUN_STINTERP(stinterp_exe,filecell.ncA.civ1{ifile,j},filecell.nc.civ1{ifile,j},filecell.st{ifile,j},...
    1825                           nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,[filebase_A '.xml'],[filebase_B '.xml']);
    1826                     display(['!' cmd])
    1827                     eval(['!' cmd]);       
    1828                 else
    1829                     RUN_STLIN(filecell.ncA.civ1{ifile,j},filecell.nc.civ1{ifile,j},'civ1',filecell.st{ifile,j},...
    1830                         str2num(nx_patch1),str2num(ny_patch1),str2num(thresh_patch1),[filebase_A '.xml'],[filebase_B '.xml']);
    1831                 end
    1832             end
    1833             if compare==3 && isequal(get(handles.test_stereo1,'Value'),0)
    1834                 cmd=RUN_PATCH(filecell.ncA.civ1{ifile,j},nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,test_interp);
    1835                 s=-1;
    1836                 if sge
    1837                     [s,w]=unix(['qrsh -q -fast.q ' cmd]);
    1838                 end
    1839                 if s~=0
    1840                    display(['!' cmd])
    1841                    eval(['!' cmd]);
    1842                 end
    1843             end
    1844         end
    1845     end
    1846 end
    1847 
    1848 % CIV2
    1849 if box_test(4)==1
    1850     RUN_CIV2(handles,filecell.ima1.civ2,filecell.ima2.civ2,filecell.nc.civ1,filecell.nc.civ2,num1_civ2,num2_civ2,...
    1851         num_a_civ2,num_b_civ2,nom_type_nc)
    1852 end
    1853 
    1854 % FIX2
    1855 if box_test(5)==1
    1856     %names of the civ2 fields
    1857     field2.vel_type='civ2';
    1858     field2.nb='nb_vectors2';
    1859     field2.X='vec2_X';
    1860     field2.Y='vec2_Y';
    1861     field2.U='vec2_U';
    1862     field2.V='vec2_V';
    1863     field2.fixflag='vec2_FixFlag';
    1864     flagindex(1)=get(handles.vec_Fmin2_2, 'Value');
    1865     flagindex(2)=get(handles.vec_F3_2, 'Value');
    1866     flagindex(3)=get(handles.vec_F4, 'Value');
    1867     thresh_vec2C=str2num(get(handles.thresh_vec2C,'String'));%threshold on image correlation vec_C
    1868     thresh_vel2=str2num(get(handles.thresh_vel2,'String'));%threshold on velocity modulus
    1869     inf_sup=get(handles.inf_sup2,'Value');
    1870     menu=get(handles.field_ref2,'String');
    1871     index=get(handles.field_ref2,'Value');
    1872     if isempty(menu)
    1873         fieldchoice='';
    1874     else
    1875         fieldchoice=menu{index};
    1876     end   
    1877     h = waitbar(0,['removing velocity vectors, fix2']);% display a wait bar
    1878     test_mask=get(handles.get_mask_fix2,'Value');
    1879     if test_mask
    1880         maskdispl=get(handles.mask_fix2,'String');
    1881         if exist(maskdispl,'file')
    1882             test_mask=2;
    1883             maskname=maskdispl;
    1884         else
    1885             maskbase=[get(handles.displ_filebase,'String') '_' maskdispl]; % mask root name
    1886         end
    1887     end
    1888     for ifile=1:nbfield
    1889         waitbar(ifile/nbfield); %update the waitbar
    1890         for j=1:nbslice       
    1891            if test_mask==0
    1892                 maskname='noFile use default';
    1893                 maskflag=0;
    1894            elseif test_mask==1
    1895                 nbslice_mask=str2num(maskdispl(1:end-4)); %
    1896                 num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
    1897                 maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
    1898                 maskflag= exist(maskname,'file')==2;
    1899                 if ~maskflag;
    1900                       maskname='noFile use default';
    1901                 end
    1902             end
    1903             if ~isempty(file_ref_fix2)
    1904                 file_ref=file_ref_fix2{ifile,j};
    1905             else
    1906                 file_ref='';
    1907             end
    1908             error=RUN_FIX(filecell.nc.civ2{ifile,j},field2,flagindex,2,thresh_vec2C,maskflag,maskname,...
    1909                                     thresh_vel2,inf_sup,file_ref,fieldchoice);
    1910             if ~isempty(error)
    1911                 msgbox_uvmat('ERROR',error)
    1912                 return
    1913             end 
    1914             if compare==3
    1915                  if test_mask==0 
    1916                       maskname='noFile use default';
    1917                       maskflag=0;
    1918                  else
    1919                       maskbase=[get(handles.displ_filebase2,'String') '_' maskdispl]; % mask root name
    1920                       nbslice_mask=str2num(maskdispl(1:end-4)); %
    1921                       num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
    1922                       maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
    1923                       maskflag= exist(maskname,'file')==2;
    1924                       if ~maskflag;
    1925                          maskname='noFile use default';
    1926                       end
    1927                  end
    1928                  error=RUN_FIX(filecell.ncA.civ2{ifile,j},field2,flagindex,1,thresh_vec2C,maskflag,maskname,...
    1929                                     thresh_vel2,inf_sup,file_ref,fieldchoice);
    1930                  if ~isempty(error)
    1931                     msgbox_uvmat('ERROR',error)
    1932                     return
    1933                  end 
    1934             end
    1935         end
    1936     end
    1937     close(h)
    1938 end
    1939 
    1940 %PATCH 2
    1941 if box_test(6)==1
    1942     rho_patch2=str2num(get(handles.rho_patch2,'String'));
    1943     if isempty(rho_patch2)
    1944         rho_patch2='1000';
    1945         set(handles.rho_patch2,'String','1')
    1946     else
    1947         rho_patch2=num2str(1000*rho_patch2);
    1948     end
    1949     nx_patch2=get(handles.nx_patch2,'String');
    1950     ny_patch2=get(handles.ny_patch2,'String');
    1951     thresh_patch2=get(handles.thresh_patch2,'String');
    1952     if isequal(str2num(nx_patch2),[])
    1953          nx_patch2='50' ;%default
    1954          set(handles.nx_patch2,'String','50');
    1955     end
    1956     if isequal(str2num(ny_patch2),[])
    1957          ny_patch2='50' ;%default
    1958          set(handles.ny_patch2,'String','50');
    1959     end
    1960     subdomain_patch2=get(handles.subdomain_patch2,'String');
    1961     icount=0;
    1962     for ifile=1:nbfield
    1963         for j=1:nbslice
    1964             icount=icount+1;
    1965             barlength=0.188*icount/(nbfield*nbslice);
    1966             set(handles.waitbar_patch2,'Position',[0.946 0.188-barlength 0.03 barlength])
    1967             drawnow
    1968             if compare~=3 | isequal(get(handles.test_stereo2,'Value'),0)
    1969                 cmd=RUN_PATCH(filecell.nc.civ2{ifile,j},nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,1,0);
    1970                 s=-1;
    1971                 if sge
    1972                     [s,w]=unix(['qrsh -q -fast.q ' cmd]);
    1973                 end
    1974                 if s~=0
    1975                     display(['!' cmd])
    1976                     eval(['!' cmd]);
    1977                 end
    1978             elseif compare==3 &&  isequal(get(handles.test_stereo2,'Value'),1)
    1979                if exist('stinterp_exe','var')%Prog Gauthier 
    1980                    cmd=RUN_STINTERP(stinterp_exe,filecell.ncA.civ2{ifile,j},filecell.nc.civ2{ifile,j},filecell.st{ifile,j},...
    1981                    nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,thresh_patch2,[filebase_A '.xml'],[filebase_B '.xml']);
    1982                    display(['!' cmd])
    1983                    eval(['!' cmd])
    1984                else
    1985                    RUN_STLIN(filecell.ncA.civ2{ifile,j},filecell.nc.civ2{ifile,j},'civ2',filecell.st{ifile,j},...
    1986                    str2num(nx_patch2),str2num(ny_patch2),str2num(thresh_patch2),[filebase_A '.xml'],[filebase_B '.xml'])
    1987                end
    1988             end   
    1989             if compare==3 && isequal(get(handles.test_stereo2,'Value'),0)
    1990                 cmd=RUN_PATCH(filecell.ncA.civ2{ifile,j},nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,1,0);
    1991                 s=-1;
    1992                 if sge
    1993                     [s,w]=unix(['qrsh -q -fast.q ' cmd]);
    1994                 end
    1995                 if s~=0
    1996                     display(['!' cmd])
    1997                     eval(['!' cmd]);
    1998                 end
    1999             end
    2000         end
    2001     end
    2002 end
    2003 
    2004 set(handles.RUN, 'Enable','On')
    2005 set(handles.RUN,'BackgroundColor',[1 0 0])
    2006 
    2007 %save the current interface setting as figure namefig, append .0 to the name if it already exists
    2008 if isfield(filecell,'st')
    2009     fileresu=filecell.st{1,1};
    2010 elseif isfield(filecell,'nc')
    2011     if isfield(filecell.nc,'civ2')
    2012         fileresu=filecell.nc.civ2{1,1};
    2013     else
    2014         fileresu=filecell.nc.civ1{1,1};
    2015     end
    2016 end
    2017 [RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileresu);
    2018 namedoc=fullfile(RootPath,subdir,RootFile);
    2019 detect=1;
    2020 while detect==1
    2021     namefigfull=[namedoc '.fig'];
    2022     hh=dir(namefigfull);
    2023     if ~isempty(hh)
    2024         detect=1;
    2025         namedoc=[namedoc '.0'];
    2026     else
    2027         detect=0;
    2028     end
    2029 end
    2030 saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
    2031 
    2032 %------------------------------------------------------------------------
    2033 % --- Executes on button press in BATCH: remote processing
    2034 function BATCH_Callback(hObject, eventdata, handles)
    2035 %------------------------------------------------------------------------
    2036 global civ1_exe civ2_exe patch_exe patch_new_exe fix_exe todo_path sge Civ_exe
    2037 compare=get(handles.compare,'Value');%test for usual PIV (compare=1) or displacement (=2) or stereo PIV (=3)
    2038 
    2039 %check the list of operations:
    2040 operations={'CIV1','FIX1','PATCH1','CIV2','FIX2','PATCH2'};
    2041 run_flag=1;
    2042 box_test(1)=get(handles.CIV1,'Value');
    2043 box_test(2)=get(handles.FIX1,'Value');
    2044 box_test(3)=get(handles.PATCH1,'Value');
    2045 box_test(4)=get(handles.CIV2,'Value');
    2046 box_test(5)=get(handles.FIX2,'Value');
    2047 box_test(6)=get(handles.PATCH2,'Value');
    2048 index=find(box_test==1);
    2049 if isempty(index)
    2050     msgbox_uvmat('ERROR','no selected operation')
    2051     return
    2052 end
    2053 index_first=min(index);
    2054 index_last=max(index);
    2055 box_used=box_test([index_first : index_last]);
    2056 [box_missing,ind_missing]=min(box_used);
    2057 if isequal(box_missing,0)
    2058     msgbox_uvmat('ERROR',['missing' cell2mat(operations(ind_missing))]);
    2059     return
    2060 end
    2061 
    2062 %root name
    2063 filebase=get(handles.displ_filebase,'String');
    2064 if isempty(filebase)||isequal(filebase,'')
    2065     msgbox_uvmat('ERROR','no input files')
    2066     return
    2067 end
    20682084   
    20692085%check mask if selecetd
     
    20992115if exist(xmlfile,'file')
    21002116    t=xmltree(xmlfile);
    2101     sparam=convert(t);
     2117    s=convert(t);
    21022118end
    21032119% else
     
    21082124%     end
    21092125% end
    2110 sge=0;
    2111 if isfield(sparam,'Civ_exe')
    2112     Civ_exe=sparam.Civ_exe;
    2113 end
    2114 if isfield(sparam,'Civ1_exe')
    2115     civ1_exe=sparam.Civ1_exe;
    2116 end
    2117 if isfield(sparam,'Civ2_exe')
    2118     civ2_exe=sparam.Civ2_exe;
    2119 end
    2120 if isfield(sparam,'Patch_exe')
    2121     patch_exe=sparam.Patch_exe;
    2122 end
    2123  if isfield(sparam,'PatchNew_exe')
    2124     patch_new_exe=sparam.PatchNew_exe;
     2126% batch=0;
     2127if batch
     2128    if isfield(s,'BatchParam')
     2129        sparam=s.BatchParam;
     2130        if ~ismember(sparam.BatchMode,{'sge'})
     2131            msgbox_uvmat('ERROR',['batch mode ' sparam.BatchMode ' not supported by UVMAT'])
     2132        end
     2133    else
     2134        msgbox_uvmat('ERROR','no batch mode defined in PARAM.xml')
     2135        return
     2136    end
     2137else
     2138    if isfield(s,'RunParam')
     2139        sparam=s.RunParam;
     2140    else
     2141        msgbox_uvmat('ERROR','no civ binaries defined in PARAM.xml')
     2142        return
     2143    end
     2144end
     2145if isfield(sparam,'CivBin')
     2146    CivBin=sparam.CivBin;
     2147end
     2148if isfield(sparam,'Civ1Bin')
     2149    civ1Bin=sparam.Civ1Bin;
     2150end
     2151if isfield(sparam,'Civ2Bin')
     2152    civ2Bin=sparam.Civ2Bin;
     2153end
     2154if isfield(sparam,'PatchBin')
     2155    patchBin=sparam.PatchBin;
     2156end
     2157 if isfield(sparam,'PatchNewBin')
     2158    patch_newBin=sparam.PatchNewBin;
    21252159 end
    2126  if isfield(sparam,'Fix_exe')
    2127     fix_exe=sparam.Fix_exe;
     2160 if isfield(sparam,'FixBin')
     2161    fixBin=sparam.FixBin;
    21282162 end
    2129  if isfield(sparam,'Todo_path')
    2130     todo_path=sparam.Todo_path;
    2131  end
    2132 if isfield(sparam,'SGE')
    2133     sge=str2num(sparam.SGE);
    2134 end
     2163%  if isfield(sparam,'Todo_path')
     2164%     todo_path=sparam.Todo_path;
     2165%  end
     2166if batch
     2167    if isfield(sparam,'BatchMode')
     2168        batch_mode=sparam.BatchMode;
     2169    end
     2170else
     2171    MaxCivProcesses=50;
     2172   if isfield(sparam,'MaxCivProcesses')
     2173        MaxCivProcesses=str2double(sparam.MaxCivProcesses);
     2174   end
     2175end
     2176
     2177%initialize the waitbars
     2178set(handles.waitbar_1,'Position',[0.946 0.876 0.03 0.001])
     2179set(handles.waitbar_patch1,'Position',[0.946 0.439 0.03 0.001])
     2180set(handles.waitbar_civ2,'Position',[0.946 0.219 0.03 0.001])
     2181set(handles.waitbar_patch2,'Position',[0.946 0.0 0.03 0.001])
     2182set(handles.BATCH, 'Enable','Off')
     2183set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
     2184drawnow
     2185%get the filename root, nomenclature and numbers
     2186
     2187% for Windows system find the UBC path name if needed
     2188if ~isunix & isequal(todo_path(1:2),'\\') & isequal(filebase(2:3),':\')
     2189    cur_dir=pwd;
     2190    if ~isequal(cur_dir(2:3),':\')
     2191        cd(matlabroot); %move to the Matlab root directory if the current Matlab dir does not allow the dos command or is M:
     2192    end
     2193    [ss,ww]=dos(['net use ' filebase(1:2)]);
     2194    if isequal(ss,0)
     2195        rankpath=findstr(ww,'\\');
     2196        if ~isempty(rankpath)
     2197            wwrest=ww(rankpath:end);
     2198            rankend=min(find(double(wwrest)==10))-1;
     2199            filebase=[wwrest(1:rankend) filebase(3:end)];
     2200            set(handles.displ_filebase,'String',filebase);
     2201        end
     2202    else
     2203         msgbox_uvmat('ERROR','for BATCH option, UBC file names, beginning by \\, are needed');
     2204         set(handles.BATCH, 'Enable','On')
     2205         set(handles.BATCH,'BackgroundColor',[1 0 0])
     2206         return
     2207    end
     2208end
     2209
     2210% set the list of files and check them
     2211display('checking the files...')
     2212[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]=...
     2213       set_civ_filenames(handles,compare,box_test);
    21352214
    21362215%choice of batch priority
    21372216ind_answer=2;
    2138 if sge
     2217if batch
    21392218    [s,w]=unix('qstat -q civ.q|grep job_| wc -l'); %check the waiting list (command unix)
    21402219    if isequal(s,0)
     
    21522231        return
    21532232    end
    2154 end
    2155 
    2156 %initialize the waitbars
    2157 set(handles.waitbar_1,'Position',[0.946 0.876 0.03 0.001])
    2158 set(handles.waitbar_patch1,'Position',[0.946 0.439 0.03 0.001])
    2159 set(handles.waitbar_civ2,'Position',[0.946 0.219 0.03 0.001])
    2160 set(handles.waitbar_patch2,'Position',[0.946 0.0 0.03 0.001])
    2161 set(handles.BATCH, 'Enable','Off')
    2162 set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
    2163 drawnow
    2164 %get the filename root, nomenclature and numbers
    2165 
    2166 % for Windows system find the UBC path name if needed
    2167 if ~isunix & isequal(todo_path(1:2),'\\') & isequal(filebase(2:3),':\')
    2168     cur_dir=pwd;
    2169     if ~isequal(cur_dir(2:3),':\')
    2170         cd(matlabroot); %move to the Matlab root directory if the current Matlab dir does not allow the dos command or is M:
    2171     end
    2172     [ss,ww]=dos(['net use ' filebase(1:2)]);
    2173     if isequal(ss,0)
    2174         rankpath=findstr(ww,'\\');
    2175         if ~isempty(rankpath)
    2176             wwrest=ww(rankpath:end);
    2177             rankend=min(find(double(wwrest)==10))-1;
    2178             filebase=[wwrest(1:rankend) filebase(3:end)];
    2179             set(handles.displ_filebase,'String',filebase);
    2180         end
    2181     else
    2182          msgbox_uvmat('ERROR','for BATCH option, UBC file names, beginning by \\, are needed');
    2183          set(handles.BATCH, 'Enable','On')
    2184          set(handles.BATCH,'BackgroundColor',[1 0 0])
    2185          return
    2186     end
    2187 end
    2188 
    2189 % set the list of files and check them
    2190 display('checking the files...')
    2191 [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]=...
    2192        set_civ_filenames(handles,compare,box_test);
     2233else
     2234    if isunix
     2235        [s,w]=unix('ps faux |grep civ|wc -l');
     2236        w(end)=[];
     2237        if str2num(w)+numel(filecell)> MaxCivProcesses
     2238            msgbox_uvmat('ERROR',{['There are already ' w ' civ processes running locally'];'Use BATCH or submit RUN later'})
     2239            return
     2240        end
     2241    end
     2242end
    21932243 
    21942244display('files OK, processing...') 
     
    22272277 
    22282278 %get patch1 parameters
    2229  if box_test(3)==1
     2279if box_test(3)==1
    22302280        rho_patch1=str2num(get(handles.rho_patch1,'String'));
    22312281        if isempty(rho_patch1)
     
    22962346end
    22972347
    2298 if ~sge
    2299        
    2300     %OPEN THE WAIT LIST FOR BATCH PROCESSES
    2301     name_lock=fullfile(todo_path,'lock'); %lock file
    2302     iwait=0;
    2303     while(exist(name_lock) & iwait<15)
    2304         pause(1); %wait 1 second
    2305         iwait=iwait+1;
    2306     end
    2307     if iwait==15
    2308         msgbox_uvmat('ERROR',['I''m tired to wait for the lock file, please delete it then click again on BATCH' name_lock ])
    2309         set(handles.BATCH, 'Enable','On')
    2310         set(handles.BATCH,'BackgroundColor',[1 0 0])
    2311         return
    2312     end
    2313     p0=fopen(name_lock,'w'); %create the file name_lock: prevents other users to interfere
    2314     name_todo=fullfile(todo_path,'TODO.txt');
    2315     p1=fopen(name_todo,'a');
    2316     if (p1<0)
    2317         msgbox_uvmat('ERROR',['error in opening ' name_todo])
    2318         set(handles.BATCH, 'Enable','On')
    2319         set(handles.BATCH,'BackgroundColor',[1 0 0])
    2320         return;
    2321     end
    2322 end
     2348% if ~sge
     2349%        
     2350%     %OPEN THE WAIT LIST FOR BATCH PROCESSES
     2351%     name_lock=fullfile(todo_path,'lock'); %lock file
     2352%     iwait=0;
     2353%     while(exist(name_lock) & iwait<15)
     2354%         pause(1); %wait 1 second
     2355%         iwait=iwait+1;
     2356%     end
     2357%     if iwait==15
     2358%         msgbox_uvmat('ERROR',['I''m tired to wait for the lock file, please delete it then click again on BATCH' name_lock ])
     2359%         set(handles.BATCH, 'Enable','On')
     2360%         set(handles.BATCH,'BackgroundColor',[1 0 0])
     2361%         return
     2362%     end
     2363%     p0=fopen(name_lock,'w'); %create the file name_lock: prevents other users to interfere
     2364%     name_todo=fullfile(todo_path,'TODO.txt');
     2365%     p1=fopen(name_todo,'a');
     2366%     if (p1<0)
     2367%         msgbox_uvmat('ERROR',['error in opening ' name_todo])
     2368%         set(handles.BATCH, 'Enable','On')
     2369%         set(handles.BATCH,'BackgroundColor',[1 0 0])
     2370%         return;
     2371%     end
     2372% end
    23232373
    23242374%MAIN LOOP
     
    23312381        i_cmd=0;
    23322382        cmd='';
    2333         if sge
     2383        if batch
    23342384           %fid=fopen([filename '.cmx'],'w')
    23352385           cmd='#!/bin/bash';
     
    24072457            i_cmd=i_cmd+1;
    24082458            if isequal(civAll,0)
    2409                 cmd=[cmd '\n' BATCH_CIV1(filename_cmx(1:end-4),namelog,par_civ1,handles)];
     2459                cmd=[cmd '\n' BATCH_CIV1(filename_cmx(1:end-4),namelog,par_civ1,handles,sparam)];
    24102460            else
    24112461                 civAllCmd=[civAllCmd ' civ1 '];
     
    24362486           end
    24372487           if isequal(civAll,0)
    2438            cmd_FIX=[fix_exe ' -f ' filecell.nc.civ1{ifile,j} ' -fi1 ' num2str(flagindex1(1)) ...
     2488           cmd_FIX=[fixBin ' -f ' filecell.nc.civ1{ifile,j} ' -fi1 ' num2str(flagindex1(1)) ...
    24392489                   ' -fi2 ' num2str(flagindex1(2)) ' -fi3 ' num2str(flagindex1(3)) ...
    24402490                   ' -threshC ' num2str(thresh_vecC1) ' -threshV ' num2str(thresh_vel1) ' -maskName ' maskname];
     
    25732623            %endTESTgrid
    25742624            i_cmd=i_cmd+1;
    2575             cmd_CIV2=BATCH_CIV2(filename_cmx,namelog,par_civ2);
     2625            cmd_CIV2=BATCH_CIV2(filename_cmx,namelog,par_civ2,sparam);
    25762626            if isequal(civAll,0)
    25772627                if(isunix)
     
    25822632            else
    25832633                 civAllCmd=[civAllCmd ' civ2 '];
    2584                  str=BATCH_CIV2_Unified(filename_cmx([1:end-4]),namelog,par_civ2);
     2634                 str=BATCH_CIV2_Unified(filename_cmx([1:end-4]),namelog,par_civ2,sparam);
    25852635                 fieldnames=fields(str);
    25862636                [civAllxml,uid_civ2]=add(civAllxml,1,'element','civ2');
     
    26082658            end                 
    26092659           if isequal(civAll,0)
    2610                 cmd_FIX=[fix_exe ' -f ' filecell.nc.civ2{ifile,j} ' -fi1 ' num2str(flagindex2(1)) ...
     2660                cmd_FIX=[fixBin ' -f ' filecell.nc.civ2{ifile,j} ' -fi1 ' num2str(flagindex2(1)) ...
    26112661                   ' -fi2 ' num2str(flagindex2(2)) ' -fi3 ' num2str(flagindex2(3)) ...
    26122662                   ' -threshC ' num2str(thresh_vec2C) ' -threshV ' num2str(thresh_vel2) ' -maskName ' maskname];
     
    26812731        if isequal(civAll,1)
    26822732            save(civAllxml,[filename_cmx([1:end-4]) '.xml']);
    2683             cmd=char({cmd;[Civ_exe ' -f ' [filename_cmx([1:end-4]) '.xml'] ' ' civAllCmd]});
     2733            cmd=char({cmd;[CivBin ' -f ' [filename_cmx([1:end-4]) '.xml'] ' ' civAllCmd]});
    26842734        end
    26852735      % create the .bat file:
    2686         if sge
     2736        if batch
    26872737                [Rootbat,Filebat,extbat]=fileparts(filename_cmx);
    26882738                filename_bat=fullfile(Rootbat,['job_' Filebat extbat]);
     
    26952745        fclose(fid);
    26962746        %dlmwrite(filename_bat,cmd,'');%write commands in filename_bat
    2697         if sge
    2698             pvalue=num2str((1-ind_answer)*500);
    2699             namelog=[filename_bat '.patch.log'];
    2700             ['!qsub -p ' pvalue ' -q civ.q -e ' filename_cmx(1:end-4) '.errors -o ' filename_cmx(1:end-4) '.log' ' ' filename_bat];
    2701             eval(  ['!qsub -p ' pvalue ' -q civ.q -e ' filename_cmx(1:end-4) '.errors -o ' filename_cmx(1:end-4) '.log' ' ' filename_bat]);
     2747        if batch
     2748            switch batch_mode
     2749                case 'sge'
     2750                    pvalue=num2str((1-ind_answer)*500);
     2751                    namelog=[filename_bat '.patch.log'];
     2752                    ['!qsub -p ' pvalue ' -q civ.q -e ' filename_cmx(1:end-4) '.errors -o ' filename_cmx(1:end-4) '.log' ' ' filename_bat];
     2753                    eval(  ['!qsub -p ' pvalue ' -q civ.q -e ' filename_cmx(1:end-4) '.errors -o ' filename_cmx(1:end-4) '.log' ' ' filename_bat]);
     2754            end
     2755       
     2756           
     2757
    27022758        else
     2759%% to lauch the jobs locally :
    27032760            if(isunix)
    2704               cmdtodo=['. ' filename_bat ];%removed for Mathieu tests %' && rm -f ' filename_bat] ;
     2761              eval(['!. ' filename_bat ' &']);
    27052762            else
    2706                cmdtodo=[filename_bat];%removed for Mathieu tests %' && del /F /Q ' filename_bat' ;
     2763              eval(['!' filename_bat ' &']);
    27072764            end
    2708             count= fprintf(p1,'%s\n', cmdtodo);
     2765%             if(isunix)
     2766%               cmdtodo=['. ' filename_bat ];%removed for Mathieu tests %' && rm -f ' filename_bat] ;
     2767%             else
     2768%                cmdtodo=[filename_bat];%removed for Mathieu tests %' && del /F /Q ' filename_bat' ;
     2769%             end
     2770%             count= fprintf(p1,'%s\n', cmdtodo);
    27092771        end
    27102772     end
    27112773end
    2712 if ~sge
    2713     fclose(p1);
    2714     fclose(p0);
    2715     delete(name_lock);
    2716 end
     2774% if ~sge
     2775%     fclose(p1);
     2776%     fclose(p0);
     2777%     delete(name_lock);
     2778% end
    27172779
    27182780set(handles.BATCH, 'Enable','On')
     
    34033465%------------------------------------------------------------------------
    34043466%pixels per cm and matrix of the image times, read from the .civ file by uvmat
    3405 global civ1_exe sge%name of the executable for civ1 calculation
     3467global civ1Bin sge%name of the executable for civ1 calculation
    34063468
    34073469%get civ parameters
     
    35983660       
    35993661                s=-1;
    3600         display(['!' civ1_exe ' -f ' filename_cmx ' > ' namelog ])
    3601         eval(['!' civ1_exe ' -f ' filename_cmx ' > ' namelog ]);
     3662        display(['!' civ1Bin ' -f ' filename_cmx ' > ' namelog ])
     3663        eval(['!' civ1Bin ' -f ' filename_cmx ' > ' namelog ]);
    36023664%               if sge%dispatch computation on the cluster using interactive queue
    3603 %           %  [s,w] = unix(['qrsh -q fast.q ' civ1_exe ' -f ' filename_cmx ' > ' namelog ' 2>&1' ]);
     3665%           %  [s,w] = unix(['qrsh -q fast.q ' civ1Bin ' -f ' filename_cmx ' > ' namelog ' 2>&1' ]);
    36043666%        end     
    36053667%         if s~=0
    3606 %            %  ['!' civ1_exe ' -f ' filename_cmx ' > ' namelog]
    3607 %            % eval(['!' civ1_exe ' -f ' filename_cmx ' > ' namelog]);       
     3668%            %  ['!' civ1Bin ' -f ' filename_cmx ' > ' namelog]
     3669%            % eval(['!' civ1Bin ' -f ' filename_cmx ' > ' namelog]);       
    36083670%         end
    36093671    end
    36103672end
    36113673
    3612 %------------------------------------------------------------------------
    3613 % RUN CIV2   CIV2    CIV2   CIV2
    3614 function RUN_CIV2(handles,filecell_2,filecell_3,filecell_nc1,filecell_nc2,num1,num2,num_a,num_b,nom_type_nc)
    3615 %------------------------------------------------------------------------
    3616 %filecell_2: names of first image
    3617 %filecell_3: names of second images
    3618 global civ2_exe sge
    3619 
    3620 %names of the civ2 fields
    3621 field.vel_type='civ2';
    3622 field.nb='nb_vectors2';
    3623 field.X='vec2_X';
    3624 field.Y='vec2_Y';
    3625 field.U='vec2_U';
    3626 field.V='vec2_V';
    3627 
    3628 %get civ parameters
    3629 ibx=get(handles.ibx_civ2,'String');
    3630 iby=get(handles.iby_civ2,'String');
    3631 rho=get(handles.rho_civ2,'String');
    3632 decimal=int2str(get(handles.decimal,'Value'));
    3633 deformation=int2str(get(handles.deformation,'Value'));
    3634 dx=get(handles.dx_civ2,'String');
    3635 dy=get(handles.dy_civ2,'String');
    3636 if isequal(str2num(dx),[])
    3637     dx='20';%default
    3638 end
    3639 if isequal(str2num(dy),[])
    3640     dy='20';%default
    3641 end
    3642     pxcmx='1';%velocity fields are expressed in pixel displacement
    3643     pxcmy='1';
    3644 A=imread(cell2mat(filecell_2(1,1)));%read the first image to get the size
    3645 sizim=size(A);
    3646 npx=num2str(sizim(2));
    3647 npy=num2str(sizim(1));
    3648 time=get(handles.displ_filebase,'UserData'); %get the set of times
    3649 filebase=get(handles.displ_filebase,'String');
    3650 %grid
    3651 gridname='';%default  ='noFile use default'
    3652 gridflag='n';%default
    3653 test_grid=get(handles.browse_gridciv2,'Value');
    3654 nbslice_grid=[];
    3655 if test_grid
    3656     gridname=get(handles.grid_civ2,'String');
    3657     if numel(gridname)>4 && isequal(gridname(end-3:end),'grid')
    3658         nbslice_grid=str2num(gridname(1:end-4)); %
    3659         if ~isempty(nbslice_grid)
    3660             gridflag='y';
    3661         end
    3662     elseif exist(gridname,'file')
    3663         gridflag='y';
    3664     else
    3665         msgbox_uvmat('ERROR',['input grid file ' gridname ' not found'])
    3666         return
    3667     end
    3668 end
    3669 sizcell=size(filecell_2);
    3670 nbfield=sizcell(1);
    3671 nbslice=sizcell(2);
    3672  
    3673 %main loop
    3674 icount=0;
    3675 for ifile=1:nbfield
    3676     for j=1:nbslice
    3677         icount=icount+1;
    3678         barlength=0.188*icount/(nbfield*nbslice);
    3679         set(handles.waitbar_civ2,'Position',[0.946 0.407-barlength 0.03 barlength])
    3680         drawnow
    3681         filename_ima_2=cell2mat(filecell_2(ifile,j));
    3682         filename_ima_2([end-3:end])=[];%remove .png extension
    3683         filename_ima_3=cell2mat(filecell_3(ifile,j));
    3684         filename_ima_3([end-3:end])=[];%remove .png extension
    3685         filename_cmx=cell2mat(filecell_nc2(ifile,j));%output netcdf file
    3686         filename_cmx([end-1:end])=[ 'cm'];%name of cmx file
    3687         filename_cmx=[filename_cmx 'x'];
    3688         namelog=[filename_cmx([1:end-3]) 'log'];
    3689         if size(time,1)>=num2(ifile) &  size(time,2)>=num_b(j)
    3690             Dt=num2str(time(num2(ifile),num_b(j))-time(num1(ifile),num_a(j)));
    3691             if isequal(Dt,'0')
    3692                 Dt='1' ;%case of 'displacement' mode
    3693             end
    3694             T0=num2str((time(num2(ifile),num_b(j))+time(num1(ifile),num_a(j)))/2);
    3695         else
    3696             Dt='1';
    3697             T0='0';
    3698         end
    3699         term_a=num2stra(num_a(j),nom_type_nc);
    3700         term_b=num2stra(num_b(j),nom_type_nc);
    3701         filename_nc1=cell2mat(filecell_nc1(ifile,j));
    3702         filename_nc1([end-2:end])=[]; % remove '.nc'     
    3703         if test_grid && ~isempty(nbslice_grid)       
    3704             num1_grid=mod(num1(ifile)-1,nbslice_grid)+1;
    3705             gridname=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
    3706             if ~exist(gridname,'file')
    3707                 msgbox_uvmat('ERROR',['missing grid file ' gridname])
    3708                 return
    3709             end
    3710         end     
    3711         test_mask=get(handles.get_mask_civ2,'Value');
    3712         if test_mask==0 
    3713             maskname='noFile use default';
    3714             maskflag='n';
    3715         else
    3716             maskdispl=get(handles.mask_civ2,'String');
    3717             maskbase=[filebase '_' maskdispl]; %
    3718             nbslice_mask=str2num(maskdispl(1:end-4)); %
    3719             num1_mask=mod(num1(ifile)-1,nbslice_mask)+1;
    3720             maskname =name_generator(maskbase,num1_mask,1,'.png','_i');
    3721             if ~exist(maskname,'file')
    3722                 maskflag='y';
    3723             else
    3724                 maskname='noFile use default';
    3725                 maskflag='n';
    3726             end
    3727         end
    3728    
    3729                 textcmx={'##############   CMX file';...
    3730                 ['FirstImage ' filename_ima_2];...
    3731                 ['LastImage  ' filename_ima_3];...
    3732                 'XX' ;...
    3733                 ['Mask ' maskflag];...
    3734                 ['MaskName ' maskname];...
    3735                 ['ImageSize ' npx ' ' npy];...   
    3736                 ['CorrelationBoxesSize ' ibx ' ' iby];...
    3737                 ['SearchBoxeSize ' ibx ' ' iby];...
    3738                 ['RO ' rho];...
    3739                 ['GridSpacing ' dx ' ' dy];...
    3740                 'XX 1.0';...
    3741                 ['Dt_TO ' Dt ' ' T0];...
    3742                 ['PixCmXY ' pxcmx ' ' pxcmy];...
    3743                 'XX 1';...
    3744                 ['ShiftXY 0 0'];...
    3745                 ['Grid ' gridflag];...
    3746                 ['GridName ' gridname];...
    3747                 'XX 85';...
    3748                 'XX 1.0';...
    3749                 'XX 1.0';...
    3750                 'Hart 1';...
    3751                 ['DecimalShift ' decimal];...
    3752                 ['Deformation ' deformation];...
    3753                 'CorrelationMin 0';...
    3754                 'IntensityMin 0';...
    3755                 'SeuilImage n';...
    3756                 'SeuilImageValues 0 4096';...
    3757                 ['ImageToUse ' term_a ' ' term_b];... % VERIFIER ?
    3758                 ['ImageUsedBefore ' filename_nc1]};
    3759         textout=char(textcmx);
    3760         dlmwrite(filename_cmx,textout,'');
    3761         s=-1; 
    3762         display(['!' civ2_exe ' -f ' filename_cmx ' > ' namelog ])
    3763         eval(['!' civ2_exe ' -f ' filename_cmx ' > ' namelog ]);   
    3764      
    3765 %               if sge%dispatch computation on the cluster using interactive queue
    3766 %             [s,w] = unix(['qrsh -q fast.q ' civ2_exe ' -f ' filename_cmx ' > ' namelog ' 2>&1']);
    3767 %         end     
    3768 %         if s~=0
    3769 %             eval(['!' civ2_exe ' -f ' filename_cmx ' > ' namelog]);
    3770 %             ['!' civ2_exe ' -f ' filename_cmx ' > ' namelog]
    3771 %         end                     
    3772     end
    3773 end
    3774 % close(h)
     3674% %------------------------------------------------------------------------
     3675% % RUN CIV2   CIV2    CIV2   CIV2
     3676% function RUN_CIV2(handles,filecell_2,filecell_3,filecell_nc1,filecell_nc2,num1,num2,num_a,num_b,nom_type_nc)
     3677% %------------------------------------------------------------------------
     3678% %filecell_2: names of first image
     3679% %filecell_3: names of second images
     3680% global civ2Bin sge
     3681%
     3682% %names of the civ2 fields
     3683% field.vel_type='civ2';
     3684% field.nb='nb_vectors2';
     3685% field.X='vec2_X';
     3686% field.Y='vec2_Y';
     3687% field.U='vec2_U';
     3688% field.V='vec2_V';
     3689%
     3690% %get civ parameters
     3691% ibx=get(handles.ibx_civ2,'String');
     3692% iby=get(handles.iby_civ2,'String');
     3693% rho=get(handles.rho_civ2,'String');
     3694% decimal=int2str(get(handles.decimal,'Value'));
     3695% deformation=int2str(get(handles.deformation,'Value'));
     3696% dx=get(handles.dx_civ2,'String');
     3697% dy=get(handles.dy_civ2,'String');
     3698% if isequal(str2num(dx),[])
     3699%     dx='20';%default
     3700% end
     3701% if isequal(str2num(dy),[])
     3702%     dy='20';%default
     3703% end
     3704%     pxcmx='1';%velocity fields are expressed in pixel displacement
     3705%     pxcmy='1';
     3706% A=imread(cell2mat(filecell_2(1,1)));%read the first image to get the size
     3707% sizim=size(A);
     3708% npx=num2str(sizim(2));
     3709% npy=num2str(sizim(1));
     3710% time=get(handles.displ_filebase,'UserData'); %get the set of times
     3711% filebase=get(handles.displ_filebase,'String');
     3712% %grid
     3713% gridname='';%default  ='noFile use default'
     3714% gridflag='n';%default
     3715% test_grid=get(handles.browse_gridciv2,'Value');
     3716% nbslice_grid=[];
     3717% if test_grid
     3718%     gridname=get(handles.grid_civ2,'String');
     3719%     if numel(gridname)>4 && isequal(gridname(end-3:end),'grid')
     3720%         nbslice_grid=str2num(gridname(1:end-4)); %
     3721%         if ~isempty(nbslice_grid)
     3722%             gridflag='y';
     3723%         end
     3724%     elseif exist(gridname,'file')
     3725%         gridflag='y';
     3726%     else
     3727%         msgbox_uvmat('ERROR',['input grid file ' gridname ' not found'])
     3728%         return
     3729%     end
     3730% end
     3731% sizcell=size(filecell_2);
     3732% nbfield=sizcell(1);
     3733% nbslice=sizcell(2);
     3734%  
     3735% %main loop
     3736% icount=0;
     3737% for ifile=1:nbfield
     3738%     for j=1:nbslice
     3739%         icount=icount+1;
     3740%         barlength=0.188*icount/(nbfield*nbslice);
     3741%         set(handles.waitbar_civ2,'Position',[0.946 0.407-barlength 0.03 barlength])
     3742%         drawnow
     3743%         filename_ima_2=cell2mat(filecell_2(ifile,j));
     3744%         filename_ima_2([end-3:end])=[];%remove .png extension
     3745%         filename_ima_3=cell2mat(filecell_3(ifile,j));
     3746%         filename_ima_3([end-3:end])=[];%remove .png extension
     3747%         filename_cmx=cell2mat(filecell_nc2(ifile,j));%output netcdf file
     3748%         filename_cmx([end-1:end])=[ 'cm'];%name of cmx file
     3749%         filename_cmx=[filename_cmx 'x'];
     3750%         namelog=[filename_cmx([1:end-3]) 'log'];
     3751%         if size(time,1)>=num2(ifile) &  size(time,2)>=num_b(j)
     3752%             Dt=num2str(time(num2(ifile),num_b(j))-time(num1(ifile),num_a(j)));
     3753%             if isequal(Dt,'0')
     3754%                 Dt='1' ;%case of 'displacement' mode
     3755%             end
     3756%             T0=num2str((time(num2(ifile),num_b(j))+time(num1(ifile),num_a(j)))/2);
     3757%         else
     3758%             Dt='1';
     3759%             T0='0';
     3760%         end
     3761%         term_a=num2stra(num_a(j),nom_type_nc);
     3762%         term_b=num2stra(num_b(j),nom_type_nc);
     3763%         filename_nc1=cell2mat(filecell_nc1(ifile,j));
     3764%         filename_nc1([end-2:end])=[]; % remove '.nc'     
     3765%         if test_grid && ~isempty(nbslice_grid)       
     3766%             num1_grid=mod(num1(ifile)-1,nbslice_grid)+1;
     3767%             gridname=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
     3768%             if ~exist(gridname,'file')
     3769%                 msgbox_uvmat('ERROR',['missing grid file ' gridname])
     3770%                 return
     3771%             end
     3772%         end     
     3773%         test_mask=get(handles.get_mask_civ2,'Value');
     3774%         if test_mask==0 
     3775%             maskname='noFile use default';
     3776%             maskflag='n';
     3777%         else
     3778%             maskdispl=get(handles.mask_civ2,'String');
     3779%             maskbase=[filebase '_' maskdispl]; %
     3780%             nbslice_mask=str2num(maskdispl(1:end-4)); %
     3781%             num1_mask=mod(num1(ifile)-1,nbslice_mask)+1;
     3782%             maskname =name_generator(maskbase,num1_mask,1,'.png','_i');
     3783%             if ~exist(maskname,'file')
     3784%                 maskflag='y';
     3785%             else
     3786%                 maskname='noFile use default';
     3787%                 maskflag='n';
     3788%             end
     3789%         end
     3790%    
     3791%               textcmx={'##############   CMX file';...
     3792%               ['FirstImage ' filename_ima_2];...
     3793%               ['LastImage  ' filename_ima_3];...
     3794%               'XX' ;...
     3795%               ['Mask ' maskflag];...
     3796%               ['MaskName ' maskname];...
     3797%               ['ImageSize ' npx ' ' npy];...   
     3798%               ['CorrelationBoxesSize ' ibx ' ' iby];...
     3799%               ['SearchBoxeSize ' ibx ' ' iby];...
     3800%               ['RO ' rho];...
     3801%               ['GridSpacing ' dx ' ' dy];...
     3802%               'XX 1.0';...
     3803%               ['Dt_TO ' Dt ' ' T0];...
     3804%               ['PixCmXY ' pxcmx ' ' pxcmy];...
     3805%               'XX 1';...
     3806%               ['ShiftXY 0 0'];...
     3807%               ['Grid ' gridflag];...
     3808%               ['GridName ' gridname];...
     3809%               'XX 85';...
     3810%               'XX 1.0';...
     3811%               'XX 1.0';...
     3812%               'Hart 1';...
     3813%               ['DecimalShift ' decimal];...
     3814%               ['Deformation ' deformation];...
     3815%               'CorrelationMin 0';...
     3816%               'IntensityMin 0';...
     3817%               'SeuilImage n';...
     3818%               'SeuilImageValues 0 4096';...
     3819%               ['ImageToUse ' term_a ' ' term_b];... % VERIFIER ?
     3820%               ['ImageUsedBefore ' filename_nc1]};
     3821%         textout=char(textcmx);
     3822%         dlmwrite(filename_cmx,textout,'');
     3823%         s=-1; 
     3824%         display(['!' civ2Bin ' -f ' filename_cmx ' > ' namelog ])
     3825%         eval(['!' civ2Bin ' -f ' filename_cmx ' > ' namelog ]);   
     3826%      
     3827% %             if sge%dispatch computation on the cluster using interactive queue
     3828% %             [s,w] = unix(['qrsh -q fast.q ' civ2Bin ' -f ' filename_cmx ' > ' namelog ' 2>&1']);
     3829% %         end     
     3830% %         if s~=0
     3831% %             eval(['!' civ2Bin ' -f ' filename_cmx ' > ' namelog]);
     3832% %             ['!' civ2Bin ' -f ' filename_cmx ' > ' namelog]
     3833% %         end                     
     3834%     end
     3835% end
     3836% % close(h)
    37753837
    37763838%------------------------------------------------------------------------
     
    37783840function cmd_PATCH=RUN_PATCH(filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,test_interp)
    37793841%------------------------------------------------------------------------
    3780 global patch_exe patch_new_exe
     3842global patchBin patch_newBin
    37813843        namelog=[filename_nc([1:end-3]) '_patch.log'];
    37823844        if test_interp==0
    3783             cmd_PATCH=[patch_exe ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ...
     3845            cmd_PATCH=[patchBin ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ...
    37843846            '  > ' namelog ' 2>&1']; % redirect standard output to the log file
    37853847         else %nouveau programme patch
    3786              cmd_PATCH=[patch_new_exe ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ...
     3848             cmd_PATCH=[patch_newBin ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ...
    37873849                ' -max ' thresh_value ' -nopt ' subdomain_patch  '  > ' namelog ' 2>&1']; % redirect standard output to the log file
    37883850        end
     
    37903852%------------------------------------------------------------------------
    37913853% --- STEREO Interp
    3792 function cmd=RUN_STINTERP(stinterp_exe,filename_A_nc,filename_B_nc,filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,xmlA,xmlB)
     3854function cmd=RUN_STINTERP(stinterpBin,filename_A_nc,filename_B_nc,filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,xmlA,xmlB)
    37933855%------------------------------------------------------------------------
    37943856namelog=[filename_nc([1:end-3]) '_stinterp.log'];
    3795 cmd=[stinterp_exe ' -f1 ' filename_A_nc  ' -f2 ' filename_B_nc ' -f  ' filename_nc ...
     3857cmd=[stinterpBin ' -f1 ' filename_A_nc  ' -f2 ' filename_B_nc ' -f  ' filename_nc ...
    37963858    ' -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
    37973859
     
    44734535function enable_patch1(handles)
    44744536%------------------------------------------------------------------------
    4475 global patch_new_exe
     4537global patch_newBin
    44764538set(handles.frame_patch1,'BackgroundColor',[1 1 0])
    44774539set(handles.rho_patch1,'Visible','on')
     
    44854547set(handles.nx_patch1_title,'Visible','on')
    44864548set(handles.ny_patch1_title,'Visible','on')
    4487 if (~isequal(patch_new_exe,[]) & ~isequal(patch_new_exe,[]))
     4549if (~isequal(patch_newBin,[]) & ~isequal(patch_newBin,[]))
    44884550    set(handles.test_interp,'Visible','on');
    44894551end
     
    47774839%------------------------------------------------------------------------
    47784840% --- CIV1  CIV1  CIV1 CIV1
    4779 function cmd_CIV1=BATCH_CIV1(filename,namelog,par,handles)
     4841function cmd_CIV1=BATCH_CIV1(filename,namelog,par,handles,sparam)
    47804842%------------------------------------------------------------------------
    47814843%pixels per cm and matrix of the image times, read from the .civ file by uvmat
    4782 global civ1_exe Civ_exe sge%name of the executable for civ1 calculation
    47834844
    47844845%changes : filename_cmx -> filename ( no extension )
     
    48544915fclose(fid);
    48554916 
    4856 if sge 
    4857     cmd_CIV1=[civ1_exe ' -f ' filename '.cmx' ]; % redirect standard output to the log file
    4858 else
    4859     cmd_CIV1=[civ1_exe ' -f ' filename_cmx ' > ' namelog ' 2>&1']; % redirect standard output to the log file
    4860 end
     4917% if sge 
     4918    cmd_CIV1=[sparam.Civ1Bin ' -f ' filename '.cmx' ]; % redirect standard output to the log file
     4919% else
     4920%     cmd_CIV1=[civ1Bin ' -f ' filename_cmx ' > ' namelog ' 2>&1']; % redirect standard output to the log file
     4921% end
    48614922if(isunix)
    48624923    [Rootbat,Filebat,extbat]=fileparts(namelog);
    48634924    ncName=fullfile(Rootbat,[ Filebat '.nc']);
    4864     cmd_CIV1=[cmd_CIV1 '\n' 'mv ' namelog  ' ' namelog '.civ1.log' '\n' 'chmod g+w ' ncName];
    4865 else
    4866     cmd_CIV1=[cmd_CIV1 '\n' 'copy /Y ' namelog ' ' namelog '.civ1.log'];
     4925    cmd_CIV1=[cmd_CIV1 '\n' 'mv ' namelog  ' ' regexprep(namelog,'\.log','') '.civ1.log' '\n' 'chmod g+w ' ncName];
     4926else
     4927    cmd_CIV1=[cmd_CIV1 '\n' 'copy /Y ' namelog ' ' regexprep(namelog,'\.log','') '.civ1.log'];
    48674928end
    48684929
     
    48724933%------------------------------------------------------------------------
    48734934%pixels per cm and matrix of the image times, read from the .civ file by uvmat
    4874 global civ1_exe Civ_exe%name of the executable for civ1 calculation
     4935global civ1Bin CivBin%name of the executable for civ1 calculation
    48754936
    48764937    civ1.image1=par.filename_ima_a;
     
    49114972%------------------------------------------------------------------------
    49124973%pixels per cm and matrix of the image times, read from the .civ file by uvmat
    4913 global civ2_exe Civ_exe%name of the executable for civ1 calculation
     4974global civ2Bin CivBin%name of the executable for civ1 calculation
    49144975
    49154976civ2.image1=par.filename_ima_a;
     
    49605021%------------------------------------------------------------------------
    49615022% --- CIV2  CIV2  CIV2 CIV2
    4962 function cmd_CIV2=BATCH_CIV2(filename_cmx,namelog,par)
     5023function cmd_CIV2=BATCH_CIV2(filename_cmx,namelog,par,sparam)
    49635024%------------------------------------------------------------------------
    49645025%pixels per cm and matrix of the image times, read from the .civ file by uvmat
    4965 global civ2_exe sge%name of the executable for civ1 calculation
     5026% global civ2Bin sge%name of the executable for civ1 calculation
    49665027   if isequal(par.Dt,'0')
    49675028                par.Dt='1' ;%case of 'displacement' mode
     
    50015062fprintf(fid,textout);
    50025063fclose(fid)
    5003 if sge
    5004     cmd_CIV2=[civ2_exe ' -f ' filename_cmx ]; % redirect standard output to the log file
    5005 else
    5006     cmd_CIV2=[civ2_exe ' -f ' filename_cmx ' > ' namelog ' 2>&1']; % redirect standard output to the log file
    5007 end
     5064% if sge
     5065    cmd_CIV2=[sparam.Civ2Bin ' -f ' filename_cmx ]; % redirect standard output to the log file
     5066% else
     5067%     cmd_CIV2=[civ2Bin ' -f ' filename_cmx ' > ' namelog ' 2>&1']; % redirect standard output to the log file
     5068% end
    50085069
    50095070%------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.