Changeset 465


Ignore:
Timestamp:
Jun 21, 2012, 7:16:22 PM (12 years ago)
Author:
gostiaux
Message:

write_cmd et write_param generalized
background task included
new conventions for bathc with matlab

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/civ.m

    r461 r465  
    11301130%% check if the binaries exist
    11311131ListProgram=get(handles.ListProgram,'String');
    1132 CivMode=ListProgram{get(handles.ListProgram,'Value')};
     1132Param.CivMode=ListProgram{get(handles.ListProgram,'Value')};
    11331133binary_list={};
    1134 switch CivMode
     1134switch Param.CivMode
    11351135    case 'CivX'
    11361136        binary_list={'Civ1Bin','Civ2Bin','PatchBin','FixBin'};
     
    11581158                return
    11591159            end
     1160           
    11601161        else  %look for the full path if the file name has been defined with a relative path in PARAM.xm
    11611162            fullname=fullfile(path_civ,Param.xml.(bin_name{1}));
     
    11821183    return
    11831184end
    1184 % if isempty(filecell)% (error message displayed in fct set_civ_filenames)
    1185 %     return
    1186 % end
    1187 Rootbat=fileparts(filecell.nc.civ1{1,1});%output netcdf file (without extention)
    11881185set(handles.civ,'UserData',filecell);%store for futur use of status callback
     1186
     1187
     1188%% create subfolders for log, cmx, nml, xml, bat
     1189RootBat=fileparts(filecell.nc.civ1{1,1})
     1190dir_list={'0_BAT','0_CMX','0_XML','0_LOG',}
     1191for k=1:length(dir_list)
     1192    if ~exist(fullfile(RootBat,dir_list{k}),'dir')
     1193        mkdir(fullfile(RootBat,dir_list{k}));
     1194    end
     1195end
     1196
     1197   
     1198%% PARTIE A VERIFIER
     1199%output netcdf file (without extention) Joel what does this mean ?
    11891200nbfield=numel(i1_civ1);
    11901201nbslice=numel(j1_civ1);
    1191 if ~strcmp(CivMode,'CivX')
     1202if ~strcmp(Param.CivMode,'CivX')
    11921203    if Param.CheckCiv1
    11931204        [Param.Civ1.FileTypeA,FileInfo,Param.Civ1.ImageA]=get_file_type(filecell.ima1.civ1{1});
     
    12081219for ifile=1:nbfield
    12091220    for j=1:nbslice
    1210         % initiate system command
    1211         switch CivMode
    1212             case 'CivX'
    1213                 if isunix % check: necessaire aussi en RUN?
    1214                     cmd=['#!/bin/bash \n '...
    1215                         '#$ -cwd \n '...
    1216                         'hostname && date \n '...
    1217                         'umask 002 \n'];%allow writting access to created files for user group
    1218                 else
    1219                     cmd=[];
    1220                 end
    1221             case 'CivAll'
    1222                 CivAllxml=xmltree;% xml contents,  all parameters
    1223                 CivAllCmd='';
    1224                 CivAllxml=set(CivAllxml,1,'name','CivDoc');
    1225         end
     1221
    12261222           
    12271223        % define output file name
    12281224        if Param.CheckCiv2==1 || Param.CheckFix2==1 || Param.CheckPatch2==1
    1229             OutputFile=filecell.nc.civ2{ifile,j};
     1225            Param.OutputFile=filecell.nc.civ2{ifile,j};
    12301226        else
    1231             OutputFile=filecell.nc.civ1{ifile,j};
    1232         end
    1233         OutputFile=regexprep(OutputFile,'.nc','');
    1234        
     1227            Param.OutputFile=filecell.nc.civ1{ifile,j};
     1228        end
     1229        Param.OutputFile=regexprep(Param.OutputFile,'.nc','');
     1230
    12351231        if Param.CheckCiv1
    12361232            % read image-dependent parameters
     
    12421238            end
    12431239            Param.Civ1.Time=((time(i2_civ1(ifile)+1,j2_civ1(j)+1)+time(i1_civ1(ifile)+1,j1_civ1(j)+1))/2);
    1244             if strcmp(CivMode,'CivX')
     1240            if strcmp(Param.CivMode,'CivX')
    12451241                Param.Civ1.term_a=num2stra(j1_civ1(j),nom_type_nc);%UTILITE?
    12461242                Param.Civ1.term_b=num2stra(j2_civ1(j),nom_type_nc);%
     
    12961292            end
    12971293           
    1298             % send command
    1299             switch CivMode
    1300                 case 'CivX'
    1301                     [cmd_civ,errormsg]=cmd_civ1(filecell.nc.civ1{ifile,j},Param);
    1302                     cmd=[cmd cmd_civ '\n'];
    1303                     if ~isempty(errormsg)
    1304                         return
    1305                     end
    1306                 case 'CivAll'
    1307                     CivAllCmd=[CivAllCmd ' civ1 '];
    1308                     str=CIV1_CMD_Unified(filecell.nc.civ1{ifile,j},'',Param.Civ1);
    1309                     fieldnames=fields(str);
    1310                     [CivAllxml,uid_civ1]=add(CivAllxml,1,'element','civ1');
    1311                     for ilist=1:length(fieldnames)
    1312                         val=eval(['str.' fieldnames{ilist}]);
    1313                         if ischar(val)
    1314                             [CivAllxml,uid_t]=add(CivAllxml,uid_civ1,'element',fieldnames{ilist});
    1315                             [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
    1316                         end
    1317                     end
    1318             end
    13191294        end
    13201295       
    1321         if Param.CheckFix1
    1322             switch CivMode
    1323                 case 'CivX'
    1324                     cmd=[cmd...
    1325                         cmd_fix(filecell.nc.civ1{ifile,j},Param,'Fix1') '\n'];
    1326                 case 'CivAll'%to abandon
    1327                     fix1.inputFileName=filecell.nc.civ1{ifile,j} ;
    1328                     fix1.fi1=num2str(param.fix1.flagindex1(1));
    1329                     fix1.fi2=num2str(param.fix1.flagindex1(2));
    1330                     fix1.fi3=num2str(param.fix1.flagindex1(3));
    1331                     fix1.threshC=num2str(param.fix1.thresh_vecC1);
    1332                     fix1.threshV=num2str(param.fix1.thresh_vel1);
    1333                     fieldnames=fields(fix1);
    1334                     [CivAllxml,uid_fix1]=add(CivAllxml,1,'element','fix1');
    1335                     for ilist=1:length(fieldnames)
    1336                         val=eval(['fix1.' fieldnames{ilist}]);
    1337                         if ischar(val)
    1338                             [CivAllxml,uid_t]=add(CivAllxml,uid_fix1,'element',fieldnames{ilist});
    1339                             [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
    1340                         end
    1341                     end
    1342                     CivAllCmd=[CivAllCmd ' fix1 '];
    1343             end
    1344         end
    1345        
    1346         %CheckPatch1
    1347         if Param.CheckPatch1==1
    1348             switch CivMode
    1349                 case 'CivX'
    1350                     cmd=[cmd...
    1351                         cmd_patch(filecell.nc.civ1{ifile,j},Param,'Patch1') '\n'];
    1352                 case 'CivAll'
    1353                     patch1.inputFileName=filecell.nc.civ1{ifile,j} ;
    1354                     patch1.nopt=subdomain_patch1;
    1355                     patch1.maxdiff=thresh_patch1;
    1356                     patch1.ro=rho_patch1;
    1357                     test_grid=get(handles.get_gridpatch1,'Value');
    1358                     if test_grid
    1359                         patch1.gridflag='y';
    1360                         gridname=get(handles.grid_patch1,'String');
    1361                         if isequal(gridname(end-3:end),'grid')
    1362                             nbslice_grid=str2double(gridname(1:end-4)); %
    1363                             if ~isnan(nbslice_grid)
    1364                                 i1_grid=mod(i1_civ1(ifile)-1,nbslice_grid)+1;
    1365                                 patch1.gridPatch=[filecell.filebase '_' fullfile_uvmat('','',gridname,'.grid','_1',i1_grid)];
    1366 %                                 patch1.gridPatch=[filecell.filebase '_' name_generator(gridname,i1_grid,1,'.grid','_i')];
    1367                                 if ~exist(patch1.gridPatch,'file')
    1368                                     errormsg='grid file absent for patch1';
    1369                                     return
    1370                                 end
    1371                             elseif exist(gridname,'file')
    1372                                 patch1.gridPatch=gridname;
    1373                             else
    1374                                 errormsg='grid file absent for patch1';
    1375                                 return
    1376                             end
    1377                         end
    1378                     else
    1379                         patch1.gridPatch='none';
    1380                         patch1.gridflag='n';
    1381                         patch1.m=nx_patch1;
    1382                         patch1.n=ny_patch1;
    1383                     end
    1384                     patch1.convectFlow='n';
    1385                     fieldnames=fields(patch1);
    1386                     [CivAllxml,uid_patch1]=add(CivAllxml,1,'element','patch1');
    1387                     for ilist=1:length(fieldnames)
    1388                         val=eval(['patch1.' fieldnames{ilist}]);
    1389                         if ischar(val)
    1390                             [CivAllxml,uid_t]=add(CivAllxml,uid_patch1,'element',fieldnames{ilist});
    1391                             [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
    1392                         end
    1393                     end
    1394                     CivAllCmd=[CivAllCmd ' patch1 '];
    1395             end
    1396         end
    13971296        if Param.CheckCiv2==1
    13981297            if isfield(Param.Civ2,'FileTypeA') &&(strcmp(Param.Civ2.FileTypeA,'video')|| strcmp(Param.Civ2.FileTypeA,'mmreader'))
     
    14201319            end
    14211320            Param.Civ2.Time=(time(i2_civ2(ifile)+1,j2_civ2(j)+1)+time(i1_civ2(ifile)+1,j1_civ2(j)+1))/2;
    1422             if strcmp(CivMode,'CivX')
    1423             Param.Civ2.term_a=num2stra(j1_civ2(j),nom_type_nc);
    1424             Param.Civ2.term_b=num2stra(j2_civ2(j),nom_type_nc);
     1321            if strcmp(Param.CivMode,'CivX')
     1322                Param.Civ2.term_a=num2stra(j1_civ2(j),nom_type_nc);
     1323                Param.Civ2.term_b=num2stra(j2_civ2(j),nom_type_nc);
    14251324            end
    14261325            Param.Civ2.filename_nc1=filecell.nc.civ1{ifile,j};
    14271326            Param.Civ2.filename_nc1(end-2:end)=[]; % remove '.nc'
    14281327           
    1429             % mask 
     1328            % mask
    14301329            if Param.Civ2.CheckMask
    14311330                if ~exist(Param.Civ2.Mask,'file')
     
    14351334                    [RootPathMask,RootFileMask]=fileparts(maskbase);
    14361335                    Param.Civ2.Mask=fullfile_uvmat(RootPathMask,[],RootFileMask,'.png','_1',i1_mask);
    1437 %                     Param.Civ2.Mask=name_generator(maskbase,i1_mask,1,'.png','_i');
     1336                    %                     Param.Civ2.Mask=name_generator(maskbase,i1_mask,1,'.png','_i');
    14381337                end
    14391338            end
     
    14451344                        i1_grid=mod(i1_civ2(ifile)-1,nbslice_grid)+1;
    14461345                        Param.Civ2.Grid=[filecell.filebase '_' fullfile_uvmat('','',gridname,'.grid','_1',i1_grid)];
    1447 %                         Param.Civ2.Grid=[filecell.filebase '_' name_generator(gridname,i1_grid,1,'.grid','_i')];
     1346                        %                         Param.Civ2.Grid=[filecell.filebase '_' name_generator(gridname,i1_grid,1,'.grid','_i')];
    14481347                    end
    14491348                end
     
    14511350            form=imformats(regexprep(get(handles.ImaExt,'String'),'^.',''));%look for image formats
    14521351            if isempty(form)
    1453                % ImageInfo=get(VideoReader(fullfile());
     1352                % ImageInfo=get(VideoReader(fullfile());
    14541353                Param.Civ2.ImageBitDepth=ImageInfo.BitsPerPixel/3;
    14551354            else
     
    14601359            Param.Civ2.ImageHeight=ImageInfo.Height;
    14611360            Param.Civ2.FrameIndexA=i1_civ2(ifile);
    1462              Param.Civ2.FrameIndexB=i2_civ2(ifile);
    1463 %             Param.Civ2.i1=i1_civ2(ifile);
    1464 %             Param.Civ2.i2=i2_civ2(ifile);
    1465             switch CivMode
    1466                 case 'CivX'
    1467                     cmd=[cmd...
    1468                         cmd_civ2(filecell.nc.civ2{ifile,j},Param) '\n'];
    1469                 case 'CivAll'
    1470                     CivAllCmd=[CivAllCmd ' civ2 '];
    1471                     str=CIV2_CMD_Unified(filecell.nc.civ2{ifile,j},'',Param.Civ2);
    1472                     fieldnames=fields(str);
    1473                     [CivAllxml,uid_civ2]=add(CivAllxml,1,'element','civ2');
    1474                     for ilist=1:length(fieldnames)
    1475                         val=eval(['str.' fieldnames{ilist}]);
    1476                         if ischar(val)
    1477                             [CivAllxml,uid_t]=add(CivAllxml,uid_civ2,'element',fieldnames{ilist});
    1478                             [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
    1479                         end
    1480                     end
    1481             end
     1361            Param.Civ2.FrameIndexB=i2_civ2(ifile);
     1362           
    14821363        end
    14831364       
    1484         % CheckFix2
    1485         if Param.CheckFix2==1
    1486             switch CivMode
    1487                 case 'CivX'
    1488                     cmd=[cmd...
    1489                         cmd_fix(filecell.nc.civ2{ifile,j},Param,'Fix2') '\n'];
    1490                 case 'CivAll'
    1491                     fix2.inputFileName=filecell.nc.civ2{ifile,j} ;
    1492                     fix2.fi1=num2str(flagindex2(1));
    1493                     fix2.fi2=num2str(flagindex2(2));
    1494                     fix2.fi3=num2str(flagindex2(3));
    1495                     fix2.threshC=num2str(thresh_vec2C);
    1496                     fix2.threshV=num2str(thresh_vel2);
    1497                     fieldnames=fields(fix2);
    1498                     [CivAllxml,uid_fix2]=add(CivAllxml,1,'element','fix2');
    1499                     for ilist=1:length(fieldnames)
    1500                         val=eval(['fix2.' fieldnames{ilist}]);
    1501                         if ischar(val)
    1502                             [CivAllxml,uid_t]=add(CivAllxml,uid_fix2,'element',fieldnames{ilist});
    1503                             [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
    1504                         end
    1505                     end
    1506                     CivAllCmd=[CivAllCmd ' fix2 '];
    1507             end
    1508         end
    15091365       
    1510         %CheckPatch2
    1511         if Param.CheckPatch2==1
    1512            
    1513             switch CivMode
    1514                
    1515                 case 'CivX'
    1516                     cmd=[cmd...
    1517                         cmd_patch(filecell.nc.civ1{ifile,j},Param,'Patch2') '\n'];
    1518                    
    1519                 case 'CivAll'
    1520                     patch2.inputFileName=filecell.nc.civ1{ifile,j} ;
    1521                     patch2.nopt=subdomain_patch2;
    1522                     patch2.maxdiff=thresh_patch2;
    1523                     patch2.ro=rho_patch2;
    1524                     test_grid=get(handles.get_gridpatch2,'Value');
    1525                     if test_grid
    1526                         patch2.gridflag='y';
    1527                         gridname=get(handles.grid_patch2,'String');
    1528                         if isequal(gridname(end-3:end),'grid')
    1529                             nbslice_grid=str2double(gridname(1:end-4)); %
    1530                             if ~isnan(nbslice_grid)
    1531                                 i1_grid=mod(i1_civ2(ifile)-1,nbslice_grid)+1;
    1532                                 patch2.gridPatch=[filecell.filebase '_' fullfile_uvmat('','',gridname,'.grid','_1',i1_grid)];
    1533 %                                 patch2.gridPatch=[filecell.filebase '_' name_generator(gridname,i1_grid,1,'.grid','_i')];
    1534                                 if ~exist(patch2.gridPatch,'file')
    1535                                     errormsg='grid file absent for patch2';
    1536                                     return
    1537                                 end
    1538                             elseif exist(gridname,'file')
    1539                                 patch2.gridPatch=gridname;
    1540                             else
    1541                                 errormsg='grid file absent for patch2';
    1542                                 return
    1543                             end
    1544                         end
    1545                     else
    1546                         patch2.gridPatch='none';
    1547                         patch2.gridflag='n';
    1548                         patch2.m=nx_patch2;
    1549                         patch2.n=ny_patch2;
    1550                     end
    1551                     patch2.convectFlow='n';
    1552                     fieldnames=fields(patch2);
    1553                     [CivAllxml,uid_patch2]=add(CivAllxml,1,'element','patch2');
    1554                     for ilist=1:length(fieldnames)
    1555                         val=eval(['patch2.' fieldnames{ilist}]);
    1556                         if ischar(val)
    1557                             [CivAllxml,uid_t]=add(CivAllxml,uid_patch2,'element',fieldnames{ilist});
    1558                             [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
    1559                         end
    1560                     end
    1561                     CivAllCmd=[CivAllCmd ' patch2 '];
    1562             end
    1563         end
     1366        % write the command and eventually the cmx, xml or nml files
     1367        cmd=write_cmd(Param,batch);
     1368        write_param(Param);
    15641369       
    1565         switch CivMode
    1566            
     1370
     1371       
     1372        % create the file used in run or batch
     1373        switch Param.CivMode
     1374            case 'Matlab'
     1375                filename_bat=regexprep(Param.OutputFile,'(\w+)([/\\])(\w+$)','$1$20_BAT$2$3.m');
    15671376            case {'CivX','CivAll'}
    1568                 if isequal(CivMode,'CivAll')
    1569                     save(CivAllxml,[OutputFile '.xml']);
    1570                     cmd=[cmd sparam.CivBin ' -f ' OutputFile '.xml '  CivAllCmd ' >' OutputFile '.log' '\n'];
    1571                 end             
    1572                 % create the .bat file used in run or batch
    1573                 filename_bat=[OutputFile '.bat'];
    1574                 [fid,message]=fopen(filename_bat,'w');
    1575                 if isequal(fid,-1)
    1576                     errormsg=['creation of .bat file: ' message];
    1577                     return
    1578                 end
    1579                 fprintf(fid,cmd);
    1580                 fclose(fid);           
    1581                 if isunix
    1582                     system(['chmod +x ' filename_bat]);
    1583                 end             
    1584                 batch_file_list{length(batch_file_list)+1}=filename_bat;
    1585                
    1586             case 'Matlab'
    1587                 drawnow
    1588                 if ~strcmp(compare,'stereo PIV')
    1589                     filename_xml=[OutputFile '.civ.xml'];
    1590                     t=struct2xml(Param);           
    1591                     save(t,filename_xml)
    1592                     if batch   
    1593                         path_civ=fileparts(which('civ'));
    1594                         filename_bat=[OutputFile '.bat'];
    1595                         [fid,message]=fopen(filename_bat,'w');
    1596                         if isequal(fid,-1)
    1597                             errormsg= ['creation of .bat file: ' message];
    1598                             return
    1599                         end
    1600 %                         text_matlabscript=[...
    1601 %                         '#!/bin/bash \n'...
    1602 %                         '. /etc/sysprofile \n'...
    1603 %                         'matlab -nodisplay -nosplash -nojvm <<END_MATLAB \n'...
    1604 %                         'cd(''' path_civ '''); \n'...
    1605 %                         'civ_matlab(''' filename_xml ''',''' OutputFile '.nc''); \n'...
    1606 %                         'exit \n'...
    1607 %                         'END_MATLAB \n'];
    1608                         cmd=['#!/bin/bash \n '...
    1609                         '#$ -cwd \n '...
    1610                         'hostname && date \n '...
    1611                         'umask 002 \n'...
    1612                          Param.xml.CivmBin ' ' Param.xml.RunTime ' ' filename_xml ' ' OutputFile '.nc'];%allow writting access to created files for user group
    1613                    
    1614                         fprintf(fid,cmd);
    1615                         fclose(fid);
    1616                         if isunix
    1617                             system(['chmod +x ' filename_bat]);
    1618                         end
    1619                         batch_file_list{length(batch_file_list)+1}=filename_bat;
    1620                     else
    1621                         [tild,errormsg]=civ_matlab(Param,filecell.nc.civ1{ifile,j});
    1622                         if isempty(errormsg)
    1623                             display([filecell.nc.civ1{ifile,j} ' written'])
    1624                         end
    1625                     end
    1626                 end
    1627         end
    1628     end
    1629 end
     1377                filename_bat=regexprep(Param.OutputFile,'(\w+)([/\\])(\w+$)','$1$20_BAT$2$3.bat');
     1378        end
     1379       
     1380        % print the command in the file
     1381        [fid,message]=fopen(filename_bat,'w');
     1382        if isequal(fid,-1)
     1383            errormsg=['creation of .bat file: ' message];
     1384            return
     1385        end
     1386        fprintf(fid,cmd);
     1387        fclose(fid);
     1388        if isunix
     1389            system(['chmod +x ' filename_bat]);
     1390        end
     1391        batch_file_list{length(batch_file_list)+1}=filename_bat;
     1392       
     1393    end
     1394end
     1395
     1396%% start calculation
    16301397
    16311398if batch 
    16321399    switch batch_mode   
    1633        
    16341400        case 'sge' %at the moment only psmn ENS Lyon uses it
    16351401            for p=1:length(batch_file_list)
     
    16661432                    extra_oar=answer{2};
    16671433                    walltime_onejob=600;%seconds
    1668                     filename_joblist=fullfile(Rootbat,'job_list.txt');
     1434                    filename_joblist=fullfile(RootBat,'job_list.txt');
    16691435                    fid=fopen(filename_joblist,'w');
    16701436                    for p=1:length(batch_file_list)
     
    16811447                        '"oar-parexec -s -f ' filename_joblist ' '...
    16821448                            '-l ' filename_joblist '.log"'];
    1683                     filename_oarcommand=fullfile(Rootbat,'oar_command');
     1449                    filename_oarcommand=fullfile(RootBat,'oar_command');
    16841450                    fid=fopen(filename_oarcommand,'w');
    16851451                    fprintf(fid,[oar_command '\n']);
     
    16921458                        );
    16931459                    walltime_onejob=600;%seconds
    1694                     filename_joblist=fullfile(Rootbat,'job_list.txt');
     1460                    filename_joblist=fullfile(RootBat,'job_list.txt');
    16951461                    fid=fopen(filename_joblist,'w');
    16961462                    for p=1:length(batch_file_list)
     
    17071473                        '-O ' regexprep(filename_joblist,'\.txt\>','.stdout') ' '...
    17081474                        '"oar-dispatch -f ' filename_joblist '"'];
    1709                     filename_oarcommand=fullfile(Rootbat,'oar_command');
     1475                    filename_oarcommand=fullfile(RootBat,'oar_command');
    17101476                    fid=fopen(filename_oarcommand,'w');
    17111477                    fprintf(fid,[oar_command '\n']);
     
    17141480                    eval(['! . ' filename_oarcommand])
    17151481                case 'mpilauncher'
    1716                     filename_joblist=fullfile(Rootbat,'job_list.txt');
     1482                    filename_joblist=fullfile(RootBat,'job_list.txt');
    17171483                    fid=fopen(filename_joblist,'w');
    17181484                   
     
    17251491                        '#OAR -n Mylauncher \n'...
    17261492                        '#OAR -l node=4/core=5,walltime=0:15:00 \n'...
    1727                         '#OAR -E ' fullfile(Rootbat,'stderrfile.log') ' \n'...
    1728                         '#OAR -O ' fullfile(Rootbat,'stdoutfile.log') ' \n'...
     1493                        '#OAR -E ' fullfile(RootBat,'stderrfile.log') ' \n'...
     1494                        '#OAR -O ' fullfile(RootBat,'stdoutfile.log') ' \n'...
    17291495                        '# ========================================================= \n'...
    17301496                        '# This simple program launch a multinode parallel OpenMPI mpilauncher \n'...
     
    17541520                        ];
    17551521                    %                 oarsub -S ./oar.sub
    1756                     filename_oarscript=fullfile(Rootbat,'oar_command');
     1522                    filename_oarscript=fullfile(RootBat,'oar_command');
    17571523                    fid=fopen(filename_oarscript,'w');
    17581524                    fprintf(fid,[text_oarscript]);
     
    17631529    end
    17641530else
    1765     if ~isequal(CivMode,'Matlab')
    1766         filename_superbat=fullfile(Rootbat,'job_list.bat');
    1767         fid=fopen(filename_superbat,'w');
    1768         if fid==-1
    1769             msgbox_uvmat('ERROR',['cannot create the command file ' filename_superbat])
    1770             return
    1771         end
    1772         for p=1:length(batch_file_list)
    1773             if isunix
    1774                 fprintf(fid,['sh ' batch_file_list{p} '\n']);
     1531    switch Param.CivMode
     1532        case 'Matlab'
     1533           
     1534            background=1;
     1535            if background
     1536                filename_superbat=fullfile(RootBat,'job_list.m');
     1537                fid=fopen(filename_superbat,'w');
     1538                if fid==-1
     1539                    msgbox_uvmat('ERROR',['cannot create the command file ' filename_superbat])
     1540                    return
     1541                end
     1542                fprintf(fid,['addpath(''' path_civ ''');\n']);
     1543                for p=1:length(batch_file_list)
     1544                    %                 if isunix
     1545                    %                     fprintf(fid,['sh ' batch_file_list{p} '\n']);
     1546                    %                 else
     1547                    %                     fprintf(fid,['@call "' regexprep(batch_file_list{p},'\\','\\\\') '"' '\n']);
     1548                    %                 end
     1549                    fprintf(fid,['run ' batch_file_list{p} '\n']);
     1550                   
     1551                end
     1552                fclose(fid);
     1553                 eval(['run ' filename_superbat]);                     
    17751554            else
    1776                 fprintf(fid,['@call "' regexprep(batch_file_list{p},'\\','\\\\') '"' '\n']);
    1777             end
    1778         end
    1779         fclose(fid);
    1780         if(isunix)
    1781             system(['chmod +x ' filename_superbat]);
    1782         end
    1783         system([filename_superbat ' &']);% execute main commmand
     1555                for p=1:length(batch_file_list)
     1556                    fid=fopen( batch_file_list{p});
     1557                    eval(fscanf(fid,'%s'));
     1558                    fclose(fid);
     1559                end
     1560            end
     1561           
     1562           
     1563        case {'CivX','CivAll'}
     1564            filename_superbat=fullfile(RootBat,'job_list.bat');
     1565            fid=fopen(filename_superbat,'w');
     1566            if fid==-1
     1567                msgbox_uvmat('ERROR',['cannot create the command file ' filename_superbat])
     1568                return
     1569            end
     1570            for p=1:length(batch_file_list)
     1571                if isunix
     1572                    fprintf(fid,['sh ' batch_file_list{p} '\n']);
     1573                else
     1574                    fprintf(fid,['@call "' regexprep(batch_file_list{p},'\\','\\\\') '"' '\n']);
     1575                end
     1576            end
     1577            fclose(fid);
     1578            if(isunix)
     1579                system(['chmod +x ' filename_superbat]);
     1580            end
     1581            background=0;
     1582            if background
     1583                system([filename_superbat ' &']);% execute main commmand
     1584            else
     1585                system(filename_superbat);
     1586            end
    17841587    end
    17851588end
     
    18121615t=set(t,1,'name','Civ');% set the head label
    18131616save(t,[namedoc '.civ.xml']); %save GUI  parameters as xml file
    1814 saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
     1617% saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
    18151618
    18161619%Save info in personal profile (initiate browser next time) TODO
     
    40263829end
    40273830
    4028 %------------------------------------------------------------------------
    4029 function [cmd,errormsg]=cmd_civ1(filename,Param)
    4030 %------------------------------------------------------------------------
    4031 %pixels per cm and matrix of the image times, read from the .civ file by uvmat
    4032 %changes : filename_cmx -> filename ( no extension )
    4033 cmd='';
    4034 filename=regexprep(filename,'.nc',''); %file name for the result
    4035 if isequal(Param.Civ1.Dt,0)
    4036     Param.Civ1.Dt=1 ;%case of 'displacement' mode
    4037 end
    4038 Param.Civ1.ImageA=regexprep(Param.Civ1.ImageA,'.png','');
    4039 Param.Civ1.ImageB=regexprep(Param.Civ1.ImageB,'.png','');
    4040 [fid,errormsg]=fopen([filename '.civ1.cmx'],'w');
    4041 if isequal(fid,-1)
    4042     errormsg=['cmd file ' filename ' cannot be created: ' errormsg];
    4043     return
    4044 end
    4045 fprintf(fid,['##############   CMX file' '\n' ]);
    4046 fprintf(fid,   ['FirstImage ' regexprep(Param.Civ1.ImageA,'\\','\\\\') '\n' ]);% for windows compatibility
    4047 fprintf(fid,   ['LastImage  ' regexprep(Param.Civ1.ImageB,'\\','\\\\') '\n' ]);% for windows compatibility
    4048 fprintf(fid,  ['XX' '\n' ]);
    4049 if isfield(Param.Civ1,'Mask')
    4050     fprintf(fid,  ['Mask ' 'y' '\n' ]);
    4051     fprintf(fid,  ['MaskName ' regexprep(Param.Civ1.Mask,'\\','\\\\') '\n' ]);
    4052 else
    4053     fprintf(fid,  ['Mask ' 'n' '\n' ]);
    4054     fprintf(fid,  ['MaskName ' 'noFile use default' '\n' ]);
    4055 end
    4056 fprintf(fid,   ['ImageSize ' num2str(Param.Civ1.ImageWidth) ' ' num2str(Param.Civ1.ImageHeight) '\n' ]);   %VERIFIER CAS GENERAL ?
    4057 fprintf(fid,   ['CorrelationBoxesSize ' num2str(Param.Civ1.CorrBoxSize(1)) ' ' num2str(Param.Civ1.CorrBoxSize(2)) '\n' ]);
    4058 fprintf(fid,   ['SearchBoxeSize ' num2str(Param.Civ1.SearchBoxSize(1)) ' ' num2str(Param.Civ1.SearchBoxSize(2)) '\n' ]);
    4059 fprintf(fid,   ['RO ' num2str(Param.Civ1.CorrSmooth) '\n' ]);
    4060 if isfield(Param.Civ1,'Grid')
    4061     fprintf(fid,   ['GridSpacing ' '25' ' ' '25' '\n' ]);
    4062 else
    4063     fprintf(fid,   ['GridSpacing ' num2str(Param.Civ1.Dx) ' ' num2str(Param.Civ1.Dy) '\n' ]);
    4064 end
    4065 fprintf(fid,   ['XX 1.0' '\n' ]);
    4066 fprintf(fid,   ['Dt_TO ' num2str(Param.Civ1.Dt) ' ' num2str(Param.Civ1.Time) '\n' ]);
    4067 fprintf(fid,  ['PixCmXY ' '1' ' ' '1' '\n' ]);
    4068 fprintf(fid,  ['XX 1' '\n' ]);
    4069 fprintf(fid,   ['ShiftXY ' num2str(Param.Civ1.SearchBoxShift(1)) ' '  num2str(Param.Civ1.SearchBoxShift(2)) '\n' ]);
    4070 if isfield(Param.Civ1,'Grid')
    4071     fprintf(fid,  ['Grid ' 'y' '\n' ]);
    4072     fprintf(fid,   ['GridName ' regexprep(Param.Civ1.Grid,'\\','\\\\') '\n' ]);
    4073 else
    4074     fprintf(fid,  ['Grid ' 'n' '\n' ]);
    4075     fprintf(fid,   ['GridName ' 'noFile use default' '\n' ]);
    4076 end
    4077 fprintf(fid,   ['XX 85' '\n' ]);
    4078 fprintf(fid,   ['XX 1.0' '\n' ]);
    4079 fprintf(fid,   ['XX 1.0' '\n' ]);
    4080 fprintf(fid,   ['Hart 1' '\n' ]);
    4081 fprintf(fid,  [ 'DecimalShift 0' '\n' ]);
    4082 fprintf(fid,   ['Deformation 0' '\n' ]);
    4083 fprintf(fid,  ['CorrelationMin 0' '\n' ]);
    4084 fprintf(fid,   ['IntensityMin 0' '\n' ]);
    4085 if ~isfield(Param.Civ1,'MinIma')% Image threshold not activated
    4086     fprintf(fid,  ['SeuilImage n' '\n' ]);
    4087     fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);%not used in principle
    4088 else% Image threshold  activated
    4089     if isempty(Param.Civ1.MaxIma)||isnan(Param.Civ1.MaxIma)
    4090         Param.Civ1.MaxIma=2^Param.Civ1.ImageBitDepth;%take the max image value as upper bound by default
    4091     end
    4092     fprintf(fid,  ['SeuilImage y' '\n' ]);
    4093     fprintf(fid,   ['SeuilImageValues ' num2str(Param.Civ1.MinIma) ' ' num2str(Param.Civ1.MaxIma) '\n' ]);
    4094 end
    4095 fprintf(fid,   ['ImageToUse ' Param.Civ1.term_a ' ' Param.Civ1.term_b '\n' ]); % VERIFIER ?
    4096 fprintf(fid,   ['ImageUsedBefore null null' '\n' ]);
    4097 fclose(fid);
    4098 
    4099 if(isunix) %unix (or Mac) system
    4100     cmd=['cp -f ' filename '.civ1.cmx ' filename '.cmx \n '];% the cmx file gives the name to the nc file
    4101     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
    4102     cmd=[cmd 'rm ' filename '.cmx'];
    4103 else %Windows system
    4104     filename=regexprep(filename,'\\','\\\\');
    4105     cmd=['copy /Y "' filename '.civ1.cmx" "' filename '.cmx" \n '];
    4106     cmd=[cmd '"' regexprep(Param.xml.Civ1Bin,'\\','\\\\')...
    4107         '" -f "' filename '.cmx" >"' filename '.civ1.log" \n ' ]; % redirect standard output to the log file
    4108     cmd=[cmd 'del "' filename '.cmx"'];
    4109 end
    4110 
    4111 
    4112 function cmd=cmd_fix(filename,Param,fixname)
    4113 %%
    4114 switch fixname
    4115     case 'Fix1'
    4116         fi2_value=num2str(Param.(fixname).CheckF2);
    4117     case 'Fix2'
    4118         fi2_value=num2str(Param.(fixname).CheckF4);%need to understand why...
    4119 end
    4120 filename=regexprep(filename,'.nc','');
    4121 MaskName_string='';%default
    4122 MaxVel_string='';%default
    4123 if ~isempty(Param.(fixname).MinVel)
    4124     MaxVel_string=[' -threshV ' num2str(Param.(fixname).MinVel)];
    4125 end
    4126 if isunix
    4127     cmd=[Param.xml.FixBin ' -f ' filename '.nc -fi1 ' num2str(Param.(fixname).CheckFmin2) ...
    4128         ' -fi2 ' fi2_value ' -fi3 ' num2str(Param.(fixname).CheckF3) ...
    4129         ' -threshC ' num2str(Param.(fixname).MinCorr) MaxVel_string MaskName_string...
    4130         ' >' filename '.' lower(fixname) '.log 2>&1'];
    4131 else
    4132     cmd=['"' Param.xml.FixBin '" -f "' filename '.nc" -fi1 ' num2str(Param.(fixname).CheckFmin2)...
    4133         ' -fi2 ' fi2_value ' -fi3 ' num2str(Param.(fixname).CheckF3) ...
    4134         ' -threshC ' num2str(Param.(fixname).MinCorr) MaxVel_string MaskName_string...
    4135         ' > "' filename '.' lower(fixname) '.log"'];
    4136     cmd=regexprep(cmd,'\\','\\\\');
    4137 end
    4138 
    4139 
    4140 function cmd=cmd_patch(filename,Param,patchname)
    4141 %% ------------------------------------------------------------------------
    4142 filename=regexprep(filename,'.nc','');
    4143 if isunix
    4144     cmd=[Param.xml.PatchBin...
    4145         ' -f ' filename '.nc -m ' num2str(Param.(patchname).Nx)...
    4146         ' -n ' num2str(Param.(patchname).Ny) ' -ro ' num2str(Param.(patchname).FieldSmooth)...
    4147         ' -nopt ' num2str(Param.(patchname).SubdomainSize) ...
    4148         '  > ' filename '.' lower(patchname) '.log 2>&1']; % redirect standard output to the log file
    4149 else
    4150     cmd=['"' Param.xml.PatchBin...
    4151         '" -f "' filename '.nc" -m ' num2str(Param.(patchname).Nx)...
    4152         ' -n ' num2str(Param.(patchname).Ny) ' -ro ' num2str(Param.(patchname).FieldSmooth)...
    4153         ' -nopt ' num2str(Param.(patchname).SubdomainSize)...
    4154         '  > "' filename '.' lower(patchname) '.log" 2>&1']; % redirect standard output to the log file
    4155     cmd=regexprep(cmd,'\\','\\\\');
    4156 end
    4157 
    4158 %------------------------------------------------------------------------
    4159 % --- CheckCiv2  CheckCiv2  CheckCiv2 CheckCiv2
    4160 function [cmd,errormsg]=cmd_civ2(filename,Param)
    4161 %------------------------------------------------------------------------
    4162 %pixels per cm and matrix of the image times, read from the .civ file by uvmat
    4163 % global civ2Bin sge%name of the executable for checkciv1 calculation
    4164  cmd='';
    4165 filename=regexprep(filename,'.nc','');
    4166 if isequal(Param.Civ2.Dt,'0')
    4167     Param.Civ2.Dt='1' ;%case of 'displacement' mode
    4168 end
    4169 Param.Civ2.ImageA=regexprep(Param.Civ2.ImageA,'.png','');
    4170 Param.Civ2.ImageB=regexprep(Param.Civ2.ImageB,'.png','');% bug : .png appears two times ?
    4171 [fid,errormsg]=fopen([filename '.civ2.cmx'],'w');
    4172 if isequal(fid,-1)
    4173     return
    4174 end
    4175 fprintf(fid,['##############   CMX file' '\n' ]);
    4176 fprintf(fid,   ['FirstImage ' regexprep(Param.Civ2.ImageA,'\\','\\\\') '\n' ]);% for windows compatibility
    4177 fprintf(fid,   ['LastImage  ' regexprep(Param.Civ2.ImageB,'\\','\\\\') '\n' ]);% for windows compatibility
    4178 fprintf(fid,  ['XX' '\n' ]);
    4179 if isfield(Param.Civ2,'Mask')
    4180     fprintf(fid,  ['Mask ' 'y' '\n' ]);
    4181     fprintf(fid,  ['MaskName ' regexprep(Param.Civ2.Mask,'\\','\\\\') '\n' ]);
    4182 else
    4183     fprintf(fid,  ['Mask ' 'n' '\n' ]);
    4184     fprintf(fid,  ['MaskName ' 'noFile use default' '\n' ]);
    4185 end
    4186 % fprintf(fid, ['Mask ' Param.Civ2.MaskFlag '\n' ]);
    4187 % fprintf(fid, ['MaskName ' regexprep(Param.Civ2.MaskName,'\\','\\\\') '\n' ]);% for windows compatibility
    4188 fprintf(fid,   ['ImageSize ' num2str(Param.Civ2.ImageWidth) ' ' num2str(Param.Civ2.ImageHeight) '\n' ]); 
    4189 % fprintf(fid, ['ImageSize ' num2str(Param.Civ2.npx) ' ' num2str(Param.Civ2.npy) '\n' ]);   %VERIFIER CAS GENERAL ?
    4190 fprintf(fid, ['CorrelationBoxesSize ' num2str(Param.Civ2.CorrBoxSize(1)) ' ' num2str(Param.Civ2.CorrBoxSize(2)) '\n' ]);
    4191 fprintf(fid, ['SearchBoxeSize ' num2str(Param.Civ2.CorrBoxSize(1)) ' ' num2str(Param.Civ2.CorrBoxSize(2)) '\n']);
    4192 fprintf(fid, ['RO ' num2str(Param.Civ2.CorrSmooth) '\n']);
    4193 if isfield(Param.Civ2,'Grid')
    4194     fprintf(fid,   ['GridSpacing ' '25' ' ' '25' '\n' ]);
    4195 else
    4196     fprintf(fid,   ['GridSpacing ' num2str(Param.Civ2.Dx) ' ' num2str(Param.Civ2.Dy) '\n' ]);
    4197 end
    4198 % fprintf(fid, ['GridSpacing ' num2str(Param.Civ2.Dx) ' ' num2str(Param.Civ2.Dy) '\n']);
    4199 fprintf(fid, ['XX 1.0' '\n' ]);
    4200 fprintf(fid, ['Dt_TO ' num2str(Param.Civ2.Dt) ' ' num2str(Param.Civ2.Time) '\n' ]);
    4201 fprintf(fid, ['PixCmXY ' '1' ' ' '1' '\n' ]);
    4202 fprintf(fid, ['XX 1' '\n' ]);
    4203 fprintf(fid, 'ShiftXY 0 0\n');
    4204 if isfield(Param.Civ2,'Grid')
    4205     fprintf(fid,  ['Grid ' 'y' '\n' ]);
    4206     fprintf(fid,   ['GridName ' regexprep(Param.Civ2.Grid,'\\','\\\\') '\n' ]);
    4207 else
    4208     fprintf(fid,  ['Grid ' 'n' '\n' ]);
    4209     fprintf(fid,   ['GridName ' 'noFile use default' '\n' ]);
    4210 end
    4211 % fprintf(fid, ['Grid ' Param.Civ2.GridFlag '\n' ]);
    4212 % fprintf(fid, ['GridName ' regexprep(Param.Civ2.GridName,'\\','\\\\') '\n']);
    4213 fprintf(fid, ['XX 85' '\n' ]);
    4214 fprintf(fid, ['XX 1.0' '\n' ]);
    4215 fprintf(fid, ['XX 1.0' '\n' ]);
    4216 fprintf(fid, ['Hart 1' '\n' ]);
    4217 fprintf(fid, ['DecimalShift ' num2str(Param.Civ2.CheckDecimal) '\n']);
    4218 fprintf(fid, ['Deformation ' num2str(Param.Civ2.CheckDeformation) '\n']);
    4219 fprintf(fid,  ['CorrelationMin 0' '\n' ]);
    4220 fprintf(fid,   ['IntensityMin 0' '\n' ]);
    4221 
    4222 if ~isfield(Param.Civ2,'MinIma')% Image threshold not activated
    4223     fprintf(fid,  ['SeuilImage n' '\n' ]);
    4224     fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);%not used in principle
    4225 else% Image threshold  activated
    4226     if isempty(Param.Civ2.MaxIma)||isnan(Param.Civ2.MaxIma)
    4227         Param.Civ2.MaxIma=2^Param.Civ2.ImageBitDepth;%take the max image value as upper bound by default
    4228     end
    4229     fprintf(fid,  ['SeuilImage y' '\n' ]);
    4230     fprintf(fid,   ['SeuilImageValues ' num2str(Param.Civ2.MinIma) ' ' num2str(Param.Civ2.MaxIma) '\n' ]);
    4231 end
    4232 fprintf(fid,   ['ImageToUse ' Param.Civ2.term_a ' ' Param.Civ2.term_b '\n' ]); % VERIFIER ?
    4233 fprintf(fid, ['ImageUsedBefore ' regexprep(Param.Civ2.filename_nc1,'\\','\\\\') '\n']);
    4234 fclose(fid);
    4235 
    4236 if(isunix)
    4237     cmd=['cp -f ' filename '.civ2.cmx ' filename '.cmx\n'...
    4238         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
    4239         'rm ' filename '.cmx \n'];%rename .cmx as .checkciv2.cmx, the result file is named [filename '.nc'] by CIVx
    4240 else
    4241     filename=regexprep(filename,'\\','\\\\');
    4242     cmd=['copy /Y "' filename '.civ2.cmx" "' filename '.cmx" \n'...
    4243         '"' regexprep(Param.xml.Civ2Bin,'\\','\\\\') '" -f "' filename  '.cmx" >"' filename '.civ2.log" \n'...
    4244         'del "' filename '.cmx" \n'];
    4245 end
    4246 
    4247 %------------------------------------------------------------------------
    4248 % --- CheckCiv1  Unified: TO ABADON
    4249 function xml_civ1_parameters=CIV1_CMD_Unified(filename,namelog,par)
    4250 %------------------------------------------------------------------------
    4251 %pixels per cm and matrix of the image times, read from the .civ file by uvmat
    4252 %global CivBin%name of the executable for checkciv1 calculation
    4253 
    4254 civ1.image1=par.ImageA;
    4255 civ1.image2=par.ImageB;
    4256 civ1.imageSize_X=par.npx;
    4257 civ1.imageSize_Y=par.npy;
    4258 civ1.outputFileName=[filename '.nc'];
    4259 civ1.correlationBoxesSize_X=par.ibx;
    4260 civ1.correlationBoxesSize_Y=par.iby;
    4261 civ1.searchBoxesSize_X=par.isx;
    4262 civ1.searchBoxesSize_Y=par.isy;
    4263 civ1.globalShift_X=par.shiftx;
    4264 civ1.globalShift_Y=par.shifty;
    4265 civ1.ro=par.rho;
    4266 civ1.hart='y';
    4267 if isequal(par.gridflag,'y')
    4268     civ1.grid=par.gridname;
    4269 else
    4270     civ1.grid='n';
    4271     civ1.gridSpacing_X=par.dx;
    4272     civ1.gridSpacing_Y=par.dy;
    4273 end
    4274 if isequal(par.maskflag,'y')
    4275     civ1.mask=par.maskname;
    4276 end
    4277 civ1.dt=par.Dt;
    4278 civ1.unit='pixel';
    4279 civ1.absolut_time_T0=par.Time;
    4280 civ1.pixcmx='1';
    4281 civ1.pixcmy='1';
    4282 civ1.convectFlow='n';
    4283 
    4284 xml_civ1_parameters=civ1;
    4285 
    4286 %------------------------------------------------------------------------
    4287 % --- CheckCiv2  Unified: TO ABADON
    4288 function civ2=CIV2_CMD_Unified(filename,namelog,par)
    4289 %------------------------------------------------------------------------
    4290 %pixels per cm and matrix of the image times, read from the .civ file by uvmat
    4291 %global CivBin%name of the executable for checkciv1 calculation
    4292 
    4293 filename=regexprep(filename,'.nc','');
    4294 
    4295 civ2.image1=par.ImageA;
    4296 civ2.image2=par.ImageB;
    4297 civ2.imageSize_X=par.npx;
    4298 civ2.imageSize_Y=par.npy;
    4299 civ2.inputFileName=[par.filename_nc1 '.nc'];
    4300 civ2.outputFileName=[filename '.nc'];
    4301 civ2.correlationBoxesSize_X=par.ibx;
    4302 civ2.correlationBoxesSize_Y=par.iby;
    4303 civ2.ro=par.rho;
    4304 %checkciv2.decimalShift=par.CheckDecimal;
    4305 %checkciv2.CheckDeformation=par.CheckDeformation;
    4306 if isequal(par.decimal,'1')
    4307     civ2.decimalShift='y';
    4308 else
    4309     civ2.decimalShift='n';
    4310 end
    4311 if isequal(par.deformation,'1')
    4312     civ2.deformation='y';
    4313 else
    4314     civ2.deformation='n';
    4315 end
    4316 if isequal(par.gridflag,'y')
    4317     civ2.grid=par.gridname;
    4318 else
    4319     civ2.grid='n';
    4320     civ2.gridSpacing_X=par.dx;
    4321     civ2.gridSpacing_Y=par.dy;
    4322 end
    4323 civ2.gridSpacing_X='10';
    4324 civ2.gridSpacing_Y='10';%NOTE: faut mettre gridSpacing pourque ca tourne, meme si c'est la grille qui est utilisee
    4325 if isequal(par.maskflag,'y')
    4326     civ2.mask=par.maskname;
    4327 else
    4328     civ2.mask='n';
    4329 end
    4330 civ2.dt=par.Dt;
    4331 civ2.unit='pixel';
    4332 civ2.absolut_time_T0=par.Time;
    4333 civ2.pixcmx='1';
    4334 civ2.pixcmy='1';
    4335 civ2.convectFlow='n';
    4336 
    4337 
    4338 % --- Executes on button press in TestPatch1.
    4339 function TestPatch1_Callback(hObject, eventdata, handles)
    4340 set(handles.TestPatch1,'BackgroundColor',[1 1 0])
    4341 drawnow
    4342 if get(handles.TestPatch1,'Value')
    4343     ref_i=str2double(get(handles.ref_i,'String'));
    4344     if strcmp(get(handles.ref_j,'Visible'),'on')
    4345         ref_j=str2double(get(handles.ref_j,'String'));
    4346     else
    4347         ref_j=1;%default
    4348     end
    4349     filecell=set_civ_filenames(handles,ref_i,ref_j,[0 0 1 0 0 0]);   
    4350     Data.ListVarName={'ny','nx','A'};
    4351     Data.VarDimName= {'ny','nx',{'ny','nx'}};   
    4352     param_patch1=read_GUI(handles.Patch1);
    4353     param_patch1.CivFile=filecell.nc.civ1{1};
    4354     Param.Patch1=param_patch1;
    4355     for irho=1:7
    4356         [Data,errormsg]=civ_matlab(Param);% get the grid of x, y positions set for PIV
    4357         if ~isempty(errormsg)
    4358             msgbox_uvmat('ERROR',errormsg)
    4359             return
    4360         end
    4361         SmoothingParam(irho)=Param.Patch1.FieldSmooth;
    4362         Data.Civ1_U_Diff=Data.Civ1_U_Diff(Data.Civ1_FF==0);
    4363         Data.Civ1_V_Diff=Data.Civ1_V_Diff(Data.Civ1_FF==0);
    4364         DiffVel(irho)=sqrt(mean(Data.Civ1_U_Diff.*Data.Civ1_U_Diff+Data.Civ1_V_Diff.*Data.Civ1_V_Diff))
    4365         NbSites(irho,:)=Data.Civ1_NbSites*numel(Data.Civ1_NbSites)/numel(Data.Civ1_U_Diff);
    4366         Param.Patch1.SmoothingParam=2*Param.Patch1.FieldSmooth;
    4367     end
    4368     figure
    4369     plot(SmoothingParam,DiffVel,'b',SmoothingParam,NbSites,'r')
    4370     set(handles.TestPatch1,'BackgroundColor',[1 0 0])
    4371 else
    4372     corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
    4373     if ~isempty(corrfig)
    4374         delete(corrfig)
    4375     end
    4376     hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
    4377     if ~isempty(hview_field)
    4378         delete(hview_field)
    4379     end
    4380 end
     3831
     3832
     3833
    43813834%'nomtype2pair': creates nomencalture for index pairs knowing the image nomenclature
    43823835%---------------------------------------------------------------------
    4383 % [nom_type_pair]=nomtype2pair(nom_type,Dti,Dtj);
     3836function NomTypeNc=nomtype2pair(NomTypeIma,mode)
    43843837%---------------------------------------------------------------------           
    4385 
    43863838% OUTPUT:
    4387 %nom_type_nc
    4388 
     3839% NomTypeNc
    43893840%---------------------------------------------------------------------
    43903841% INPUT:
    4391 % 'nom_type': string defining the kind of nomenclature used:
    4392      %nom_type='': constant name [filebase ext] (default output if 'nom_type' is undefined)
    4393      %nom_type='*': the same  file [filebase ext] contains successive fields (ex avi movies)
    4394      %nom_type='_i': series of files with a single index i preceded by '_'(e.g. 'aa_45.png').
    4395      %nom_type='#' series of indexed images wich is not series_i [filebase index ext], e.g. 'aa045.jpg' or 'aa45.tif'
    4396      %nom_type='_i_j' matrix of files with two indices i and j separated by '_'(e.g. 'aa_45_2.png')
    4397      %nom_type='_i1-i2' from pairs from a single index (e.g. 'aa_45-47.nc')
    4398      %nom_type='_i_j1-j2'pairs of j indices (e.g. 'aa_45_2-3.nc')
    4399      %nom_type='_i1-i2_j' pairs of i indices (e.g. 'aa_45-46_2.nc')
    4400      %nom_type='#a','#A', with a numerical index and an index letter(e.g.'aa045b.png'), OBSOLETE (replaced by 'series_i_j')
    4401      %nom_type='%03d' or '%04d', series of indexed images with numbers completed with zeros to 3 or 4 digits, e.g.'aa045.tif'
    4402      %nom_type='_%03d', '_%04d', or '_%05d', series of indexed images with _ and numbers completed with zeros to 3, 4 or 5 digits, e.g.'aa_045.tif'
    4403      %nom_type='raw_SMD', same as '#a' but with no extension ext='', OBSOLETE
    4404      %nom_type='#_ab' from pairs of '#a' images (e.g. 'aa045bc.nc'), ext='.nc', OBSOLETE (replaced by 'netc_2D')
    4405      %nom_type='%3dab' from pairs of '%3da' images (e.g. 'aa045bc.nc'), ext='.nc', OBSOLETE (replaced by 'netc_2D')
    4406 % Dti: ~=0 if i index pairs are used
    4407 % Dtj: ~=0 if i index pairs are used
    4408 
    4409 function NomTypeNc=nomtype2pair(NomTypeIma,mode)
    4410 
    4411 %determine nom_type_nc:
     3842% 'NomTypeIma': string defining the kind of nomenclature used for images
     3843
    44123844NomTypeNc=NomTypeIma;%default
    44133845switch mode
     
    44383870
    44393871function NomType_Callback(hObject, eventdata, handles)
    4440 % set(handles.RootPath,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
    4441 % RootPath=get(handles.RootPath,'String');
    4442 % RootFile=get(handles.RootFile,'String');
    4443 % ref_i=str2num(get(handles.ref_i,'String'));
    4444 % ref_j=str2num(get(handles.ref_j,'String'));
    4445 % NomType=get(handles.NomType,'String');
    4446 % ImaExt=get(handles.ImaExt,'String');
    4447 % fileinput=fullfile_uvmat(RootPath,'',RootFile,ImaExt,NomType,ref_i,[],ref_j);
    4448 % errormsg=display_file_name(handles,fileinput);
    4449 % if ~isempty(errormsg)
    4450 %     msgbox_uvmat('ERROR',errormsg)
    4451 % end
    4452 % set(handles.RootPath,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
     3872set(handles.RootPath,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
     3873RootPath=get(handles.RootPath,'String');
     3874RootFile=get(handles.RootFile,'String');
     3875ref_i=str2num(get(handles.ref_i,'String'));
     3876ref_j=str2num(get(handles.ref_j,'String'));
     3877NomType=get(handles.NomType,'String');
     3878ImaExt=get(handles.ImaExt,'String');
     3879fileinput=fullfile_uvmat(RootPath,'',RootFile,ImaExt,NomType,ref_i,[],ref_j);
     3880errormsg=display_file_name(handles,fileinput);
     3881if ~isempty(errormsg)
     3882    msgbox_uvmat('ERROR',errormsg)
     3883end
     3884set(handles.RootPath,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
    44533885
    44543886% --- Executes on selection change in ListProgram.
     
    44893921end
    44903922
     3923% --- Executes on button press in TestPatch1.
     3924function TestPatch1_Callback(hObject, eventdata, handles)
     3925set(handles.TestPatch1,'BackgroundColor',[1 1 0])
     3926drawnow
     3927if get(handles.TestPatch1,'Value')
     3928    ref_i=str2double(get(handles.ref_i,'String'));
     3929    if strcmp(get(handles.ref_j,'Visible'),'on')
     3930        ref_j=str2double(get(handles.ref_j,'String'));
     3931    else
     3932        ref_j=1;%default
     3933    end
     3934    filecell=set_civ_filenames(handles,ref_i,ref_j,[0 0 1 0 0 0]);   
     3935    Data.ListVarName={'ny','nx','A'};
     3936    Data.VarDimName= {'ny','nx',{'ny','nx'}};   
     3937    param_patch1=read_GUI(handles.Patch1);
     3938    param_patch1.CivFile=filecell.nc.civ1{1};
     3939    Param.Patch1=param_patch1;
     3940    for irho=1:7
     3941        [Data,errormsg]=civ_matlab(Param);% get the grid of x, y positions set for PIV
     3942        if ~isempty(errormsg)
     3943            msgbox_uvmat('ERROR',errormsg)
     3944            return
     3945        end
     3946        SmoothingParam(irho)=Param.Patch1.FieldSmooth;
     3947        Data.Civ1_U_Diff=Data.Civ1_U_Diff(Data.Civ1_FF==0);
     3948        Data.Civ1_V_Diff=Data.Civ1_V_Diff(Data.Civ1_FF==0);
     3949        DiffVel(irho)=sqrt(mean(Data.Civ1_U_Diff.*Data.Civ1_U_Diff+Data.Civ1_V_Diff.*Data.Civ1_V_Diff))
     3950        NbSites(irho,:)=Data.Civ1_NbSites*numel(Data.Civ1_NbSites)/numel(Data.Civ1_U_Diff);
     3951        Param.Patch1.SmoothingParam=2*Param.Patch1.FieldSmooth;
     3952    end
     3953    figure
     3954    plot(SmoothingParam,DiffVel,'b',SmoothingParam,NbSites,'r')
     3955    set(handles.TestPatch1,'BackgroundColor',[1 0 0])
     3956else
     3957    corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
     3958    if ~isempty(corrfig)
     3959        delete(corrfig)
     3960    end
     3961    hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
     3962    if ~isempty(hview_field)
     3963        delete(hview_field)
     3964    end
     3965end
     3966
    44913967
    44923968% --- Executes on button press in TestCiv2.
    44933969function TestCiv2_Callback(hObject, eventdata, handles)
    44943970
    4495 
    4496 
    44973971function RootFile_Callback(hObject, eventdata, handles)
    44983972
    4499 
    4500 
    45013973function SubdirImages_Callback(hObject, eventdata, handles)
     3974
     3975
     3976
     3977function errormsg=write_param(Param)
     3978%------------------------------------------------------------------------
     3979%pixels per cm and matrix of the image times, read from the .civ file by uvmat
     3980%changes : filename_cmx -> filename ( no extension )
     3981errormsg='';
     3982switch Param.CivMode
     3983    case 'CivX'
     3984        if Param.CheckCiv1
     3985            filename=regexprep(Param.OutputFile,'(\w+)([/\\])(\w+$)','$1$20_CMX$2$3.civ1.cmx');
     3986            if isequal(Param.Civ1.Dt,0)
     3987                Param.Civ1.Dt=1 ;%case of 'displacement' mode
     3988            end
     3989            Param.Civ1.ImageA=regexprep(Param.Civ1.ImageA,'.png','');
     3990            Param.Civ1.ImageB=regexprep(Param.Civ1.ImageB,'.png','');
     3991            [fid,errormsg]=fopen(filename,'w');
     3992            if isequal(fid,-1)
     3993                errormsg=['cmd file ' filename ' cannot be created: ' errormsg];
     3994                return
     3995            end
     3996            fprintf(fid,['##############   CMX file' '\n' ]);
     3997            fprintf(fid,   ['FirstImage ' regexprep(Param.Civ1.ImageA,'\\','\\\\') '\n' ]);% for windows compatibility
     3998            fprintf(fid,   ['LastImage  ' regexprep(Param.Civ1.ImageB,'\\','\\\\') '\n' ]);% for windows compatibility
     3999            fprintf(fid,  ['XX' '\n' ]);
     4000            if isfield(Param.Civ1,'Mask')
     4001                fprintf(fid,  ['Mask ' 'y' '\n' ]);
     4002                fprintf(fid,  ['MaskName ' regexprep(Param.Civ1.Mask,'\\','\\\\') '\n' ]);
     4003            else
     4004                fprintf(fid,  ['Mask ' 'n' '\n' ]);
     4005                fprintf(fid,  ['MaskName ' 'noFile use default' '\n' ]);
     4006            end
     4007            fprintf(fid,   ['ImageSize ' num2str(Param.Civ1.ImageWidth) ' ' num2str(Param.Civ1.ImageHeight) '\n' ]);   %VERIFIER CAS GENERAL ?
     4008            fprintf(fid,   ['CorrelationBoxesSize ' num2str(Param.Civ1.CorrBoxSize(1)) ' ' num2str(Param.Civ1.CorrBoxSize(2)) '\n' ]);
     4009            fprintf(fid,   ['SearchBoxeSize ' num2str(Param.Civ1.SearchBoxSize(1)) ' ' num2str(Param.Civ1.SearchBoxSize(2)) '\n' ]);
     4010            fprintf(fid,   ['RO ' num2str(Param.Civ1.CorrSmooth) '\n' ]);
     4011            if isfield(Param.Civ1,'Grid')
     4012                fprintf(fid,   ['GridSpacing ' '25' ' ' '25' '\n' ]);
     4013            else
     4014                fprintf(fid,   ['GridSpacing ' num2str(Param.Civ1.Dx) ' ' num2str(Param.Civ1.Dy) '\n' ]);
     4015            end
     4016            fprintf(fid,   ['XX 1.0' '\n' ]);
     4017            fprintf(fid,   ['Dt_TO ' num2str(Param.Civ1.Dt) ' ' num2str(Param.Civ1.Time) '\n' ]);
     4018            fprintf(fid,  ['PixCmXY ' '1' ' ' '1' '\n' ]);
     4019            fprintf(fid,  ['XX 1' '\n' ]);
     4020            fprintf(fid,   ['ShiftXY ' num2str(Param.Civ1.SearchBoxShift(1)) ' '  num2str(Param.Civ1.SearchBoxShift(2)) '\n' ]);
     4021            if isfield(Param.Civ1,'Grid')
     4022                fprintf(fid,  ['Grid ' 'y' '\n' ]);
     4023                fprintf(fid,   ['GridName ' regexprep(Param.Civ1.Grid,'\\','\\\\') '\n' ]);
     4024            else
     4025                fprintf(fid,  ['Grid ' 'n' '\n' ]);
     4026                fprintf(fid,   ['GridName ' 'noFile use default' '\n' ]);
     4027            end
     4028            fprintf(fid,   ['XX 85' '\n' ]);
     4029            fprintf(fid,   ['XX 1.0' '\n' ]);
     4030            fprintf(fid,   ['XX 1.0' '\n' ]);
     4031            fprintf(fid,   ['Hart 1' '\n' ]);
     4032            fprintf(fid,  [ 'DecimalShift 0' '\n' ]);
     4033            fprintf(fid,   ['Deformation 0' '\n' ]);
     4034            fprintf(fid,  ['CorrelationMin 0' '\n' ]);
     4035            fprintf(fid,   ['IntensityMin 0' '\n' ]);
     4036            if ~isfield(Param.Civ1,'MinIma')% Image threshold not activated
     4037                fprintf(fid,  ['SeuilImage n' '\n' ]);
     4038                fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);%not used in principle
     4039            else% Image threshold  activated
     4040                if isempty(Param.Civ1.MaxIma)||isnan(Param.Civ1.MaxIma)
     4041                    Param.Civ1.MaxIma=2^Param.Civ1.ImageBitDepth;%take the max image value as upper bound by default
     4042                end
     4043                fprintf(fid,  ['SeuilImage y' '\n' ]);
     4044                fprintf(fid,   ['SeuilImageValues ' num2str(Param.Civ1.MinIma) ' ' num2str(Param.Civ1.MaxIma) '\n' ]);
     4045            end
     4046            fprintf(fid,   ['ImageToUse ' Param.Civ1.term_a ' ' Param.Civ1.term_b '\n' ]); % VERIFIER ?
     4047            fprintf(fid,   ['ImageUsedBefore null null' '\n' ]);
     4048            fclose(fid);
     4049        end
     4050       
     4051        if Param.CheckCiv2
     4052            filename=regexprep(Param.OutputFile,'(\w+)([/\\])(\w+$)','$1$20_CMX$2$3.civ2.cmx');
     4053
     4054            if isequal(Param.Civ2.Dt,'0')
     4055                Param.Civ2.Dt='1' ;%case of 'displacement' mode
     4056            end
     4057            Param.Civ2.ImageA=regexprep(Param.Civ2.ImageA,'.png','');
     4058            Param.Civ2.ImageB=regexprep(Param.Civ2.ImageB,'.png','');% bug : .png appears two times ?
     4059            [fid,errormsg]=fopen(filename,'w');
     4060            if isequal(fid,-1)
     4061                return
     4062            end
     4063            fprintf(fid,['##############   CMX file' '\n' ]);
     4064            fprintf(fid,   ['FirstImage ' regexprep(Param.Civ2.ImageA,'\\','\\\\') '\n' ]);% for windows compatibility
     4065            fprintf(fid,   ['LastImage  ' regexprep(Param.Civ2.ImageB,'\\','\\\\') '\n' ]);% for windows compatibility
     4066            fprintf(fid,  ['XX' '\n' ]);
     4067            if isfield(Param.Civ2,'Mask')
     4068                fprintf(fid,  ['Mask ' 'y' '\n' ]);
     4069                fprintf(fid,  ['MaskName ' regexprep(Param.Civ2.Mask,'\\','\\\\') '\n' ]);
     4070            else
     4071                fprintf(fid,  ['Mask ' 'n' '\n' ]);
     4072                fprintf(fid,  ['MaskName ' 'noFile use default' '\n' ]);
     4073            end
     4074            % fprintf(fid, ['Mask ' Param.Civ2.MaskFlag '\n' ]);
     4075            % fprintf(fid, ['MaskName ' regexprep(Param.Civ2.MaskName,'\\','\\\\') '\n' ]);% for windows compatibility
     4076            fprintf(fid,   ['ImageSize ' num2str(Param.Civ2.ImageWidth) ' ' num2str(Param.Civ2.ImageHeight) '\n' ]);
     4077            % fprintf(fid, ['ImageSize ' num2str(Param.Civ2.npx) ' ' num2str(Param.Civ2.npy) '\n' ]);   %VERIFIER CAS GENERAL ?
     4078            fprintf(fid, ['CorrelationBoxesSize ' num2str(Param.Civ2.CorrBoxSize(1)) ' ' num2str(Param.Civ2.CorrBoxSize(2)) '\n' ]);
     4079            fprintf(fid, ['SearchBoxeSize ' num2str(Param.Civ2.CorrBoxSize(1)) ' ' num2str(Param.Civ2.CorrBoxSize(2)) '\n']);
     4080            fprintf(fid, ['RO ' num2str(Param.Civ2.CorrSmooth) '\n']);
     4081            if isfield(Param.Civ2,'Grid')
     4082                fprintf(fid,   ['GridSpacing ' '25' ' ' '25' '\n' ]);
     4083            else
     4084                fprintf(fid,   ['GridSpacing ' num2str(Param.Civ2.Dx) ' ' num2str(Param.Civ2.Dy) '\n' ]);
     4085            end
     4086            % fprintf(fid, ['GridSpacing ' num2str(Param.Civ2.Dx) ' ' num2str(Param.Civ2.Dy) '\n']);
     4087            fprintf(fid, ['XX 1.0' '\n' ]);
     4088            fprintf(fid, ['Dt_TO ' num2str(Param.Civ2.Dt) ' ' num2str(Param.Civ2.Time) '\n' ]);
     4089            fprintf(fid, ['PixCmXY ' '1' ' ' '1' '\n' ]);
     4090            fprintf(fid, ['XX 1' '\n' ]);
     4091            fprintf(fid, 'ShiftXY 0 0\n');
     4092            if isfield(Param.Civ2,'Grid')
     4093                fprintf(fid,  ['Grid ' 'y' '\n' ]);
     4094                fprintf(fid,   ['GridName ' regexprep(Param.Civ2.Grid,'\\','\\\\') '\n' ]);
     4095            else
     4096                fprintf(fid,  ['Grid ' 'n' '\n' ]);
     4097                fprintf(fid,   ['GridName ' 'noFile use default' '\n' ]);
     4098            end
     4099            % fprintf(fid, ['Grid ' Param.Civ2.GridFlag '\n' ]);
     4100            % fprintf(fid, ['GridName ' regexprep(Param.Civ2.GridName,'\\','\\\\') '\n']);
     4101            fprintf(fid, ['XX 85' '\n' ]);
     4102            fprintf(fid, ['XX 1.0' '\n' ]);
     4103            fprintf(fid, ['XX 1.0' '\n' ]);
     4104            fprintf(fid, ['Hart 1' '\n' ]);
     4105            fprintf(fid, ['DecimalShift ' num2str(Param.Civ2.CheckDecimal) '\n']);
     4106            fprintf(fid, ['Deformation ' num2str(Param.Civ2.CheckDeformation) '\n']);
     4107            fprintf(fid,  ['CorrelationMin 0' '\n' ]);
     4108            fprintf(fid,   ['IntensityMin 0' '\n' ]);
     4109           
     4110            if ~isfield(Param.Civ2,'MinIma')% Image threshold not activated
     4111                fprintf(fid,  ['SeuilImage n' '\n' ]);
     4112                fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);%not used in principle
     4113            else% Image threshold  activated
     4114                if isempty(Param.Civ2.MaxIma)||isnan(Param.Civ2.MaxIma)
     4115                    Param.Civ2.MaxIma=2^Param.Civ2.ImageBitDepth;%take the max image value as upper bound by default
     4116                end
     4117                fprintf(fid,  ['SeuilImage y' '\n' ]);
     4118                fprintf(fid,   ['SeuilImageValues ' num2str(Param.Civ2.MinIma) ' ' num2str(Param.Civ2.MaxIma) '\n' ]);
     4119            end
     4120            fprintf(fid,   ['ImageToUse ' Param.Civ2.term_a ' ' Param.Civ2.term_b '\n' ]); % VERIFIER ?
     4121            fprintf(fid, ['ImageUsedBefore ' regexprep(Param.Civ2.filename_nc1,'\\','\\\\') '\n']);
     4122            fclose(fid);
     4123        end
     4124    case 'Matlab'
     4125        filename=regexprep(Param.OutputFile,'(\w+)([/\\])(\w+$)','$1$20_XML$2$3.xml');
     4126        save(struct2xml(Param),filename);
     4127end
     4128
     4129
     4130function cmd=write_cmd(Param,batch)
     4131
     4132% initiate system command
     4133cmd=[];
     4134
     4135switch Param.CivMode
     4136    case 'CivX'
     4137        if isunix % check: necessaire aussi en RUN?
     4138            cmd=[cmd '#!/bin/bash \n '...
     4139                '#$ -cwd \n '...
     4140                'hostname && date \n '...
     4141                'umask 002 \n'];%allow writting access to created files for user group
     4142        end
     4143    case 'CivAll'
     4144        if isunix % check: necessaire aussi en RUN?
     4145            cmd=[cmd '#!/bin/bash \n '...
     4146                '#$ -cwd \n '...
     4147                'hostname && date \n '...
     4148                'umask 002 \n'];%allow writting access to created files for user group
     4149        end
     4150end
     4151
     4152filename=regexprep(Param.OutputFile,'.nc','');
     4153
     4154if Param.CheckCiv1
     4155    switch Param.CivMode
     4156        case 'CivX'
     4157            if(isunix) %unix (or Mac) system
     4158                cmd=[cmd 'cp -f ' regexprep(filename,'(\w+)/(\w+$)','$1/0_CMX/$2.civ1.cmx ') regexprep(filename,'(\w+)/(\w+$)','$1/$2.cmx \n')...% the cmx file gives the name to the nc file
     4159                    Param.xml.Civ1Bin ' -f ' regexprep(filename,'(\w+)/(\w+$)','$1/$2.cmx >') regexprep(filename,'(\w+)/(\w+$)','$1/0_LOG/$2.civ1.log \n')... % redirect standard output to the log file, the result file is named [filename '.nc'] by CIVx
     4160                    'rm ' regexprep(filename,'(\w+)/(\w+$)','$1/$2.cmx \n')];
     4161            else %Windows system
     4162                filename=regexprep(filename,'\\','\\\\');
     4163                cmd=['copy /Y ' regexprep(filename,'(\w+)\\\\(\w+$)','"$1\\\\0_CMX\\\\$2.civ1.cmx" ') regexprep(filename,'(\w+)\\\\(\w+$)','"$1\\\\$2.civ1.cmx" \n')...
     4164                    '"' regexprep(Param.xml.Civ1Bin,'\\','\\\\') '" -f ' regexprep(filename,'(\w+)\\\\(\w+$)','"$1\\\\$2.cmx" > ')...
     4165                    regexprep(filename,'(\w+)\\\\(\w+$)','"$1\\\\0_LOG\\\\$2.civ1.log" \n')... % redirect standard output to the log file
     4166                    'del ' regexprep(filename,'(\w+)\\\\(\w+$)','"$1\\\\$2.cmx" \n')];
     4167            end
     4168        case 'CivAll'
     4169            CivAllCmd=[CivAllCmd ' civ1 '];
     4170            str=CIV1_CMD_Unified(filecell.nc.civ1{ifile,j},'',Param.Civ1);
     4171            fieldnames=fields(str);
     4172            [CivAllxml,uid_civ1]=add(CivAllxml,1,'element','civ1');
     4173            for ilist=1:length(fieldnames)
     4174                val=eval(['str.' fieldnames{ilist}]);
     4175                if ischar(val)
     4176                    [CivAllxml,uid_t]=add(CivAllxml,uid_civ1,'element',fieldnames{ilist});
     4177                    [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
     4178                end
     4179            end
     4180    end
     4181end
     4182
     4183if Param.CheckFix1
     4184    switch Param.CivMode
     4185        case 'CivX'
     4186            cmd=[cmd...
     4187                cmd_fix(Param,'Fix1') '\n'];
     4188        case 'CivAll'%to abandon
     4189            fix1.inputFileName=filecell.nc.civ1{ifile,j} ;
     4190            fix1.fi1=num2str(param.fix1.flagindex1(1));
     4191            fix1.fi2=num2str(param.fix1.flagindex1(2));
     4192            fix1.fi3=num2str(param.fix1.flagindex1(3));
     4193            fix1.threshC=num2str(param.fix1.thresh_vecC1);
     4194            fix1.threshV=num2str(param.fix1.thresh_vel1);
     4195            fieldnames=fields(fix1);
     4196            [CivAllxml,uid_fix1]=add(CivAllxml,1,'element','fix1');
     4197            for ilist=1:length(fieldnames)
     4198                val=eval(['fix1.' fieldnames{ilist}]);
     4199                if ischar(val)
     4200                    [CivAllxml,uid_t]=add(CivAllxml,uid_fix1,'element',fieldnames{ilist});
     4201                    [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
     4202                end
     4203            end
     4204            CivAllCmd=[CivAllCmd ' fix1 '];
     4205    end
     4206end
     4207
     4208
     4209%CheckPatch1
     4210if Param.CheckPatch1
     4211    switch Param.CivMode
     4212        case 'CivX'
     4213            cmd=[cmd...
     4214                cmd_patch(Param,'Patch1') '\n'];
     4215        case 'CivAll'
     4216            patch1.inputFileName=filecell.nc.civ1{ifile,j} ;
     4217            patch1.nopt=subdomain_patch1;
     4218            patch1.maxdiff=thresh_patch1;
     4219            patch1.ro=rho_patch1;
     4220            test_grid=get(handles.get_gridpatch1,'Value');
     4221            if test_grid
     4222                patch1.gridflag='y';
     4223                gridname=get(handles.grid_patch1,'String');
     4224                if isequal(gridname(end-3:end),'grid')
     4225                    nbslice_grid=str2double(gridname(1:end-4)); %
     4226                    if ~isnan(nbslice_grid)
     4227                        i1_grid=mod(i1_civ1(ifile)-1,nbslice_grid)+1;
     4228                        patch1.gridPatch=[filecell.filebase '_' fullfile_uvmat('','',gridname,'.grid','_1',i1_grid)];
     4229                        %                                 patch1.gridPatch=[filecell.filebase '_' name_generator(gridname,i1_grid,1,'.grid','_i')];
     4230                        if ~exist(patch1.gridPatch,'file')
     4231                            errormsg='grid file absent for patch1';
     4232                            return
     4233                        end
     4234                    elseif exist(gridname,'file')
     4235                        patch1.gridPatch=gridname;
     4236                    else
     4237                        errormsg='grid file absent for patch1';
     4238                        return
     4239                    end
     4240                end
     4241            else
     4242                patch1.gridPatch='none';
     4243                patch1.gridflag='n';
     4244                patch1.m=nx_patch1;
     4245                patch1.n=ny_patch1;
     4246            end
     4247            patch1.convectFlow='n';
     4248            fieldnames=fields(patch1);
     4249            [CivAllxml,uid_patch1]=add(CivAllxml,1,'element','patch1');
     4250            for ilist=1:length(fieldnames)
     4251                val=eval(['patch1.' fieldnames{ilist}]);
     4252                if ischar(val)
     4253                    [CivAllxml,uid_t]=add(CivAllxml,uid_patch1,'element',fieldnames{ilist});
     4254                    [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
     4255                end
     4256            end
     4257            CivAllCmd=[CivAllCmd ' patch1 '];
     4258    end
     4259end
     4260
     4261if Param.CheckCiv2
     4262    switch Param.CivMode
     4263        case 'CivX'
     4264            if(isunix)
     4265                cmd=[cmd 'cp -f '  regexprep(filename,'(\w+)/(\w+$)','$1/0_CMX/$2.civ2.cmx ') regexprep(filename,'(\w+)/(\w+$)','$1/$2.cmx \n')...
     4266                    Param.xml.Civ2Bin ' -f ' regexprep(filename,'(\w+)/(\w+$)','$1/$2.cmx >') regexprep(filename,'(\w+)/(\w+$)','$1/0_LOG/$2.civ2.log \n')...% redirect standard output to the log file, the result file is named [filename '.nc'] by CIVx
     4267                    'rm ' regexprep(filename,'(\w+)/(\w+$)','$1/$2.cmx \n')];%rename .cmx as .checkciv2.cmx, the result file is named [filename '.nc'] by CIVx
     4268            else
     4269                filename=regexprep(filename,'\\','\\\\');
     4270                cmd=[cmd 'copy /Y ' regexprep(filename,'(\w+)\\\\(\w+$)','"$1\\\\0_CMX\\\\$2.civ2.cmx" ') regexprep(filename,'(\w+)\\\\(\w+$)','"$1\\\\$2.cmx" \n')...
     4271                    '"' regexprep(Param.xml.Civ2Bin,'\\','\\\\') '" -f "' regexprep(filename,'(\w+)\\\\(\w+$)','"$1\\\\$2.cmx" > ')...
     4272                     regexprep(filename,'(\w+)\\\\(\w+$)','"$1\\\\0_LOG\\\\$2.civ2.log" \n')... % redirect standard output to the log file
     4273                    'del ' regexprep(filename,'(\w+)\\\\(\w+$)','"$1\\\\$2.cmx" \n')];
     4274            end
     4275        case 'CivAll'
     4276            CivAllCmd=[CivAllCmd ' civ2 '];
     4277            str=CIV2_CMD_Unified(filecell.nc.civ2{ifile,j},'',Param.Civ2);
     4278            fieldnames=fields(str);
     4279            [CivAllxml,uid_civ2]=add(CivAllxml,1,'element','civ2');
     4280            for ilist=1:length(fieldnames)
     4281                val=eval(['str.' fieldnames{ilist}]);
     4282                if ischar(val)
     4283                    [CivAllxml,uid_t]=add(CivAllxml,uid_civ2,'element',fieldnames{ilist});
     4284                    [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
     4285                end
     4286            end
     4287    end
     4288end
     4289
     4290% CheckFix2
     4291if Param.CheckFix2==1
     4292    switch Param.CivMode
     4293        case 'CivX'
     4294            cmd=[cmd...
     4295                cmd_fix(Param,'Fix2') '\n'];
     4296        case 'CivAll'
     4297            fix2.inputFileName=filecell.nc.civ2{ifile,j} ;
     4298            fix2.fi1=num2str(flagindex2(1));
     4299            fix2.fi2=num2str(flagindex2(2));
     4300            fix2.fi3=num2str(flagindex2(3));
     4301            fix2.threshC=num2str(thresh_vec2C);
     4302            fix2.threshV=num2str(thresh_vel2);
     4303            fieldnames=fields(fix2);
     4304            [CivAllxml,uid_fix2]=add(CivAllxml,1,'element','fix2');
     4305            for ilist=1:length(fieldnames)
     4306                val=eval(['fix2.' fieldnames{ilist}]);
     4307                if ischar(val)
     4308                    [CivAllxml,uid_t]=add(CivAllxml,uid_fix2,'element',fieldnames{ilist});
     4309                    [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
     4310                end
     4311            end
     4312            CivAllCmd=[CivAllCmd ' fix2 '];
     4313    end
     4314end
     4315
     4316%CheckPatch2
     4317if Param.CheckPatch2==1
     4318   
     4319    switch Param.CivMode
     4320       
     4321        case 'CivX'
     4322            cmd=[cmd...
     4323                cmd_patch(Param,'Patch2') '\n'];
     4324        case 'CivAll'
     4325            patch2.inputFileName=filecell.nc.civ1{ifile,j} ;
     4326            patch2.nopt=subdomain_patch2;
     4327            patch2.maxdiff=thresh_patch2;
     4328            patch2.ro=rho_patch2;
     4329            test_grid=get(handles.get_gridpatch2,'Value');
     4330            if test_grid
     4331                patch2.gridflag='y';
     4332                gridname=get(handles.grid_patch2,'String');
     4333                if isequal(gridname(end-3:end),'grid')
     4334                    nbslice_grid=str2double(gridname(1:end-4)); %
     4335                    if ~isnan(nbslice_grid)
     4336                        i1_grid=mod(i1_civ2(ifile)-1,nbslice_grid)+1;
     4337                        patch2.gridPatch=[filecell.filebase '_' fullfile_uvmat('','',gridname,'.grid','_1',i1_grid)];
     4338                        %                                 patch2.gridPatch=[filecell.filebase '_' name_generator(gridname,i1_grid,1,'.grid','_i')];
     4339                        if ~exist(patch2.gridPatch,'file')
     4340                            errormsg='grid file absent for patch2';
     4341                            return
     4342                        end
     4343                    elseif exist(gridname,'file')
     4344                        patch2.gridPatch=gridname;
     4345                    else
     4346                        errormsg='grid file absent for patch2';
     4347                        return
     4348                    end
     4349                end
     4350            else
     4351                patch2.gridPatch='none';
     4352                patch2.gridflag='n';
     4353                patch2.m=nx_patch2;
     4354                patch2.n=ny_patch2;
     4355            end
     4356            patch2.convectFlow='n';
     4357            fieldnames=fields(patch2);
     4358            [CivAllxml,uid_patch2]=add(CivAllxml,1,'element','patch2');
     4359            for ilist=1:length(fieldnames)
     4360                val=eval(['patch2.' fieldnames{ilist}]);
     4361                if ischar(val)
     4362                    [CivAllxml,uid_t]=add(CivAllxml,uid_patch2,'element',fieldnames{ilist});
     4363                    [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
     4364                end
     4365            end
     4366            CivAllCmd=[CivAllCmd ' patch2 '];
     4367    end
     4368end
     4369
     4370if isequal(Param.CivMode,'CivAll')
     4371    save(CivAllxml,[Param.OutputFile '.xml']);
     4372    cmd=[cmd sparam.CivBin ' -f ' Param.OutputFile '.xml '  CivAllCmd ' >' Param.OutputFile '.log' '\n'];
     4373end
     4374
     4375if isequal(Param.CivMode,'Matlab')
     4376    if batch
     4377        cmd=['#!/bin/bash \n '...
     4378            '#$ -cwd \n '...
     4379            'hostname && date \n '...
     4380            'umask 002 \n'...
     4381            Param.xml.CivmBin ' ' Param.xml.RunTime ' ' filename_xml ' ' Param.OutputFile '.nc'];%allow writting access to created files for user group
     4382       
     4383        fprintf(fid,cmd);
     4384        fclose(fid);
     4385        if isunix
     4386            system(['chmod +x ' filename_bat]);
     4387        end
     4388        batch_file_list{length(batch_file_list)+1}=filename_bat;
     4389    else
     4390        cmd=['civ_matlab(''' regexprep(filename,'(\w+)([/\\])(\w+$)','$1$20_XML$2$3.xml') ''','''...
     4391            filename '.nc'');']
     4392%         [tild,errormsg]=civ_matlab(Param,filecell.nc.civ1{ifile,j});
     4393    end
     4394end
     4395   
     4396
     4397if isequal(Param.CivMode,'MatlabCompile')
     4398        cmd=['#!/bin/bash \n '...
     4399            '#$ -cwd \n '...
     4400            'hostname && date \n '...
     4401            'umask 002 \n'...
     4402            Param.xml.CivmBin ' ' Param.xml.RunTime ' ' filename_xml ' ' Param.OutputFile '.nc'];%allow writting access to created files for user group
     4403end
     4404
     4405
     4406if isequal(Param.CivMode,'MatlabNonCompile')
     4407%         cmd=[regexprep(which(civ_matlab),'.m$','')...
     4408%             '(' regexprep(filename,'(\w+)/(\w+$)','$1/0_XML$2.xml,')...
     4409%             filename '.nc);'];
     4410%         [tild,errormsg]=civ_matlab(Param,filecell.nc.civ1{ifile,j});
     4411end
     4412
     4413
     4414
     4415   
     4416   
     4417
     4418function cmd=cmd_fix(Param,fixname)
     4419%%
     4420switch fixname
     4421    case 'Fix1'
     4422        fi2_value=num2str(Param.(fixname).CheckF2);
     4423        filename=regexprep(Param.OutputFile,'.nc','');
     4424    case 'Fix2'
     4425        fi2_value=num2str(Param.(fixname).CheckF4);%need to understand why...
     4426        filename=regexprep(Param.OutputFile,'.nc','');       
     4427end
     4428
     4429% filename=regexprep(Param.(fixname).OutFileName,'.nc','');
     4430MaskName_string='';%default
     4431MaxVel_string='';%default
     4432if ~isempty(Param.(fixname).MinVel)
     4433    MaxVel_string=[' -threshV ' num2str(Param.(fixname).MinVel)];
     4434end
     4435if isunix
     4436    cmd=[Param.xml.FixBin ' -f ' filename '.nc -fi1 ' num2str(Param.(fixname).CheckFmin2) ...
     4437        ' -fi2 ' fi2_value ' -fi3 ' num2str(Param.(fixname).CheckF3) ...
     4438        ' -threshC ' num2str(Param.(fixname).MinCorr) MaxVel_string MaskName_string...
     4439        ' >' regexprep(filename,'(\w+)/(\w+$)','$1/0_LOG/$2.')  lower(fixname) '.log 2>&1'];
     4440else
     4441    cmd=['"' Param.xml.FixBin '" -f "' filename '.nc" -fi1 ' num2str(Param.(fixname).CheckFmin2)...
     4442        ' -fi2 ' fi2_value ' -fi3 ' num2str(Param.(fixname).CheckF3) ...
     4443        ' -threshC ' num2str(Param.(fixname).MinCorr) MaxVel_string MaskName_string...
     4444        ' > "' regexprep(filename,'(\w+)\\(\w+$)','$1\\0_LOG\\$2.') lower(fixname) '.log"'];
     4445    cmd=regexprep(cmd,'\\','\\\\');
     4446end
     4447
     4448
     4449function cmd=cmd_patch(Param,patchname)
     4450%% ------------------------------------------------------------------------
     4451switch patchname
     4452    case 'Patch1'
     4453        filename=regexprep(Param.OutputFile,'.nc','');
     4454    case 'Patch2'
     4455        filename=regexprep(Param.OutputFile,'.nc','');       
     4456end
     4457% filename=regexprep(Param.(patchname).OutFileName,'.nc','');
     4458if isunix
     4459    cmd=[Param.xml.PatchBin...
     4460        ' -f ' filename '.nc -m ' num2str(Param.(patchname).Nx)...
     4461        ' -n ' num2str(Param.(patchname).Ny) ' -ro ' num2str(Param.(patchname).FieldSmooth)...
     4462        ' -nopt ' num2str(Param.(patchname).SubdomainSize) ...
     4463        '  > ' regexprep(filename,'(\w+)/(\w+$)','$1/0_LOG/$2.')  lower(patchname) '.log 2>&1']; % redirect standard output to the log file
     4464else
     4465    cmd=['"' Param.xml.PatchBin...
     4466        '" -f "' filename '.nc" -m ' num2str(Param.(patchname).Nx)...
     4467        ' -n ' num2str(Param.(patchname).Ny) ' -ro ' num2str(Param.(patchname).FieldSmooth)...
     4468        ' -nopt ' num2str(Param.(patchname).SubdomainSize)...
     4469        '  > "' filename '.' lower(patchname) '.log" 2>&1']; % redirect standard output to the log file
     4470    cmd=regexprep(cmd,'\\','\\\\');
     4471end
     4472
     4473
     4474
     4475
     4476%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     4477% USELESS FUNCTIONS BELOW HERE,  TO CLEAN
     4478%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     4479
     4480
     4481
     4482
     4483
     4484%------------------------------------------------------------------------
     4485% --- CheckCiv1  Unified: TO ABADON
     4486function xml_civ1_parameters=CIV1_CMD_Unified(filename,namelog,par)
     4487%------------------------------------------------------------------------
     4488%pixels per cm and matrix of the image times, read from the .civ file by uvmat
     4489%global CivBin%name of the executable for checkciv1 calculation
     4490
     4491civ1.image1=par.ImageA;
     4492civ1.image2=par.ImageB;
     4493civ1.imageSize_X=par.npx;
     4494civ1.imageSize_Y=par.npy;
     4495civ1.outputFileName=[filename '.nc'];
     4496civ1.correlationBoxesSize_X=par.ibx;
     4497civ1.correlationBoxesSize_Y=par.iby;
     4498civ1.searchBoxesSize_X=par.isx;
     4499civ1.searchBoxesSize_Y=par.isy;
     4500civ1.globalShift_X=par.shiftx;
     4501civ1.globalShift_Y=par.shifty;
     4502civ1.ro=par.rho;
     4503civ1.hart='y';
     4504if isequal(par.gridflag,'y')
     4505    civ1.grid=par.gridname;
     4506else
     4507    civ1.grid='n';
     4508    civ1.gridSpacing_X=par.dx;
     4509    civ1.gridSpacing_Y=par.dy;
     4510end
     4511if isequal(par.maskflag,'y')
     4512    civ1.mask=par.maskname;
     4513end
     4514civ1.dt=par.Dt;
     4515civ1.unit='pixel';
     4516civ1.absolut_time_T0=par.Time;
     4517civ1.pixcmx='1';
     4518civ1.pixcmy='1';
     4519civ1.convectFlow='n';
     4520
     4521xml_civ1_parameters=civ1;
     4522
     4523%------------------------------------------------------------------------
     4524% --- CheckCiv2  Unified: TO ABADON
     4525function civ2=CIV2_CMD_Unified(filename,namelog,par)
     4526%------------------------------------------------------------------------
     4527%pixels per cm and matrix of the image times, read from the .civ file by uvmat
     4528%global CivBin%name of the executable for checkciv1 calculation
     4529
     4530filename=regexprep(filename,'.nc','');
     4531
     4532civ2.image1=par.ImageA;
     4533civ2.image2=par.ImageB;
     4534civ2.imageSize_X=par.npx;
     4535civ2.imageSize_Y=par.npy;
     4536civ2.inputFileName=[par.filename_nc1 '.nc'];
     4537civ2.outputFileName=[filename '.nc'];
     4538civ2.correlationBoxesSize_X=par.ibx;
     4539civ2.correlationBoxesSize_Y=par.iby;
     4540civ2.ro=par.rho;
     4541%checkciv2.decimalShift=par.CheckDecimal;
     4542%checkciv2.CheckDeformation=par.CheckDeformation;
     4543if isequal(par.decimal,'1')
     4544    civ2.decimalShift='y';
     4545else
     4546    civ2.decimalShift='n';
     4547end
     4548if isequal(par.deformation,'1')
     4549    civ2.deformation='y';
     4550else
     4551    civ2.deformation='n';
     4552end
     4553if isequal(par.gridflag,'y')
     4554    civ2.grid=par.gridname;
     4555else
     4556    civ2.grid='n';
     4557    civ2.gridSpacing_X=par.dx;
     4558    civ2.gridSpacing_Y=par.dy;
     4559end
     4560civ2.gridSpacing_X='10';
     4561civ2.gridSpacing_Y='10';%NOTE: faut mettre gridSpacing pourque ca tourne, meme si c'est la grille qui est utilisee
     4562if isequal(par.maskflag,'y')
     4563    civ2.mask=par.maskname;
     4564else
     4565    civ2.mask='n';
     4566end
     4567civ2.dt=par.Dt;
     4568civ2.unit='pixel';
     4569civ2.absolut_time_T0=par.Time;
     4570civ2.pixcmx='1';
     4571civ2.pixcmy='1';
     4572civ2.convectFlow='n';
     4573
     4574
     4575
Note: See TracChangeset for help on using the changeset viewer.