Changeset 635 for trunk/src/series.m
- Timestamp:
- May 19, 2013, 11:37:49 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/series.m
r630 r635 524 524 InputTable(iview,:)=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}]; 525 525 set(handles.TimeTable,'Data',[{[]},{[]},{[]},{[]}]) 526 set(handles.MinIndex_i,'Data',[ {[]}])527 set(handles.MaxIndex_i,'Data',[ {[]}])528 set(handles.MinIndex_j,'Data',[ {[]}])529 set(handles.MaxIndex_j,'Data',[ {[]}])526 set(handles.MinIndex_i,'Data',[]) 527 set(handles.MaxIndex_i,'Data',[]) 528 set(handles.MinIndex_j,'Data',[]) 529 set(handles.MaxIndex_j,'Data',[]) 530 530 set(handles.ListView,'Value',1) 531 531 set(handles.ListView,'String',{'1'}) … … 606 606 MinIndex_j=1;% index j set to 1 by default 607 607 MaxIndex_j=1; 608 MinIndex_i=find(i1_series( :,2,:), 1 )-1;% min ref index i detected in the series (corresponding to the first non-zero value of i1_series, except for zero index)609 MaxIndex_i=find(i1_series( :,2,:), 1,'last' )-1;%max ref index i detected in the series (corresponding to the last non-zero value of i1_series)608 MinIndex_i=find(i1_series(1,2,:), 1 )-1;% min ref index i detected in the series (corresponding to the first non-zero value of i1_series, except for zero index) 609 MaxIndex_i=find(i1_series(1,2,:),1,'last' )-1;%max ref index i detected in the series (corresponding to the last non-zero value of i1_series) 610 610 else 611 pair_max=squeeze(max(i1_series,[],1)); %max on pair index 612 j_max=max(pair_max,[],1); 613 MinIndex_i=find(j_max, 1 )-1;% min ref index i detected in the series (corresponding to the first non-zero value of i1_series, except for zero index) 614 MaxIndex_i=find(j_max, 1, 'last' )-1;% max ref index i detected in the series (corresponding to the first non-zero value of i1_series, except for zero index) 615 diff_i_max=diff(j_max); 611 ref_i=squeeze(max(i1_series(1,:,:),[],2));% select ref_j index for each ref_i 612 ref_j=squeeze(max(j1_series(1,:,:),[],3));% select ref_i index for each ref_j 613 % [ref_j,ref_i]=find(squeeze(i1_series(1,:,:))); 614 % [ref_j,ref_i]=find(squeeze(i1_series(1,:,:))) 615 MinIndex_i=min(find(ref_i))-1; 616 MaxIndex_i=max(find(ref_i))-1; 617 % MinIndex_j=min(ref_j)-1; 618 MaxIndex_j=max(find(ref_j))-1; 619 % MinIndex_j=min(find(j1_series_j))-1; 620 % MaxIndex_j=max(find(j1_series_j))-1; 621 % MaxIndex_i=max(i1_series_i)-1; 622 % MinIndex_j=min(i1_series_j)-1; 623 % MaxIndex_j=max(i1_series_j)-1; 624 % MaxIndex_i=max(ref_i)-1; 625 MinIndex_j=min(find(ref_j))-1; 626 % MaxIndex_j=max(ref_j)-1; 627 diff_j_max=diff(ref_j); 628 diff_i_max=diff(ref_i); 629 630 % pair_max=squeeze(max(i1_series,[],1)); %max on pair index 631 % j_max=max(pair_max,[],1); 632 % MinIndex_i=find(j_max, 1 )-1;% min ref index i detected in the series (corresponding to the first non-zero value of i1_series, except for zero index) 633 % MaxIndex_i=find(j_max, 1, 'last' )-1;% max ref index i detected in the series (corresponding to the first non-zero value of i1_series, except for zero index) 634 % diff_i_max=diff(j_max); 616 635 if ~isempty(diff_i_max) && isequal (diff_i_max,diff_i_max(1)*ones(size(diff_i_max))) 617 636 set(handles.num_incr_i,'String',num2str(diff_i_max(1)))% detect an increment to dispaly by default 618 637 end 619 i_max=max(pair_max,[],2);620 MinIndex_j=min(find(i_max))-1;% min ref index j621 MaxIndex_j=max(find(i_max))-1;% max ref index j622 diff_j_max=diff(i_max);638 % i_max=max(pair_max,[],2); 639 % MinIndex_j=min(find(i_max))-1;% min ref index j 640 % MaxIndex_j=max(find(i_max))-1;% max ref index j 641 % diff_j_max=diff(i_max); 623 642 if isequal (diff_j_max,diff_j_max(1)*ones(size(diff_j_max))) 624 643 set(handles.num_incr_j,'String',num2str(diff_j_max(1))) … … 635 654 MaxIndex_i_cell=get(handles.MaxIndex_i,'Data');%retrieve the min indices in the table MinIndex 636 655 MaxIndex_j_cell=get(handles.MaxIndex_j,'Data');%retrieve the min indices in the table MinIndex 637 MinIndex_i_cell {iview,1}=MinIndex_i;638 MinIndex_j_cell {iview,1}=MinIndex_j;639 MaxIndex_i_cell {iview,1}=MaxIndex_i;640 MaxIndex_j_cell {iview,1}=MaxIndex_j;656 MinIndex_i_cell(iview,1)=MinIndex_i; 657 MinIndex_j_cell(iview,1)=MinIndex_j; 658 MaxIndex_i_cell(iview,1)=MaxIndex_i; 659 MaxIndex_j_cell(iview,1)=MaxIndex_j; 641 660 set(handles.MinIndex_i,'Data',MinIndex_i_cell)%display the min indices in the table MinIndex 642 661 set(handles.MinIndex_j,'Data',MinIndex_j_cell)%display the max indices in the table MaxIndex … … 1321 1340 %------------------------------------------------------------------------ 1322 1341 % --- Executes on button press in RUN. 1342 %------------------------------------------------------------------------ 1323 1343 function RUN_Callback(hObject, eventdata, handles) 1324 %------------------------------------------------------------------------ 1325 1326 set(handles.RUN,'BusyAction','queue'); 1327 set(0,'CurrentFigure',handles.series) 1328 set(handles.RUN, 'Enable','Off') 1329 set(handles.RUN,'BackgroundColor',[ 0.831 0.816 0.784])1344 1345 %% settings of the button RUN 1346 set(handles.RUN,'BusyAction','queue');% activation of STOP button will set BusyAction to 'cancel' 1347 %set(0,'CurrentFigure',handles.series); % display the GUI series 1348 set(handles.RUN, 'Enable','Off')% avoid further RUN action until the current one is finished 1349 set(handles.RUN,'BackgroundColor',[1 1 0])%show activation of RUN by yellow color 1330 1350 drawnow 1331 1351 1332 %% read the input parameters and set the output dir and nomenclature 1333 [Series,OutputDir,errormsg]=prepare_jobs(handles);% get parameters form the GUI series 1334 if ~isempty(errormsg) 1335 if ~strcmp(errormsg,'Cancel') 1336 msgbox_uvmat('ERROR',errormsg) 1337 end 1338 STOP_Callback([],[], handles) 1339 return 1340 end 1341 OutputNomType=nomtype2pair(Series.InputTable{1,4});% nomenclature for output files 1342 DirXml=fullfile(OutputDir,'0_XML'); 1343 if ~exist(DirXml,'dir') 1344 [tild,msg1]=mkdir(DirXml); 1345 if ~strcmp(msg1,'') 1346 msgbox_uvmat('ERROR',['cannot create ' DirXml ': ' msg1]);%error message for directory creation 1347 return 1348 end 1349 end 1350 1351 %% select the Action modes 1352 RunMode='local';%default 1353 if isfield(Series.Action,'RunMode') 1354 RunMode=Series.Action.RunMode; 1352 %% read the data on the GUI series 1353 Param=read_GUI_series(handles);%displayed parameters 1354 SeriesData=get(handles.series,'UserData');%hidden parameters 1355 1356 %% create the output data directory if needed 1357 if isfield(Param,'OutputSubDir') 1358 SubDirOut=[get(handles.OutputSubDir,'String') Param.OutputDirExt]; 1359 SubDirOutNew=SubDirOut; 1360 detect=exist(fullfile(Param.InputTable{1,1},SubDirOutNew),'dir');% test if the dir already exist 1361 check_create=1; %need to create the result directory by default 1362 while detect 1363 answer=msgbox_uvmat('INPUT_Y-N',['use existing ouput directory: ' fullfile(Param.InputTable{1,1},SubDirOutNew) ', possibly delete previous data']); 1364 if strcmp(answer,'Cancel') 1365 errormsg='Cancel'; 1366 return 1367 elseif strcmp(answer,'Yes') 1368 detect=0; 1369 check_create=0; 1370 else 1371 r=regexp(SubDirOutNew,'(?<root>.*\D)(?<num1>\d+)$','names');%detect whether name ends by a number 1372 if isempty(r) 1373 r(1).root=[SubDirOutNew '_']; 1374 r(1).num1='0'; 1375 end 1376 SubDirOutNew=[r(1).root num2str(str2num(r(1).num1)+1)];%increment the index by 1 or put 1 1377 detect=exist(fullfile(Param.InputTable{1,1},SubDirOutNew),'dir');% test if the dir already exists 1378 check_create=1; 1379 end 1380 end 1381 Param.OutputDirExt=regexprep(SubDirOutNew,Param.OutputSubDir,''); 1382 Param.OutputRootFile=Param.InputTable{1,3};% the first sorted RootFile taken for output 1383 set(handles.OutputDirExt,'String',Param.OutputDirExt) 1384 OutputDir=fullfile(Param.InputTable{1,1},[Param.OutputSubDir Param.OutputDirExt]);% full name (with path) of output directory 1385 if check_create % create output directory if it does not exist 1386 [tild,msg1]=mkdir(OutputDir); 1387 if ~strcmp(msg1,'') 1388 errormsg=['cannot create ' OutputDir ': ' msg1];%error message for directory creation 1389 return 1390 end 1391 end 1392 OutputNomType=nomtype2pair(Param.InputTable{1,4});% nomenclature for output files 1393 DirXml=fullfile(OutputDir,'0_XML'); 1394 if ~exist(DirXml,'dir') 1395 [tild,msg1]=mkdir(DirXml); 1396 if ~strcmp(msg1,'') 1397 msgbox_uvmat('ERROR',['cannot create ' DirXml ': ' msg1]);%error message for directory creation 1398 return 1399 end 1400 end 1401 end 1402 1403 %% select the Action mode, 'local', 'background' or 'cluster' (if available) 1404 RunMode='local';%default (needed for first opening of the GUI series) 1405 if isfield(Param.Action,'RunMode') 1406 RunMode=Param.Action.RunMode; 1355 1407 end 1356 1408 ActionExt='.m';%default 1357 if isfield( Series.Action,'ActionExt')1358 ActionExt= Series.Action.ActionExt;% '.m' or '.sh' (compiled)1359 end 1360 ActionName= Series.Action.ActionName;1361 ActionPath= Series.Action.ActionPath;1409 if isfield(Param.Action,'ActionExt') 1410 ActionExt=Param.Action.ActionExt;% '.m' or '.sh' (compiled) 1411 end 1412 ActionName=Param.Action.ActionName; 1413 ActionPath=Param.Action.ActionPath; 1362 1414 path_series=fileparts(which('series')); 1363 1415 … … 1411 1463 return 1412 1464 end 1413 % Series.RunTime=RunTime;1414 1465 end 1415 1466 … … 1419 1470 NbCore=1;% no need to split the calculation 1420 1471 case 'cluster_oar' 1421 if strcmp( Series.Action.ActionExt,'.m')% case of Matlab function (uncompiled)1472 if strcmp(Param.Action.ActionExt,'.m')% case of Matlab function (uncompiled) 1422 1473 NbCore=1;% one core used only (limitation of Matlab licences) 1423 1474 msgbox_uvmat('WARNING','Number of cores =1: select the compiled version civ_matlab.sh for multi-core processing'); … … 1429 1480 end 1430 1481 end 1431 if ~isfield( Series.IndexRange,'NbSlice')1432 Series.IndexRange.NbSlice=[];1433 end 1434 if isempty( Series.IndexRange.NbSlice)1482 if ~isfield(Param.IndexRange,'NbSlice') 1483 Param.IndexRange.NbSlice=[]; 1484 end 1485 if isempty(Param.IndexRange.NbSlice) 1435 1486 NbProcess=NbCore;% choose one process per core 1436 1487 else 1437 NbProcess= Series.IndexRange.NbSlice;% the nbre of run processes is equal to the number of slices1488 NbProcess=Param.IndexRange.NbSlice;% the nbre of run processes is equal to the number of slices 1438 1489 NbCore=min(NbCore,NbProcess);% at least one process per core 1439 1490 end 1440 1491 1441 1442 %% read index ranges 1443 [first_i,incr_i,last_i,first_j,incr_j,last_j,errormsg]=get_index_range(Series.IndexRange); 1444 if ~isempty(errormsg) 1445 msgbox_uvmat('ERROR',['series/Run_Callback/get_index_range' errormsg]) 1492 %% get the set of reference field indices 1493 first_i=1; 1494 last_i=1; 1495 incr_i=1; 1496 first_j=1; 1497 last_j=1; 1498 incr_j=1; 1499 if isfield(Param.IndexRange,'first_i') 1500 first_i=Param.IndexRange.first_i; 1501 incr_i=Param.IndexRange.incr_i; 1502 last_i=Param.IndexRange.last_i; 1503 end 1504 if isfield(Param.IndexRange,'first_j') 1505 first_j=Param.IndexRange.first_j; 1506 last_j=Param.IndexRange.last_j; 1507 incr_j=Param.IndexRange.incr_j; 1508 end 1509 if last_i < first_i || last_j < first_j 1510 msgbox_uvmat('ERROR', 'series/Run_Callback:last field index must be larger or equal to the first one') 1446 1511 set(handles.RUN, 'Enable','On'), 1447 1512 set(handles.RUN,'BackgroundColor',[1 0 0]) 1448 1513 return 1514 end 1515 %incr_i must be defined, =1 by default, if NbSlice is active 1516 if isempty(incr_i)&& ~isempty(Param.IndexRange.NbSlice) 1517 incr_i=1; 1518 set(handles.num_incr_i,'String','1') 1519 end 1520 if isempty(incr_i) 1521 if isempty(incr_j) 1522 [ref_j,ref_i]=find(squeeze(SeriesData.i1_series{1}(1,:,:))); 1523 ref_j=ref_j(ref_j>=first_j & ref_j<=last_j); 1524 ref_i=ref_i(ref_i>=first_i & ref_i<=last_i); 1525 ref_j=ref_j-1; 1526 ref_i=ref_i-1; 1527 else 1528 ref_j=first_j:incr_j:last_j; 1529 [tild,ref_i]=find(squeeze(SeriesData.i1_series{1}(1,:,:))); 1530 ref_i=ref_i-1; 1531 ref_i=ref_i(ref_i>=first_i & ref_i<=last_i); 1532 end 1449 1533 else 1450 BlockLength=ceil(numel(first_i:incr_i:last_i)/NbProcess); 1451 end 1452 nbfield_j=numel(first_j:incr_j:last_j); 1534 ref_i=first_i:incr_i:last_i; 1535 if isempty(incr_j) 1536 [ref_j,tild]=find(squeeze(SeriesData.i1_series{1}(1,:,:))); 1537 ref_j=ref_j-1; 1538 ref_j=ref_j(ref_j>=first_j & ref_j<=last_j); 1539 else 1540 ref_j=first_j:incr_j:last_j; 1541 end 1542 end 1543 BlockLength=ceil(numel(ref_i)/NbProcess); 1544 nbfield_j=numel(ref_j); 1453 1545 1454 1546 %% record nbre of output files and starting time for computation for status … … 1457 1549 switch StatusData.OutputFileMode 1458 1550 case 'NbInput' 1459 StatusData.NbOutputFile=numel( first_i:incr_i:last_i)*numel(first_j:incr_j:last_j);1551 StatusData.NbOutputFile=numel(ref_i)*nbfield_j; 1460 1552 case 'NbInput_i' 1461 StatusData.NbOutputFile=numel( first_i:incr_i:last_i);1553 StatusData.NbOutputFile=numel(ref_i); 1462 1554 case 'NbSlice' 1463 1555 StatusData.NbOutputFile=str2num(get(handles.num_NbSlice,'String')); … … 1469 1561 %% direct processing on the current Matlab session 1470 1562 if strcmp (RunMode,'local') 1471 % Series.RUNHandle=handles.RUN;1472 % Series.WaitbarHandle=handles.Waitbar;1473 1563 for iprocess=1:NbProcess 1474 if isempty(Series.IndexRange.NbSlice) 1475 Series.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i; 1476 if Series.IndexRange.first_i>last_i 1564 if isempty(Param.IndexRange.NbSlice) 1565 %Param.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i; 1566 Param.IndexRange.first_i=ref_i(1+(iprocess-1)*BlockLength); 1567 if Param.IndexRange.first_i>last_i 1477 1568 break 1478 1569 end 1479 Series.IndexRange.last_i=min(first_i+(iprocess)*BlockLength*incr_i-1,last_i); 1480 else 1481 Series.IndexRange.first_i= first_i+incr_i*(iprocess-1); 1482 Series.IndexRange.incr_i=incr_i*Series.IndexRange.NbSlice; 1483 end 1484 t=struct2xml(Series); 1570 Param.IndexRange.last_i=min(ref_i(iprocess*BlockLength),last_i); 1571 %Param.IndexRange.last_i=min(first_i+(iprocess)*BlockLength*incr_i-1,last_i); 1572 else %multislices (then incr_i is not empty) 1573 Param.IndexRange.first_i= first_i+incr_i*(iprocess-1); 1574 Param.IndexRange.incr_i=incr_i*Param.IndexRange.NbSlice; 1575 end 1576 if isfield(Param,'OutputSubDir') 1577 t=struct2xml(Param); 1485 1578 t=set(t,1,'name','Series'); 1486 filexml=fullfile_uvmat(DirXml,'', Series.InputTable{1,3},'.xml',OutputNomType,...1487 Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j);1579 filexml=fullfile_uvmat(DirXml,'',Param.InputTable{1,3},'.xml',OutputNomType,... 1580 Param.IndexRange.first_i,Param.IndexRange.last_i,first_j,last_j); 1488 1581 save(t,filexml); 1582 end 1489 1583 switch ActionExt 1490 1584 case '.m' 1491 h_fun( Series);1585 h_fun(Param); 1492 1586 case '.sh' 1493 1587 switch computer … … 1506 1600 %% processing on a different session of the same computer (background) or cluster, create executable files 1507 1601 batch_file_list=cell(NbProcess,1);% initiate the list of executable files 1508 DirBat=fullfile(OutputDir,'0_BAT'); 1602 DirBat=fullfile(OutputDir,'0_EXE'); 1603 switch computer 1604 case {'PCWIN','PCWIN64'} %Windows system 1605 ExeExt='.bat'; 1606 case {'GLNX86','GLNXA64','MACI64'}%Linux system 1607 ExeExt='.sh'; 1608 end 1509 1609 %create subdirectory for executable files 1510 1610 if ~exist(DirBat,'dir') … … 1525 1625 end 1526 1626 for iprocess=1:NbProcess 1527 if isempty( Series.IndexRange.NbSlice)% process by blocks of i index1528 Series.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i;1529 if Series.IndexRange.first_i>last_i1627 if isempty(Param.IndexRange.NbSlice)% process by blocks of i index 1628 Param.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i; 1629 if Param.IndexRange.first_i>last_i 1530 1630 NbProcess=iprocess-1; 1531 1631 break% leave the loop, we are at the end of the calculation 1532 1632 end 1533 Series.IndexRange.last_i=min(last_i,first_i+(iprocess)*BlockLength*incr_i-1);1633 Param.IndexRange.last_i=min(last_i,first_i+(iprocess)*BlockLength*incr_i-1); 1534 1634 else% process by slices of i index if NbSlice is defined, computation in a single process if NbSlice =1 1535 Series.IndexRange.first_i= first_i+iprocess-1;1536 Series.IndexRange.incr_i=incr_i*Series.IndexRange.NbSlice;1635 Param.IndexRange.first_i= first_i+iprocess-1; 1636 Param.IndexRange.incr_i=incr_i*Param.IndexRange.NbSlice; 1537 1637 end 1538 1638 1539 1639 % create, fill and save the xml parameter file 1540 t=struct2xml( Series);1640 t=struct2xml(Param); 1541 1641 t=set(t,1,'name','Series'); 1542 filexml=fullfile_uvmat(DirXml,'', Series.InputTable{1,3},'.xml',OutputNomType,...1543 Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j);1642 filexml=fullfile_uvmat(DirXml,'',Param.InputTable{1,3},'.xml',OutputNomType,... 1643 Param.IndexRange.first_i,Param.IndexRange.last_i,first_j,last_j); 1544 1644 save(t,filexml);% save the parameter file 1545 1645 1546 1646 %create the executable file 1547 % filebat=fullfile_uvmat(DirBat,'',Series.InputTable{1,3},'.bat',OutputNomType,... 1548 % Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j); 1549 filebat=fullfile_uvmat(DirBat,'',Series.InputTable{1,3},'.sh',OutputNomType,... 1550 Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j); 1647 filebat=fullfile_uvmat(DirBat,'',Param.InputTable{1,3},ExeExt,OutputNomType,... 1648 Param.IndexRange.first_i,Param.IndexRange.last_i,first_j,last_j); 1551 1649 batch_file_list{iprocess}=filebat; 1552 1650 [fid,message]=fopen(filebat,'w');% create the executable file … … 1557 1655 1558 1656 % set the log file name 1559 filelog=fullfile_uvmat(DirLog,'', Series.InputTable{1,3},'.log',OutputNomType,...1560 Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j);1657 filelog=fullfile_uvmat(DirLog,'',Param.InputTable{1,3},'.log',OutputNomType,... 1658 Param.IndexRange.first_i,Param.IndexRange.last_i,first_j,last_j); 1561 1659 1562 1660 % fill and save the executable file … … 1570 1668 'matlab -nodisplay -nosplash -nojvm -logfile ''' filelog ''' <<END_MATLAB \n'... 1571 1669 'addpath(''' path_series '''); \n'... 1572 'addpath(''' Series.Action.ActionPath '''); \n'...1573 '' Series.Action.ActionName '( ''' filexml '''); \n'...1670 'addpath(''' Param.Action.ActionPath '''); \n'... 1671 '' Param.Action.ActionName '( ''' filexml '''); \n'... 1574 1672 'exit \n'... 1575 1673 'END_MATLAB \n']; … … 1580 1678 text_matlabscript=['matlab -automation -logfile ' regexprep(filelog,'\\','\\\\')... 1581 1679 ' -r "addpath(''' regexprep(path_series,'\\','\\\\') ''');'... 1582 'addpath(''' regexprep( Series.Action.ActionPath,'\\','\\\\') ''');'...1583 '' Series.Action.ActionName '( ''' regexprep(filexml,'\\','\\\\') ''');exit"'];1680 'addpath(''' regexprep(Param.Action.ActionPath,'\\','\\\\') ''');'... 1681 '' Param.Action.ActionName '( ''' regexprep(filexml,'\\','\\\\') ''');exit"']; 1584 1682 fprintf(fid,text_matlabscript);%fill the executable file with the char string cmd 1585 1683 fclose(fid);% close the executable file … … 1600 1698 % cmd=['matlab -automation -logfile ' regexprep(filelog,'\\','\\\\')... 1601 1699 % ' -r "addpath(''' regexprep(path_series,'\\','\\\\') ''');'... 1602 % 'addpath(''' regexprep( Series.Action.ActionPath,'\\','\\\\') ''');'...1603 % '' Series.Action.ActionName '( ''' regexprep(filexml,'\\','\\\\') ''');exit"'];1700 % 'addpath(''' regexprep(Param.Action.ActionPath,'\\','\\\\') ''');'... 1701 % '' Param.Action.ActionName '( ''' regexprep(filexml,'\\','\\\\') ''');exit"']; 1604 1702 fprintf(fid,cmd); 1605 1703 fclose(fid); … … 1680 1778 % --- Main launch command, called by RUN and BATCH 1681 1779 1682 function [Series,OutputDir,errormsg]=prepare_jobs(handles) 1683 %INPUT: 1684 % handles: handles of graphic objects on the GUI series 1685 1686 %------------------------------------------------------------------------ 1687 OutputDir=''; 1688 errormsg=''; 1689 1690 %% Read parameters from series 1691 Series=read_GUI(handles.series); 1692 1693 %% get_field GUI 1694 % if isfield(Series,'InputFields')&&isfield(Series.InputFields,'Field') 1695 % if strcmp(Series.InputFields.Field,'get_field...') 1696 % hget_field=findobj(allchild(0),'name','get_field'); 1697 % Series.GetField=read_GUI(hget_field); 1698 % end 1699 % end 1700 1701 %% create the output data directory 1702 %determine the root file corresponding to the first sub dir 1703 if get(handles.RUN,'value') && isfield(Series,'OutputSubDir') 1704 SubDirOut=[get(handles.OutputSubDir,'String') Series.OutputDirExt]; 1705 SubDirOutNew=SubDirOut; 1706 SeriesData=get(handles.series,'UserData'); 1707 % if size(Series.InputTable,1)>1 && isfield(SeriesData,'AllowInputSort') && SeriesData.AllowInputSort 1708 % [tild,iview]=sort(Series.InputTable(:,2)); %subdirectories sorted in alphabetical order 1709 % Series.InputTable=Series.InputTable(iview,:); 1710 % end 1711 detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if the dir already exist 1712 check_create=1; %need to create the result directory by default 1713 while detect 1714 answer=msgbox_uvmat('INPUT_Y-N',['use existing ouput directory: ' fullfile(Series.InputTable{1,1},SubDirOutNew) ', possibly delete previous data']); 1715 if strcmp(answer,'Cancel') 1716 errormsg='Cancel'; 1717 return 1718 elseif strcmp(answer,'Yes') 1719 detect=0; 1720 check_create=0; 1721 else 1722 r=regexp(SubDirOutNew,'(?<root>.*\D)(?<num1>\d+)$','names');%detect whether name ends by a number 1723 if isempty(r) 1724 r(1).root=[SubDirOutNew '_']; 1725 r(1).num1='0'; 1726 end 1727 SubDirOutNew=[r(1).root num2str(str2num(r(1).num1)+1)];%increment the index by 1 or put 1 1728 detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if the dir already exists 1729 check_create=1; 1730 end 1731 end 1732 Series.OutputDirExt=regexprep(SubDirOutNew,Series.OutputSubDir,''); 1733 Series.OutputRootFile=Series.InputTable{1,3};% the first sorted RootFile taken for output 1734 set(handles.OutputDirExt,'String',Series.OutputDirExt) 1735 OutputDir=fullfile(Series.InputTable{1,1},[Series.OutputSubDir Series.OutputDirExt]);% full name (with path) of output directory 1736 if check_create % create output directory if it does not exist 1737 [tild,msg1]=mkdir(OutputDir); 1738 if ~strcmp(msg1,'') 1739 errormsg=['cannot create ' OutputDir ': ' msg1];%error message for directory creation 1740 return 1741 end 1742 end 1743 % RootOut=fullfile(OutputDir,Series.InputTable{1,3});% name of the parameter xml file set in this directory 1744 end 1745 1746 %% removes unused information on Series 1747 if isfield(Series,'Pairs') 1748 Series=rmfield(Series,'Pairs'); %info Pairs not needed for output 1749 end 1750 Series.IndexRange=rmfield(Series.IndexRange,'TimeTable'); 1751 % Series.IndexRange=rmfield(Series.IndexRange,'MinIndex_j'); 1752 % Series.IndexRange=rmfield(Series.IndexRange,'MaxIndex_i'); 1753 empty_line=false(size(Series.InputTable,1),1); 1754 for iline=1:size(Series.InputTable,1) 1755 empty_line(iline)=isequal(Series.InputTable(iline,1:3),{'','',''}); 1756 end 1757 Series.InputTable(empty_line,:)=[]; 1780 %------------------------------------------------------------------------ 1781 % --- read parameters from the GUI series 1782 %------------------------------------------------------------------------ 1783 function Param=read_GUI_series(handles) 1784 1785 %% read raw parameters from the GUI series 1786 Param=read_GUI(handles.series); 1787 1788 %% clean the output structure by removing unused information 1789 if isfield(Param,'Pairs') 1790 Param=rmfield(Param,'Pairs'); %info Pairs not needed for output 1791 end 1792 Param.IndexRange=rmfield(Param.IndexRange,'TimeTable'); 1793 empty_line=false(size(Param.InputTable,1),1); 1794 for iline=1:size(Param.InputTable,1) 1795 empty_line(iline)=isequal(Param.InputTable(iline,1:3),{'','',''}); 1796 end 1797 Param.InputTable(empty_line,:)=[]; 1758 1798 1759 1799 %------------------------------------------------------------------------ … … 1882 1922 1883 1923 %% Activate the Action fct 1884 [Series,tild,errormsg]=prepare_jobs(handles);% read the parameters from the GUI series 1885 if ~isempty(errormsg) 1886 if ~strcmp(errormsg,'Cancel') 1887 msgbox_uvmat('ERROR',errormsg) 1888 end 1889 return 1890 end 1891 ParamOut=h_fun(Series); 1924 Param=read_GUI_series(handles);% read the parameters from the GUI series 1925 ParamOut=h_fun(Param); 1892 1926 1893 1927 %% Put the first line of the selected Action fct as tooltip help … … 1918 1952 1919 1953 %% Check whether alphabetical sorting of input Subdir is alowed by the Action fct (for multiples series entries) 1920 if isfield(ParamOut,'AllowInputSort')&&isequal(ParamOut.AllowInputSort,'on')&& size( Series.InputTable,1)>11954 if isfield(ParamOut,'AllowInputSort')&&isequal(ParamOut.AllowInputSort,'on')&& size(Param.InputTable,1)>1 1921 1955 [tild,iview]=sort(InputTable(:,2)); %subdirectories sorted in alphabetical order 1922 1956 set(handles.InputTable,'Data',InputTable(iview,:)); … … 1941 1975 MaxIndex_i=get(handles.MaxIndex_i,'Data'); 1942 1976 MaxIndex_j=get(handles.MaxIndex_j,'Data'); 1943 set(handles.num_first_i,'String',num2str(MinIndex_i {1}))% set first as the min index (for the first line)1944 set(handles.num_last_i,'String',num2str(MaxIndex_i {1}))% set last as the max index (for the first line)1977 set(handles.num_first_i,'String',num2str(MinIndex_i(1)))% set first as the min index (for the first line) 1978 set(handles.num_last_i,'String',num2str(MaxIndex_i(1)))% set last as the max index (for the first line) 1945 1979 set(handles.num_incr_i,'String','1') 1946 set(handles.num_first_j,'String',num2str(MinIndex_j {1}))% set first as the min index (for the first line)1947 set(handles.num_last_j,'String',num2str(MaxIndex_j {1}))% set last as the max index (for the first line)1980 set(handles.num_first_j,'String',num2str(MinIndex_j(1)))% set first as the min index (for the first line) 1981 set(handles.num_last_j,'String',num2str(MaxIndex_j(1)))% set last as the max index (for the first line) 1948 1982 set(handles.num_incr_j,'String','1') 1949 1983 else % check index ranges 1950 1984 first_i=1;last_i=1;first_j=1;last_j=1; 1951 if isfield( Series.IndexRange,'first_i')1952 first_i= Series.IndexRange.first_i;1953 % incr_i= Series.IndexRange.incr_i;1954 last_i= Series.IndexRange.last_i;1955 end 1956 if isfield( Series.IndexRange,'first_j')1957 first_j= Series.IndexRange.first_j;1958 % incr_j= Series.IndexRange.incr_j;1959 last_j= Series.IndexRange.last_j;1985 if isfield(Param.IndexRange,'first_i') 1986 first_i=Param.IndexRange.first_i; 1987 % incr_i=Param.IndexRange.incr_i; 1988 last_i=Param.IndexRange.last_i; 1989 end 1990 if isfield(Param.IndexRange,'first_j') 1991 first_j=Param.IndexRange.first_j; 1992 % incr_j=Param.IndexRange.incr_j; 1993 last_j=Param.IndexRange.last_j; 1960 1994 end 1961 1995 if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),... … … 2120 2154 delete(hget_field)%delete opened versions of get_field 2121 2155 end 2122 Series=read_GUI(handles.series);2123 Series.InputTable=Series.InputTable(1,:);2124 filecell=get_file_series( Series);2156 Param=read_GUI(handles.series); 2157 Param.InputTable=Param.InputTable(1,:); 2158 filecell=get_file_series(Param); 2125 2159 if exist(filecell{1,1},'file') 2126 2160 GetFieldData=get_field(filecell{1,1}); … … 2431 2465 if isempty(TransformIndex)%the input string does not exist in the menu 2432 2466 TransformIndex= length(TransformList); 2433 TransformList=[TransformList(1:end-1);{Transform nName};TransformList(end)];% the selected function is appended in the menu, before the last item 'more...'2467 TransformList=[TransformList(1:end-1);{TransformName};TransformList(end)];% the selected function is appended in the menu, before the last item 'more...' 2434 2468 set(handles.TransformName,'String',TransformList) 2435 2469 TransformPathList=[TransformPathList;{TransformPath}]; … … 2451 2485 set(handles.TransformName,'UserData',TransformPathList); 2452 2486 2453 2454 % -------------------------------------------------------------------- 2487 %------------------------------------------------------------------------ 2488 % --- fct activated by the upper bar menu ExportConfig 2489 %------------------------------------------------------------------------ 2455 2490 function MenuExportConfig_Callback(hObject, eventdata, handles) 2456 global Series 2457 [Series,errormsg]=prepare_jobs(handles); 2458 2459 evalin('base','global Series')%make CurData global in the workspace2491 2492 global Param 2493 Param=read_GUI_series(handles); 2494 evalin('base','global Param')%make CurData global in the workspace 2460 2495 display('current series config :') 2461 evalin('base',' Series') %display CurData in the workspace2496 evalin('base','Param') %display CurData in the workspace 2462 2497 commandwindow; %brings the Matlab command window to the front 2463 2498 2464 % -------------------------------------------------------------------- 2499 %------------------------------------------------------------------------ 2500 % --- fct activated by the upper bar menu InportConfig 2501 %------------------------------------------------------------------------ 2465 2502 function MenuImportConfig_Callback(hObject, eventdata, handles) 2466 % -------------------------------------------------------------------- 2503 2467 2504 InputTable=get(handles.InputTable,'Data'); 2468 2505 [FileName, PathName] = uigetfile( ... … … 2476 2513 fill_GUI(Param,handles.series) 2477 2514 2478 % --- Executes on selection change in RunMode. 2479 function RunMode_Callback(hObject, eventdata, handles) 2480 2481 % --- Executes on selection change in Coord_x. 2482 function Coord_x_Callback(hObject, eventdata, handles) 2483 2484 % --- Executes on selection change in Coord_y. 2485 function Coord_y_Callback(hObject, eventdata, handles) 2486 2487 % -------------------------------------------------------------------- 2488 % --- Executes when series is resized. 2515 %------------------------------------------------------------------------ 2516 % --- Executes when the GUI series is resized. 2517 %------------------------------------------------------------------------ 2489 2518 function series_ResizeFcn(hObject, eventdata, handles) 2490 % -------------------------------------------------------------------- 2519 2491 2520 %% input table 2492 2521 set(handles.InputTable,'Unit','pixel') … … 2670 2699 set(hwaitbar,'Position',BarPosition) 2671 2700 end 2672 %TODO: adjust waitbar 2673 2674 % civ_files=get(hfig,'UserData'); 2675 2676 % [filepath,filename,ext]=fileparts(civ_files{1}); 2677 % [tild,SubDir,extdir]=fileparts(filepath); 2678 % SubDir=[SubDir extdir]; 2679 % option_civ=StatusData.option_civ; 2680 % nbfiles=numel(civ_files); 2681 % testrecent=0; 2682 % count=0; 2683 % datnum=zeros(1,nbfiles); 2684 % filefound=cell(1,nbfiles); 2685 % for ifile=1:nbfiles 2686 % detect=exist(civ_files{ifile},'file'); % check the existence of the file 2687 % option=0; 2688 % if detect==0 2689 % option_str='not created'; 2690 % else 2691 % datfile=dir(civ_files{ifile}); 2692 % if isfield(datfile,'datenum') 2693 % datnum(ifile)=datfile.datenum;%only available in recent matlab versions 2694 % testrecent=1; 2695 % end 2696 % filefound(ifile)={datfile.name}; 2697 % 2698 % % check the content netcdf file 2699 % Data=nc2struct(civ_files{ifile},'ListGlobalAttribute','CivStage','patch2','fix2','civ2','patch','fix'); 2700 % option_list={'civ1','fix1','patch1','civ2','fix2','patch2'}; 2701 % if ~isempty(Data.CivStage) 2702 % option=Data.CivStage;%case of Matlab civ 2703 % else 2704 % if ~isempty(Data.patch2) && isequal(Data.patch2,1) 2705 % option=6; 2706 % elseif ~isempty(Data.fix2) && isequal(Data.fix2,1) 2707 % option=5; 2708 % elseif ~isempty(Data.civ2) && isequal(Data.civ2,1); 2709 % option=4; 2710 % elseif ~isempty(Data.patch) && isequal(Data.patch,1); 2711 % option=3; 2712 % elseif ~isempty(Data.fix) && isequal(Data.fix,1); 2713 % option=2; 2714 % else 2715 % option=1; 2716 % end 2717 % end 2718 % option_str=option_list{option}; 2719 % if datnum(ifile)<StatusData.time_ref 2720 % option_str=[option_str ' --OLD--']; 2721 % end 2722 % end 2723 % if option >= option_civ 2724 % count=count+1; 2725 % end 2726 % [filepath,filename,ext]=fileparts(civ_files{ifile}); 2727 % Tabchar{ifile,1}=[fullfile(SubDir,filename) ext '...' option_str]; 2728 % end 2729 % datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files 2730 % if isempty(datnum) 2731 % if testrecent 2732 % message='no civ result created yet'; 2733 % else 2734 % message=''; 2735 % end 2736 % else 2737 % datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files 2738 % [first,ind]=min(datnum); 2739 % [last,indlast]=max(datnum); 2740 % message={[num2str(count) ' file(s) done over ' num2str(nbfiles)] ;['oldest modification: ' cell2mat(filefound(ind)) ' : ' datestr(first)];... 2741 % ['latest modification: ' cell2mat(filefound(indlast)) ' : ' datestr(last)]}; 2742 % end 2743 % hlist=findobj(hfig,'tag','list'); 2744 % htitlebox=findobj(hfig,'tag','titlebox'); 2745 % hwaitbar=findobj(hfig,'tag','waitbar'); 2746 % set(hlist,'String',Tabchar) 2747 % set(htitlebox,'String', message) 2748 % 2749 %------------------------------------------------------------------------ 2750 % launched by deleting the status figure 2751 function stop_status(hObject, eventdata) 2752 %------------------------------------------------------------------------ 2753 hciv=findobj(allchild(0),'tag','series'); 2754 hhciv=guidata(hciv); 2755 set(hhciv.status,'value',0) %reset the status uicontrol in the GUI civ 2756 set(hhciv.status,'BackgroundColor',[0 1 0]) 2757 delete(gcbf) 2758 2701 2702 %------------------------------------------------------------------------ 2759 2703 % --- Executes on selection change in ActionExt. 2704 %------------------------------------------------------------------------ 2760 2705 function ActionExt_Callback(hObject, eventdata, handles) 2706 2761 2707 ActionExtList=get(handles.ActionExt,'String'); 2762 2708 ActionExt=ActionExtList{get(handles.ActionExt,'Value')}; … … 2782 2728 compile(ActionName,TransformPath) 2783 2729 cd(currentdir) 2784 end 2785 2730 end 2786 2731 else 2787 2732 sh_file_info=dir(fullfile(get(handles.ActionPath,'String'),[ActionName '.sh'])); … … 2852 2797 end 2853 2798 menu=menu(1:imax); 2854
Note: See TracChangeset
for help on using the changeset viewer.