Changeset 393

Show
Ignore:
Timestamp:
06/19/09 17:57:54 (15 years ago)
Author:
smidl
Message:

merger_mx works!

Location:
applications/bdmtoolbox/mex
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • applications/bdmtoolbox/mex/CMakeLists.txt

    r391 r393  
    1313 
    1414MEX(merger_mx) 
     15EXEC(merger) 
    1516MEX(config2mxstruct) 
    1617MEX(mxstruct2config) 
  • applications/bdmtoolbox/mex/merger_mx.cpp

    r391 r393  
    2525 
    2626        // LOAD CONFIG 
    27         UImxArray Src; 
    28         Src.addList(input[0],"Sources"); 
     27        UImxArray Cfg; 
     28        Cfg.addList(input[0],"Sources"); 
     29        Cfg.addGroup(input[1],"Support"); 
     30        Cfg.addGroup(input[2],"Merger"); 
     31 
     32        //DBG 
     33        Cfg.writeFile("merger_mx.cfg"); 
    2934         
    30         UImxArray Sup (input[1]); 
    31         UImxArray Mer (input[2]); 
    3235        // Sources 
    3336        Array<mpdf*> Sources; 
    3437        //abuse Mer to store sources 
    35  
    36         Setting& _Sources=Src.lookup("Sources"); 
     38        Setting& _Sources=Cfg.lookup("Sources"); 
    3739        int Slen=_Sources.getLength(); 
    3840        Sources.set_size(Slen); 
    3941        for (int i=0; i<Slen; i++){ 
    40                 mpdf* mtmp = UI::build<mpdf>(_Sources,i); 
    41                 if (mtmp) {  
     42                try{ 
     43                        mpdf* mtmp = UI::build<mpdf>(_Sources,i); 
    4244                        Sources(i)=mtmp; 
    43                 } else{ // source is not mpdf 
    44                         epdf* etmp = UI::build<epdf>(_Sources,i); 
    45                         if (etmp){ 
    46                                 Sources(i) = new mepdf(etmp, true); 
     45                } 
     46                catch (UIbuildException e){ 
     47                        // it is not mpdf - see if it is epdf 
     48                        try { 
     49                                epdf* etmp = UI::build<epdf>(_Sources,i); 
     50                                if (etmp){ 
     51                                        Sources(i) = new mepdf(etmp, true); 
     52                                } 
     53                                 
    4754                        } 
     55                        catch (...) {it_error("no mpdfs or epdfs found!");} 
    4856                } 
    4957 
    5058        } 
    5159 
    52         merger_base* Merger=UI::build<merger_base>(Mer.getRoot()); 
     60        merger_base* Merger=UI::build<merger_base>(Cfg,"Merger"); 
    5361 
    5462        // Support 
    55         Setting & _Supp=Sup.getRoot(); 
     63        Setting & _Supp=Cfg.lookup("Support"); 
    5664         
     65        if (_Supp.exists("grid") &&  _Supp.exists("nbins")) { 
    5766        Array<vec> bounds (0); 
    5867        UI::get (bounds, _Supp, "grid"); 
    5968        ivec nbins(0); 
    6069        UI::get (nbins, _Supp, "nbins"); 
     70        Merger->set_support (bounds,nbins); 
    6171         
    62         epdf *g0=UI::build<epdf> (_Supp, "pdf"); 
    63         int npoints=100; 
    64         _Supp.lookupValue("nsamples",npoints); 
    65          
     72        }else { 
     73                if (_Supp.exists("pdf") &&  _Supp.exists("nsamples")){ 
     74                        epdf *g0=UI::build<epdf> (_Supp, "pdf"); 
     75                        int npoints=100; 
     76                        _Supp.lookupValue("nsamples",npoints); 
     77                        Merger->set_support (*g0,npoints); 
     78                        delete g0;       
     79                } 
     80                else it_error("Use either [grid,nbins] or [pdf,nsamples]."); 
     81        } 
    6682// COMPUTE RESULTS 
    6783        Merger->set_sources(Sources,true); // takes care of deletion of sources 
    68         if (bounds.length() > 0 && nbins.length()>0) { 
    69                 Merger->set_support (bounds,nbins); 
    70         } else { 
    71                 if (g0) { 
    72                         Merger->set_support (*g0,npoints); 
    73                         delete g0; 
    74                 } 
    75         } 
    7684        Merger->merge(); 
    7785