Changeset 456


Ignore:
Timestamp:
05/15/09 15:09:21 (16 years ago)
Author:
jschierm
Message:

Extraction of file-parsing sections into method-independent functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/m/solutions/dakota/dakota_out_parse.m

    r1 r456  
    4747display(sprintf('Dakota method=%s.',method));
    4848
    49 scm =[];
    50 pcm =[];
    51 srcm=[];
    52 prcm=[];
     49scm =struct([]);
     50pcm =struct([]);
     51srcm=struct([]);
     52prcm=struct([]);
    5353
    5454%%  switch according to the Dakota method
     
    175175function [dresp,scm,pcm,srcm,prcm]=nond_samp(fidi)
    176176
    177 ieof=0;
    178 
    179 %%  loop through the file to find the Dakota statistics
     177%  loop through the file to find the number of function evaluations
     178
     179[nfeval]=nfeval_read(fidi);
     180
     181%  loop through the file to find the number of samples
     182
     183[nsamp]=nsamp_read(fidi);
     184
     185%  loop through the file to find the moments
     186
     187[dresp]=moments_read(fidi,struct([]));
     188
     189%  loop through the file to find the confidence intervals
     190
     191[dresp]=cis_read(fidi,dresp);
     192
     193%  loop through the file to find the probabilities
     194
     195[dresp]=cdfs_read(fidi,dresp);
     196
     197%  loop through the file to find the scm
     198
     199[scm]=corrmat_read(fidi,'Simple Correlation Matrix');
     200
     201%  loop through the file to find the pcm
     202
     203[pcm]=corrmat_read(fidi,'Partial Correlation Matrix');
     204
     205%  loop through the file to find the srcm
     206
     207[srcm]=corrmat_read(fidi,'Simple Rank Correlation Matrix');
     208
     209%  loop through the file to find the prcm
     210
     211[prcm]=corrmat_read(fidi,'Partial Rank Correlation Matrix');
     212
     213end
     214
     215%%  function to find and read the number of samples
     216
     217function [nsamp]=nsamp_read(fidi)
    180218
    181219[fline]=findline(fidi,'Statistics based on ');
     
    186224[ntokens,tokens]=fltokens(fline);
    187225nsamp=tokens{1}{4};
    188 display(sprintf('Dakota samples=%d.',nsamp));
    189 
    190 %%  loop through the file to find the moments
     226display(sprintf('  Dakota samples=%d.',nsamp));
     227
     228end
     229
     230%%  function to find and read the moments
     231
     232function [dresp]=moments_read(fidi,dresp)
    191233
    192234[fline]=findline(fidi,'Moments for each response function');
     
    195237end
    196238
    197 display('Reading moments for each response function:');
    198 ndresp=0;
    199 
    200 while ~ieof
     239display('Reading moments for response functions:');
     240
     241while 1
     242    fline=fgetl(fidi);
     243    if isempty(fline)
     244        break;
     245    end
     246    [ntokens,tokens]=fltokens(fline);
     247   
     248%  add new response function and moments
     249
     250    dresp(end+1).descriptor=tokens{1}{ 1};
     251    display(sprintf('  %s',dresp(end).descriptor));
     252    dresp(end  ).mean      =tokens{1}{ 4};
     253    dresp(end  ).stddev    =tokens{1}{ 8};
     254    dresp(end  ).coefvar   =tokens{1}{13};
     255end
     256
     257display(sprintf('  Number of Dakota response functions=%d.',...
     258    length(dresp)));
     259
     260end
     261
     262%%  function to find and read the confidence intervals
     263
     264function [dresp]=cis_read(fidi,dresp)
     265
     266[fline]=findline(fidi,...
     267    '95% confidence intervals for each response function');
     268if ~ischar(fline)
     269    return
     270end
     271
     272display('Reading 95% confidence intervals for response functions:');
     273
     274while 1
     275    fline=fgetl(fidi);
     276    if isempty(fline)
     277        break;
     278    end
     279    [ntokens,tokens]=fltokens(fline);
     280   
     281%  find response function associated with confidence intervals
     282
     283    idresp=0;
     284    for i=1:length(dresp)
     285        if strcmpi(tokens{1}{ 1},dresp(i).descriptor)
     286            idresp=i;
     287            break;
     288        end
     289    end
     290    if ~idresp
     291        idresp=length(dresp)+1;
     292        dresp(idresp).descriptor=tokens{1}{ 1};
     293        display(sprintf('  %s',dresp(idresp).descriptor));
     294    end
     295
     296%  add confidence intervals to response functions
     297
     298    dresp(i).meanci  (1,1)=tokens{1}{ 5};
     299    dresp(i).meanci  (2,1)=tokens{1}{ 6};
     300    dresp(i).stddevci(1,1)=tokens{1}{12};
     301    dresp(i).stddevci(2,1)=tokens{1}{13};
     302end
     303
     304display(sprintf('  Number of Dakota response functions=%d.',...
     305    length(dresp)));
     306
     307end
     308
     309%%  function to find and read the cdf's
     310
     311function [dresp]=cdfs_read(fidi,dresp)
     312
     313[fline]=findline(fidi,'Probabilities for each response function');
     314if ~ischar(fline)
     315    return
     316end
     317
     318display('Reading CDF''s for response functions:');
     319
     320while ~isempty(fline)
    201321    fline=fgetl(fidi);
    202322    if ~ischar(fline)
    203         ieof=1;
    204         break;
    205     end
    206     if isempty(fline)
    207         break;
    208     end
    209    
    210 %  add new response function and moments
    211 
    212     ndresp=ndresp+1;
    213     [ntokens,tokens]=fltokens(fline);
    214     dresp(ndresp).descriptor=tokens{1}{ 1};
    215     display(sprintf('    %s',dresp(ndresp).descriptor));
    216     dresp(ndresp).mean      =tokens{1}{ 4};
    217     dresp(ndresp).stddev    =tokens{1}{ 8};
    218     dresp(ndresp).coefvar   =tokens{1}{13};
    219 end
    220 
    221 display(sprintf('Number of Dakota response functions=%d.',ndresp));
    222 
    223 %%  loop through the file to find the confidence intervals
    224 
    225 [fline]=findline(fidi,...
    226     '95% confidence intervals for each response function');
    227 if ~ischar(fline)
    228     return
    229 end
    230 
    231 display('Reading 95% confidence intervals for each response function.');
    232 
    233 while ~ieof
    234     fline=fgetl(fidi);
    235     if ~ischar(fline)
    236         ieof=1;
    237         break;
    238     end
    239     if isempty(fline)
    240         break;
    241     end
    242    
    243 %  add confidence intervals to response functions
    244 
    245     [ntokens,tokens]=fltokens(fline);
    246     for i=1:ndresp
    247         if strcmpi(tokens{1}{ 1},dresp(i).descriptor)
    248             dresp(i).meanci  (1,1)=tokens{1}{ 5};
    249             dresp(i).meanci  (2,1)=tokens{1}{ 6};
    250             dresp(i).stddevci(1,1)=tokens{1}{12};
    251             dresp(i).stddevci(2,1)=tokens{1}{13};
    252             break;
    253         end
    254     end
    255 end
    256 
    257 %%  loop through the file to find the probabilities
    258 
    259 [fline]=findline(fidi,'Probabilities for each response function');
    260 if ~ischar(fline)
    261     return
    262 end
    263 
    264 display('Reading CDF''s for each response function.');
    265 
    266 while ~ieof && ~isempty(fline)
    267     fline=fgetl(fidi);
    268     if ~ischar(fline)
    269         ieof=1;
    270323        break;
    271324    end
     
    279332
    280333        idresp=0;
    281         for i=1:ndresp
     334        for i=1:length(dresp)
    282335            if strcmpi(tokens{1}{ 6},dresp(i).descriptor)
    283336                idresp=i;
     
    285338            end
    286339        end
    287    
     340        if ~idresp
     341            idresp=length(dresp)+1;
     342            dresp(idresp).descriptor=tokens{1}{ 6};
     343            display(sprintf('  %s',dresp(idresp).descriptor));
     344        end
     345
    288346%  skip column headings of cdf
    289347
     
    296354        icdf=0;
    297355        while ~isempty(fline) && ...
    298                 ~strncmpi(fline,'Cumulative Distribution Function',32)
     356              ~strncmpi(fline,'Cumulative Distribution Function',32)
    299357            [ntokens,tokens]=fltokens(fline);
    300358            icdf=icdf+1;
     
    313371end
    314372
    315 %%  loop through the file to find the scm
    316 
    317 [fline]=findline(fidi,'Simple Correlation Matrix');
    318 if ~ischar(fline)
    319     scm=[];
    320     return
    321 end
    322 
    323 display('Reading simple correlation matrix.');
    324 scm=corrmat(fidi,fline);
    325 
    326 %%  loop through the file to find the pcm
    327 
    328 [fline]=findline(fidi,'Partial Correlation Matrix');
    329 if ~ischar(fline)
    330     pcm=[];
    331     return
    332 end
    333 
    334 display('Reading partial correlation matrix.');
    335 pcm=corrmat(fidi,fline);
    336 
    337 %%  loop through the file to find the srcm
    338 
    339 [fline]=findline(fidi,'Simple Rank Correlation Matrix');
    340 if ~ischar(fline)
    341     srcm=[];
    342     return
    343 end
    344 
    345 display('Reading simple rank correlation matrix.');
    346 srcm=corrmat(fidi,fline);
    347 
    348 %%  loop through the file to find the prcm
    349 
    350 [fline]=findline(fidi,'Partial Rank Correlation Matrix');
    351 if ~ischar(fline)
    352     prcm=[];
    353     return
    354 end
    355 
    356 display('Reading partial rank correlation matrix.');
    357 prcm=corrmat(fidi,fline);
    358 
    359 end
    360 
    361 %%  function to read a correlation matrix at current file position
    362 
    363 function [cmat]=corrmat(fidi,fline)
    364 
    365 ieof=0;
     373display(sprintf('  Number of Dakota response functions=%d.',...
     374    length(dresp)));
     375
     376end
     377
     378%%  function to find and read a correlation matrix
     379
     380function [cmat]=corrmat_read(fidi,cmstr)
     381
     382[fline]=findline(fidi,cmstr);
     383if ~ischar(fline)
     384    cmat=struct([]);
     385    return
     386end
     387
     388display(['Reading ''' fline '''.']);
     389
    366390cmat.title=fline;
    367391
    368 while ~ieof && ~isempty(fline)
     392while ~isempty(fline)
    369393    fline=fgetl(fidi);
    370394    if ~ischar(fline)
    371         ieof=1;
    372395        break;
    373396    end
     
    384407    end
    385408   
    386 %  process rows of matrix
     409%  process rows of matrix, reading until blank line
    387410
    388411    nrow=0;
    389     while ~ieof
     412    while 1
    390413        fline=fgetl(fidi);
    391414        if isempty(fline)
     
    413436function [dresp]=nond_locrel(fidi)
    414437
     438%  loop through the file to find the number of function evaluations
     439
     440[nfeval]=nfeval_read(fidi);
     441
     442%  loop through the file to find the statistics
     443
     444[dresp]=mvstats_read(fidi,struct([]));
     445
     446end
     447
     448%%  function to find and read the number of function evaluations
     449
     450function [nfeval]=nfeval_read(fidi)
     451
     452[fline]=findline(fidi,'<<<<< Function evaluation summary');
     453if ~ischar(fline)
     454    return
     455end
     456
     457[ntokens,tokens]=fltokens(fline);
     458nfeval=tokens{1}{5};
     459display(sprintf('  Dakota function evaluations=%d.',nfeval));
     460
     461end
     462
     463%%  function to find and read the MV statistics
     464
     465function [dresp]=mvstats_read(fidi,dresp)
     466
    415467ieof=0;
    416468
    417 %%  loop through the file to find the Dakota statistics
    418 
    419 [fline]=findline(fidi,'<<<<< Function evaluation summary');
    420 if ~ischar(fline)
    421     return
    422 end
    423 
    424 [ntokens,tokens]=fltokens(fline);
    425 nfunc=tokens{1}{5};
    426 display(sprintf('Dakota function evaluations=%d.',nfunc));
    427 
    428 %%  loop through the file to find the statistics
    429 
    430469[fline]=findline(fidi,'MV Statistics for ');
    431470if ~ischar(fline)
     
    433472end
    434473
    435 display('Reading MV statistics for each response function:');
     474display('Reading MV statistics for response functions:');
    436475ndresp=0;
    437476
     
    441480%  add new response function and moments
    442481
    443     ndresp=ndresp+1;
    444482    [ntokens,tokens]=fltokens(fline);
    445     dresp(ndresp).descriptor=tokens{1}{4};
    446     display(sprintf('    %s',dresp(ndresp).descriptor));
     483    dresp(end+1).descriptor=tokens{1}{4};
     484    display(sprintf('  %s',dresp(end).descriptor));
    447485    fline=fgetl(fidi);
    448486    [ntokens,tokens]=fltokens(fline);
    449     dresp(ndresp).mean      =tokens{1}{5};
     487    dresp(end  ).mean      =tokens{1}{5};
    450488    fline=fgetl(fidi);
    451489    [ntokens,tokens]=fltokens(fline);
    452     dresp(ndresp).stddev    =tokens{1}{7};
     490    dresp(end  ).stddev    =tokens{1}{7};
    453491
    454492%  read and add importance factors to response function
     
    465503        [ntokens,tokens]=fltokens(fline);
    466504        idvar=idvar+1;
    467         dresp(ndresp).desvar(idvar,1)=cellstr(tokens{1}{5});
    468         dresp(ndresp).impfac(idvar,1)=        tokens{1}{7};
     505        dresp(end).desvar(idvar,1)=cellstr(tokens{1}{5});
     506        dresp(end).impfac(idvar,1)=        tokens{1}{7};
    469507
    470508        fline=fgetl(fidi);
     
    478516
    479517    if ~idvar
    480         display('      Importance Factors not available.');
    481         dresp(ndresp).desvar={};
    482         dresp(ndresp).impfac=[];
     518        display('    Importance Factors not available.');
     519        dresp(end).desvar={};
     520        dresp(end).impfac=[];
    483521        while ~ieof && ...
    484522                ~strncmpi(fline,'Cumulative Distribution Function',32) && ...
     
    504542
    505543        idresp=0;
    506         for i=1:ndresp
    507             if strcmpi(tokens{1}{6},dresp(i).descriptor)
     544        for i=1:length(dresp)
     545            if strcmpi(tokens{1}{ 6},dresp(i).descriptor)
    508546                idresp=i;
    509547                break;
    510548            end
     549        end
     550        if ~idresp
     551            idresp=length(dresp)+1;
     552            dresp(idresp).descriptor=tokens{1}{ 6};
     553            display(sprintf('  %s',dresp(idresp).descriptor));
    511554        end
    512555   
     
    540583
    541584    if ~icdf
    542         display('      Cumulative Distribution Function not available.');
     585        display('    Cumulative Distribution Function not available.');
    543586        dresp(ndresp).cdf=[];
    544587        while ~ieof && ...
     
    555598end
    556599
    557 display(sprintf('Number of Dakota response functions=%d.',ndresp));
     600display(sprintf('  Number of Dakota response functions=%d.',...
     601    length(dresp)));
    558602
    559603end
     
    571615display(['  ' deblank(fline)]);
    572616
    573 [fline]=findline(fidi,'<<<<< Function evaluation summary');
    574 if ~ischar(fline)
    575     return
    576 end
    577 display(['  ' deblank(fline)]);
    578 
    579 [ntokens,tokens]=fltokens(fline);
    580 nfunc=tokens{1}{5};
    581 % display(sprintf('Dakota function evaluations=%d.',nfunc));
    582 
    583 %%  loop through the file to find the best evaluation
     617%  loop through the file to find the number of function evaluations
     618
     619[nfeval]=nfeval_read(fidi);
     620
     621%  loop through the file to find the best evaluation
     622
     623[dresp]=best_read(fidi,struct([]));
     624
     625end
     626
     627%%  function to find and read the best evaluation
     628
     629function [dresp]=best_read(fidi,dresp)
    584630
    585631[fline]=findline(fidi,'<<<<< Best ');
     
    587633    return
    588634end
    589 dresp.best=[];
     635dresp(end+1).best=[];
    590636
    591637display('Reading values for best function evaluation:');
Note: See TracChangeset for help on using the changeset viewer.