Changeset 635 for trunk/src/series.m


Ignore:
Timestamp:
May 19, 2013, 11:37:49 PM (11 years ago)
Author:
sommeria
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/series.m

    r630 r635  
    524524    InputTable(iview,:)=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}];
    525525    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',[])
    530530    set(handles.ListView,'Value',1)
    531531    set(handles.ListView,'String',{'1'})
     
    606606    MinIndex_j=1;% index j set to 1 by default
    607607    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)
    610610else
    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);
    616635    if ~isempty(diff_i_max) && isequal (diff_i_max,diff_i_max(1)*ones(size(diff_i_max)))
    617636        set(handles.num_incr_i,'String',num2str(diff_i_max(1)))% detect an increment to dispaly by default
    618637    end
    619     i_max=max(pair_max,[],2);
    620     MinIndex_j=min(find(i_max))-1;% min ref index j
    621     MaxIndex_j=max(find(i_max))-1;% max ref index j
    622     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);
    623642    if isequal (diff_j_max,diff_j_max(1)*ones(size(diff_j_max)))
    624643        set(handles.num_incr_j,'String',num2str(diff_j_max(1)))
     
    635654MaxIndex_i_cell=get(handles.MaxIndex_i,'Data');%retrieve the min indices in the table MinIndex
    636655MaxIndex_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;
     656MinIndex_i_cell(iview,1)=MinIndex_i;
     657MinIndex_j_cell(iview,1)=MinIndex_j;
     658MaxIndex_i_cell(iview,1)=MaxIndex_i;
     659MaxIndex_j_cell(iview,1)=MaxIndex_j;
    641660set(handles.MinIndex_i,'Data',MinIndex_i_cell)%display the min indices in the table MinIndex
    642661set(handles.MinIndex_j,'Data',MinIndex_j_cell)%display the max indices in the table MaxIndex
     
    13211340%------------------------------------------------------------------------
    13221341% --- Executes on button press in RUN.
     1342%------------------------------------------------------------------------
    13231343function 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
     1346set(handles.RUN,'BusyAction','queue');% activation of STOP button will set BusyAction to 'cancel'
     1347%set(0,'CurrentFigure',handles.series); % display the GUI series
     1348set(handles.RUN, 'Enable','Off')% avoid further RUN action until the current one is finished
     1349set(handles.RUN,'BackgroundColor',[1 1 0])%show activation of RUN by yellow color
    13301350drawnow
    13311351
    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
     1353Param=read_GUI_series(handles);%displayed parameters
     1354SeriesData=get(handles.series,'UserData');%hidden parameters
     1355
     1356%% create the output data directory if needed
     1357if 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
     1401end
     1402
     1403%% select the Action mode, 'local', 'background' or 'cluster' (if available)
     1404RunMode='local';%default (needed for first opening of the GUI series)
     1405if isfield(Param.Action,'RunMode')
     1406    RunMode=Param.Action.RunMode;
    13551407end
    13561408ActionExt='.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;
     1409if isfield(Param.Action,'ActionExt')
     1410    ActionExt=Param.Action.ActionExt;% '.m' or '.sh' (compiled)
     1411end
     1412ActionName=Param.Action.ActionName;
     1413ActionPath=Param.Action.ActionPath;
    13621414path_series=fileparts(which('series'));
    13631415
     
    14111463        return
    14121464    end
    1413 %     Series.RunTime=RunTime;
    14141465end
    14151466
     
    14191470        NbCore=1;% no need to split the calculation
    14201471    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)
    14221473            NbCore=1;% one core used only (limitation of Matlab licences)
    14231474            msgbox_uvmat('WARNING','Number of cores =1: select the compiled version civ_matlab.sh for multi-core processing');
     
    14291480        end
    14301481end
    1431 if ~isfield(Series.IndexRange,'NbSlice')
    1432     Series.IndexRange.NbSlice=[];
    1433 end
    1434 if isempty(Series.IndexRange.NbSlice)
     1482if ~isfield(Param.IndexRange,'NbSlice')
     1483    Param.IndexRange.NbSlice=[];
     1484end
     1485if isempty(Param.IndexRange.NbSlice)
    14351486    NbProcess=NbCore;% choose one process per core
    14361487else
    1437     NbProcess=Series.IndexRange.NbSlice;% the nbre of run processes is equal to the number of slices
     1488    NbProcess=Param.IndexRange.NbSlice;% the nbre of run processes is equal to the number of slices
    14381489    NbCore=min(NbCore,NbProcess);% at least one process per core
    14391490end
    14401491       
    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
     1493first_i=1;
     1494last_i=1;
     1495incr_i=1;
     1496first_j=1;
     1497last_j=1;
     1498incr_j=1;
     1499if 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;
     1503end
     1504if 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;
     1508end
     1509if 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')
    14461511    set(handles.RUN, 'Enable','On'),
    14471512    set(handles.RUN,'BackgroundColor',[1 0 0])
    14481513    return
     1514end
     1515%incr_i must be defined, =1 by default, if NbSlice is active
     1516if isempty(incr_i)&& ~isempty(Param.IndexRange.NbSlice)
     1517    incr_i=1;
     1518    set(handles.num_incr_i,'String','1')
     1519end
     1520if 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
    14491533else
    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
     1542end
     1543BlockLength=ceil(numel(ref_i)/NbProcess);
     1544nbfield_j=numel(ref_j);
    14531545
    14541546%% record nbre of output files and starting time for computation for status
     
    14571549    switch StatusData.OutputFileMode
    14581550        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;
    14601552        case 'NbInput_i'
    1461             StatusData.NbOutputFile=numel(first_i:incr_i:last_i);
     1553            StatusData.NbOutputFile=numel(ref_i);
    14621554        case 'NbSlice'   
    14631555            StatusData.NbOutputFile=str2num(get(handles.num_NbSlice,'String'));
     
    14691561%% direct processing on the current Matlab session
    14701562if strcmp (RunMode,'local')
    1471 %     Series.RUNHandle=handles.RUN;
    1472 %     Series.WaitbarHandle=handles.Waitbar;
    14731563    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
    14771568                break
    14781569            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);
    14851578        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);
    14881581        save(t,filexml);
     1582        end
    14891583        switch ActionExt
    14901584            case '.m'
    1491                 h_fun(Series);
     1585                h_fun(Param);
    14921586            case '.sh'
    14931587                switch computer
     
    15061600    %% processing on a different session of the same computer (background) or cluster, create executable files
    15071601    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
    15091609    %create subdirectory for executable files
    15101610    if ~exist(DirBat,'dir')
     
    15251625    end
    15261626    for iprocess=1:NbProcess
    1527         if isempty(Series.IndexRange.NbSlice)% process by blocks of i index
    1528             Series.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i;
    1529             if Series.IndexRange.first_i>last_i
     1627        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
    15301630                NbProcess=iprocess-1;
    15311631                break% leave the loop, we are at the end of the calculation
    15321632            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);
    15341634        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;
    15371637        end
    15381638       
    15391639        % create, fill and save the xml parameter file
    1540         t=struct2xml(Series);
     1640        t=struct2xml(Param);
    15411641        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);
    15441644        save(t,filexml);% save the parameter file
    15451645       
    15461646        %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);
    15511649        batch_file_list{iprocess}=filebat;
    15521650        [fid,message]=fopen(filebat,'w');% create the executable file
     
    15571655       
    15581656        % 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);
    15611659       
    15621660        % fill and save the executable file
     
    15701668                            'matlab -nodisplay -nosplash -nojvm -logfile ''' filelog ''' <<END_MATLAB \n'...
    15711669                            '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'...
    15741672                            'exit \n'...
    15751673                            'END_MATLAB \n'];
     
    15801678                        text_matlabscript=['matlab -automation -logfile ' regexprep(filelog,'\\','\\\\')...
    15811679                            ' -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"'];
    15841682                        fprintf(fid,text_matlabscript);%fill the executable file with the  char string cmd
    15851683                        fclose(fid);% close the executable file
     
    16001698                        %                                 cmd=['matlab -automation -logfile ' regexprep(filelog,'\\','\\\\')...
    16011699                        %                                     ' -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"'];
    16041702                        fprintf(fid,cmd);
    16051703                        fclose(fid);
     
    16801778% --- Main launch command, called by RUN and BATCH
    16811779
    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%------------------------------------------------------------------------
     1783function Param=read_GUI_series(handles)
     1784
     1785%% read raw parameters from the GUI series
     1786Param=read_GUI(handles.series);
     1787
     1788%% clean the output structure by removing unused information
     1789if isfield(Param,'Pairs')
     1790    Param=rmfield(Param,'Pairs'); %info Pairs not needed for output
     1791end
     1792Param.IndexRange=rmfield(Param.IndexRange,'TimeTable');
     1793empty_line=false(size(Param.InputTable,1),1);
     1794for iline=1:size(Param.InputTable,1)
     1795    empty_line(iline)=isequal(Param.InputTable(iline,1:3),{'','',''});
     1796end
     1797Param.InputTable(empty_line,:)=[];
    17581798
    17591799%------------------------------------------------------------------------
     
    18821922
    18831923%% 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);
     1924Param=read_GUI_series(handles);% read the parameters from the GUI series
     1925ParamOut=h_fun(Param);
    18921926
    18931927%% Put the first line of the selected Action fct as tooltip help
     
    19181952
    19191953%% 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)>1
     1954if isfield(ParamOut,'AllowInputSort')&&isequal(ParamOut.AllowInputSort,'on')&& size(Param.InputTable,1)>1
    19211955    [tild,iview]=sort(InputTable(:,2)); %subdirectories sorted in alphabetical order
    19221956    set(handles.InputTable,'Data',InputTable(iview,:));
     
    19411975    MaxIndex_i=get(handles.MaxIndex_i,'Data');
    19421976    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)
    19451979    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)
    19481982    set(handles.num_incr_j,'String','1')
    19491983else  % check index ranges
    19501984    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;
    19601994    end
    19611995    if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
     
    21202154        delete(hget_field)%delete opened versions of get_field
    21212155    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);
    21252159    if exist(filecell{1,1},'file')
    21262160        GetFieldData=get_field(filecell{1,1});
     
    24312465    if isempty(TransformIndex)%the input string does not exist in the menu
    24322466        TransformIndex= length(TransformList);
    2433         TransformList=[TransformList(1:end-1);{TransformnName};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...'
    24342468        set(handles.TransformName,'String',TransformList)
    24352469        TransformPathList=[TransformPathList;{TransformPath}];
     
    24512485set(handles.TransformName,'UserData',TransformPathList);
    24522486
    2453 
    2454 % --------------------------------------------------------------------
     2487%------------------------------------------------------------------------
     2488% --- fct activated by the upper bar menu ExportConfig
     2489%------------------------------------------------------------------------
    24552490function 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 workspace
     2491
     2492global Param
     2493Param=read_GUI_series(handles);
     2494evalin('base','global Param')%make CurData global in the workspace
    24602495display('current series config :')
    2461 evalin('base','Series') %display CurData in the workspace
     2496evalin('base','Param') %display CurData in the workspace
    24622497commandwindow; %brings the Matlab command window to the front
    24632498
    2464 % --------------------------------------------------------------------
     2499%------------------------------------------------------------------------
     2500% --- fct activated by the upper bar menu InportConfig
     2501%------------------------------------------------------------------------
    24652502function MenuImportConfig_Callback(hObject, eventdata, handles)
    2466 % --------------------------------------------------------------------
     2503
    24672504InputTable=get(handles.InputTable,'Data');
    24682505[FileName, PathName] = uigetfile( ...
     
    24762513fill_GUI(Param,handles.series)
    24772514
    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%------------------------------------------------------------------------
    24892518function series_ResizeFcn(hObject, eventdata, handles)
    2490 % --------------------------------------------------------------------
     2519
    24912520%% input table
    24922521set(handles.InputTable,'Unit','pixel')
     
    26702699    set(hwaitbar,'Position',BarPosition)
    26712700end
    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%------------------------------------------------------------------------
    27592703% --- Executes on selection change in ActionExt.
     2704%------------------------------------------------------------------------
    27602705function ActionExt_Callback(hObject, eventdata, handles)
     2706
    27612707ActionExtList=get(handles.ActionExt,'String');
    27622708ActionExt=ActionExtList{get(handles.ActionExt,'Value')};
     
    27822728            compile(ActionName,TransformPath)
    27832729            cd(currentdir)
    2784         end
    2785        
     2730        end       
    27862731    else
    27872732        sh_file_info=dir(fullfile(get(handles.ActionPath,'String'),[ActionName '.sh']));
     
    28522797end
    28532798menu=menu(1:imax);
    2854 
Note: See TracChangeset for help on using the changeset viewer.