Changeset 21662
- Timestamp:
- 04/06/17 13:15:27 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/qmu/dakota_out_parse.m
r19672 r21662 1 function [method,dresp,scm,pcm,srcm,prcm]=dakota_out_parse(filei) % {{{ 1 2 % 2 3 % read a Dakota .out or .dat output file and parse it. … … 46 47 % to foreign countries or providing access to foreign persons." 47 48 % 48 function [method,dresp,scm,pcm,srcm,prcm]=dakota_out_parse(filei) 49 50 if ~nargin 51 help dakota_out_parse 52 return 53 end 54 55 if ~exist('filei' ,'var') || isempty(filei) 56 filei=input('Input file? ','s'); 57 end 58 fidi=fopen(sprintf('%s',filei),'r'); 59 if (fidi < 0) 60 error('''%s'' could not be opened.',filei); 61 end 62 63 %% check the first line for the Dakota tabular output file 64 65 method=[]; 66 fline=fgetl(fidi); 67 if ~ischar(fline) 68 error('File ''%s'' is empty.',filei); 69 end 70 71 if strncmpi(fline,'%eval_id',8) 72 method='unknown'; 73 [dresp]=dak_tab_out(fidi,fline); 74 return 75 else 76 fseek(fidi,0,'bof'); 77 end 78 79 %% loop through the file to find the Dakota method name 80 81 [fline]=findline(fidi,'methodName = '); 82 if ~ischar(fline) 83 %do nothing 84 else 85 % display([' ' deblank(fline)]); 49 50 if ~nargin 51 help dakota_out_parse 52 return 53 end 54 55 if ~exist('filei' ,'var') || isempty(filei) 56 filei=input('Input file? ','s'); 57 end 58 fidi=fopen(sprintf('%s',filei),'r'); 59 if (fidi < 0) 60 error('''%s'' could not be opened.',filei); 61 end 62 63 %% check the first line for the Dakota tabular output file 64 65 method=[]; 66 fline=fgetl(fidi); 67 if ~ischar(fline) 68 error('File ''%s'' is empty.',filei); 69 end 70 71 if strncmpi(fline,'%eval_id',8) 72 method='unknown'; 73 [dresp]=dak_tab_out(fidi,fline); 74 return 75 else 76 fseek(fidi,0,'bof'); 77 end 78 79 %% loop through the file to find the Dakota method name 80 81 [fline]=findline(fidi,'methodName = '); 82 if ~ischar(fline) 83 %do nothing 84 else 85 % display([' ' deblank(fline)]); 86 87 [ntokens,tokens]=fltokens(fline); 88 method=tokens{1}{3}; 89 display(sprintf('Dakota methodName=''%s''.',method)); 90 end 91 92 dresp=struct([]); 93 scm =struct([]); 94 pcm =struct([]); 95 srcm=struct([]); 96 prcm=struct([]); 97 98 %% loop through the file to find the function evaluation summary 99 100 fline=''; 101 [nfeval]=nfeval_read(fidi,fline); 102 fline=fgetl(fidi); 103 104 %% process each results section based on content of the file 105 106 while ischar(fline) 107 % ipos=ftell(fidi); 108 if isempty(fline) 109 elseif strncmp(fline,'<<<<< Function evaluation summary',33) 110 [nfeval]=nfeval_read(fidi,fline); 111 elseif strncmp(fline,'Statistics based on ',20) 112 [nsamp]=nsamp_read(fidi,fline); 113 elseif strncmp(fline,'Moments for each response function',34) 114 [dresp]=moments_read(fidi,dresp,fline); 115 elseif strncmp(fline,'Moment-based statistics for each response function',50) 116 [dresp]=mbstats_read(fidi,dresp,fline); 117 elseif strncmp(fline,'95% confidence intervals for each response function',51) 118 [dresp]=cis_read(fidi,dresp,fline); 119 elseif strncmp(fline,'Probabilities for each response function',40) || ... 120 strncmp(fline,'Level mappings for each response function',41) 121 [dresp]=cdfs_read(fidi,dresp,fline); 122 elseif strncmp(fline,'Probability Density Function (PDF) histograms for each response function',72) 123 [dresp]=pdfs_read(fidi,dresp,fline); 124 elseif strncmp(fline,'Simple Correlation Matrix',25) 125 [scm]=corrmat_read(fidi,'Simple Correlation Matrix',fline); 126 elseif strncmp(fline,'Partial Correlation Matrix',26) 127 [pcm]=corrmat_read(fidi,'Partial Correlation Matrix',fline); 128 elseif strncmp(fline,'Simple Rank Correlation Matrix',30) 129 [srcm]=corrmat_read(fidi,'Simple Rank Correlation Matrix',fline); 130 elseif strncmp(fline,'Partial Rank Correlation Matrix',31) 131 [prcm]=corrmat_read(fidi,'Partial Rank Correlation Matrix',fline); 132 elseif strncmp(fline,'MV Statistics for ',18) 133 [dresp]=mvstats_read(fidi,dresp,fline); 134 elseif strncmp(fline,'<<<<< Best ',11) 135 [dresp]=best_read(fidi,dresp,fline); 136 elseif strncmp(fline,'The following lists volumetric uniformity measures',50) 137 [dresp]=vum_read(fidi,dresp,fline); 138 elseif strncmp(fline,'<<<<< Iterator ',15) && ... 139 (length(fline) > 26) && ... 140 ~isempty(strfind(fline(16:end),' completed.')) 141 [method]=itcomp_read(fidi,fline); 142 elseif strncmp(fline,'-----',5) 143 else 144 display(['Unexpected line: ' deblank(fline)]); 145 end 146 fline=fgetl(fidi); 147 % fseek(fidi,ipos,'bof'); 148 end 149 150 %% loop through the file to verify the end 151 152 % [fline]=findline(fidi,'<<<<< Single Method Strategy completed'); 153 % if ~ischar(fline) 154 % return 155 % end 156 display('End of file successfully reached.'); 157 fclose(fidi); 158 159 end % }}} 160 function [dresp]=dak_tab_out(fidi,fline) % {{{ 161 %% function to parse the dakota tabular output file 162 163 display('Reading Dakota tabular output file.'); 164 165 % process column headings of matrix (skipping eval_id) 166 167 [ntokens,tokens]=fltokens(fline); 168 169 % New file DAKOTA versions>6 170 if strncmpi(fline,'%eval_id interface',18) 171 offset=2; 172 else %DAKOTA versions<6 173 offset=1; 174 end 175 desc=cell (1,ntokens-offset); 176 data=zeros(1,ntokens-offset); 177 178 for i=1:ntokens-offset 179 desc(1,i)=cellstr(tokens{1}{i+offset}); 180 end 181 display(sprintf('Number of columns (Dakota V+R)=%d.',ntokens-2)); 182 183 % process rows of matrix 184 185 nrow=0; 186 while 1 187 fline=fgetl(fidi); 188 if ~ischar(fline) || isempty(fline) 189 break; 190 end 191 [ntokens,tokens]=fltokens(fline); 192 193 % add row values to matrix (skipping eval_id) 194 195 nrow=nrow+1; 196 for i=1:ntokens-offset 197 data(nrow,i)=tokens{1}{i+offset}; 198 end 199 end 200 display(sprintf('Number of rows (Dakota func evals)=%d.',nrow)); 201 202 % calculate statistics 203 204 % since normfit doesn't have a dim argument, and matlab isvector is true 205 % for a 1xn matrix, handle the case of one row explicitly 206 if (size(data,1) > 1) 207 %dmean =mean (data); 208 %dstddev=std (data,0); 209 [dmean,dstddev,dmeanci,dstddevci]=... 210 normfit_issm(data,0.05); 211 else 212 dmean =zeros(1,size(data,2)); 213 dstddev =zeros(1,size(data,2)); 214 dmeanci =zeros(2,size(data,2)); 215 dstddevci=zeros(2,size(data,2)); 216 for i=1:size(data,2) 217 [dmean(1,i),dstddev(1,i),dmeanci(:,i),dstddevci(:,i)]=... 218 normfit_issm(data(:,i),0.05); 219 end 220 end 221 222 dmin =min (data,[],1); 223 dquart1=prctile_issm(data,25,1); 224 dmedian=median (data,1); 225 dquart3=prctile_issm(data,75,1); 226 dmax =max (data,[],1); 227 dmin95=prctile_issm(data,5,1); 228 dmax95=prctile_issm(data,95,1); 229 230 % same as Dakota scm, Excel correl 231 dcorrel=corrcoef(data); 232 233 % divide the data into structures for consistency 234 235 for i=1:length(desc) 236 dresp(i).descriptor=char(desc(i)); 237 dresp(i).sample =data(:,i); 238 dresp(i).mean =dmean(i); 239 dresp(i).stddev =dstddev(i); 240 dresp(i).meanci =dmeanci(:,i); 241 dresp(i).stddevci =dstddevci(:,i); 242 dresp(i).min =dmin(i); 243 dresp(i).quart1 =dquart1(i); 244 dresp(i).median =dmedian(i); 245 dresp(i).quart3 =dquart3(i); 246 dresp(i).max =dmax(i); 247 dresp(i).dmin95 =dmin95(i); 248 dresp(i).dmax95 =dmax95(i); 249 end 250 251 % draw box plot 252 253 % figure 254 % subplot(2,1,1) 255 % plot_boxplot(dresp); 256 257 % draw normal probability plot 258 259 % subplot(2,1,2) 260 % plot_normplot(dresp); 261 262 end % }}} 263 function [nfeval]=nfeval_read(fidi,fline) % {{{ 264 %% function to find and read the number of function evaluations 265 266 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 267 [fline]=findline(fidi,'<<<<< Function evaluation summary'); 268 if ~ischar(fline) 269 nfeval = 0; 270 return 271 end 272 end 273 274 [ntokens,tokens]=fltokens(fline); 275 nfeval=tokens{1}{5}; 276 display(sprintf(' Dakota function evaluations=%d.',nfeval)); 277 278 end % }}} 279 function [nsamp]=nsamp_read(fidi,fline) % {{{ 280 %% function to find and read the number of samples 281 282 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 283 [fline]=findline(fidi,'Statistics based on '); 284 if ~ischar(fline) 285 return 286 end 287 end 288 289 [ntokens,tokens]=fltokens(fline); 290 nsamp=tokens{1}{4}; 291 display(sprintf(' Dakota samples=%d.',nsamp)); 292 293 end % }}} 294 function [dresp]=moments_read(fidi,dresp,fline) % {{{ 295 %% function to find and read the moments 296 297 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 298 [fline]=findline(fidi,'Moments for each response function'); 299 if ~ischar(fline) 300 return 301 end 302 end 303 304 display('Reading moments for response functions:'); 305 306 while 1 307 fline=fgetl(fidi); 308 if isempty(fline) 309 break; 310 end 311 [ntokens,tokens]=fltokens(fline); 312 313 % add new response function and moments 314 315 dresp(end+1).descriptor=tokens{1}{ 1}; 316 display(sprintf(' %s',dresp(end).descriptor)); 317 dresp(end ).mean =tokens{1}{ 4}; 318 dresp(end ).stddev =tokens{1}{ 8}; 319 dresp(end ).coefvar =tokens{1}{13}; 320 end 321 322 display(sprintf(' Number of Dakota response functions=%d.',... 323 length(dresp))); 324 325 end % }}} 326 function [dresp]=mbstats_read(fidi,dresp,fline) % {{{ 327 %% function to find and read the moment-based statistics 328 329 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 330 [fline]=findline(fidi,'Moment-based statistics for each response function'); 331 if ~ischar(fline) 332 return 333 end 334 end 335 336 display('Reading moment-based statistics for response functions:'); 337 338 % skip column headings of moment-based statistics 339 340 fline=fgetl(fidi); 341 342 while 1 343 fline=fgetl(fidi); 344 if isempty(fline) 345 break; 346 end 347 [ntokens,tokens]=fltokens(fline); 348 349 % add new response function and moment-based statistics 350 351 dresp(end+1).descriptor=tokens{1}{ 1}; 352 display(sprintf(' %s',dresp(end).descriptor)); 353 dresp(end ).mean =tokens{1}{ 2}; 354 dresp(end ).stddev =tokens{1}{ 3}; 355 dresp(end ).skewness =tokens{1}{ 4}; 356 dresp(end ).kurtosis =tokens{1}{ 5}; 357 end 358 359 display(sprintf(' Number of Dakota response functions=%d.',... 360 length(dresp))); 361 362 end % }}} 363 function [dresp]=cis_read(fidi,dresp,fline) % {{{ 364 %% function to find and read the confidence intervals 365 366 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 367 [fline]=findline(fidi,... 368 '95% confidence intervals for each response function'); 369 if ~ischar(fline) 370 return 371 end 372 end 373 374 display('Reading 95% confidence intervals for response functions:'); 375 376 while 1 377 fline=fgetl(fidi); 378 if isempty(fline) 379 break; 380 end 381 [ntokens,tokens]=fltokens(fline); 382 383 % check for column headings in Dakota 5.2 384 385 if (ntokens == 4) 386 fline=fgetl(fidi); 387 if isempty(fline) 388 break; 389 end 390 [ntokens,tokens]=fltokens(fline); 391 end 392 393 % find response function associated with confidence intervals 394 395 idresp=0; 396 for i=1:length(dresp) 397 if strcmpi(tokens{1}{ 1},dresp(i).descriptor) 398 idresp=i; 399 break; 400 end 401 end 402 if ~idresp 403 idresp=length(dresp)+1; 404 dresp(idresp).descriptor=tokens{1}{ 1}; 405 display(sprintf(' %s',dresp(idresp).descriptor)); 406 end 407 408 % add confidence intervals to response functions 409 410 if (ntokens == 14) 411 dresp(i).meanci (1,1)=tokens{1}{ 5}; 412 dresp(i).meanci (2,1)=tokens{1}{ 6}; 413 dresp(i).stddevci(1,1)=tokens{1}{12}; 414 dresp(i).stddevci(2,1)=tokens{1}{13}; 415 else 416 dresp(i).meanci (1,1)=tokens{1}{ 2}; 417 dresp(i).meanci (2,1)=tokens{1}{ 3}; 418 dresp(i).stddevci(1,1)=tokens{1}{ 4}; 419 dresp(i).stddevci(2,1)=tokens{1}{ 5}; 420 end 421 end 422 423 display(sprintf(' Number of Dakota response functions=%d.',... 424 length(dresp))); 425 426 end % }}} 427 function [dresp]=cdfs_read(fidi,dresp,fline) % {{{ 428 %% function to find and read the cdf's 429 430 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 431 [fline]=findline(fidi,'Probabilities for each response function'); 432 if ~ischar(fline) 433 [fline]=findline(fidi,'Level mappings for each response function'); 434 if ~ischar(fline) 435 return 436 end 437 end 438 end 439 440 display('Reading CDF''s for response functions:'); 441 442 while ischar(fline) && ~isempty(fline) 443 fline=fgetl(fidi); 444 if ~ischar(fline) 445 break; 446 end 447 448 % process header line of cdf 449 450 while ischar(fline) && ~isempty(fline) 451 [ntokens,tokens]=fltokens(fline); 452 453 % find response function associated with cdf 454 455 idresp=0; 456 for i=1:length(dresp) 457 if strcmpi(tokens{1}{ 6},dresp(i).descriptor) 458 idresp=i; 459 break; 460 end 461 end 462 if ~idresp 463 idresp=length(dresp)+1; 464 dresp(idresp).descriptor=tokens{1}{ 6}; 465 display(sprintf(' %s',dresp(idresp).descriptor)); 466 end 467 468 % skip column headings of cdf 469 470 fline=fgetl(fidi); 471 fline=fgetl(fidi); 472 473 % read and add cdf table to response function 474 475 fline=fgetl(fidi); 476 icdf=0; 477 while ischar(fline) && ~isempty(fline) && ... 478 ~strncmpi(fline,'Cumulative Distribution Function',32) 479 [ntokens,tokens]=fltokens(fline); 480 icdf=icdf+1; 481 dresp(idresp).cdf(icdf,1:4)=NaN; 482 % in later versions of Dakota, uncalculated columns are now blank 483 itoken=0; 484 for i=1:length(fline)/19 485 if ~isempty(deblank(fline((i-1)*19+1:i*19))) 486 itoken=itoken+1; 487 dresp(idresp).cdf(icdf,i)=tokens{1}{itoken}; 488 end 489 end 490 fline=fgetl(fidi); 491 end 492 end 493 end 494 495 display(sprintf(' Number of Dakota response functions=%d.',... 496 length(dresp))); 497 498 end % }}} 499 function [dresp]=pdfs_read(fidi,dresp,fline) % {{{ 500 %% function to find and read the pdf's 501 502 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 503 [fline]=findline(fidi,'Probability Density Function (PDF) histograms for each response function'); 504 if ~ischar(fline) 505 return 506 end 507 end 508 509 display('Reading PDF''s for response functions:'); 510 511 while ischar(fline) && ~isempty(fline) 512 fline=fgetl(fidi); 513 if ~ischar(fline) 514 break; 515 end 516 517 % process header line of pdf 518 519 while ischar(fline) && ~isempty(fline) 520 [ntokens,tokens]=fltokens(fline); 521 522 % find response function associated with pdf 523 524 idresp=0; 525 for i=1:length(dresp) 526 if strcmpi(tokens{1}{ 3},dresp(i).descriptor) 527 idresp=i; 528 break; 529 end 530 end 531 if ~idresp 532 idresp=length(dresp)+1; 533 dresp(idresp).descriptor=tokens{1}{ 3}; 534 display(sprintf(' %s',dresp(idresp).descriptor)); 535 end 536 537 % skip column headings of pdf 538 539 fline=fgetl(fidi); 540 fline=fgetl(fidi); 541 542 % read and add pdf table to response function 543 544 fline=fgetl(fidi); 545 ipdf=0; 546 while ischar(fline) && ~isempty(fline) && ... 547 ~strncmpi(fline,'PDF for', 7) 548 [ntokens,tokens]=fltokens(fline); 549 ipdf=ipdf+1; 550 dresp(idresp).pdf(ipdf,1:3)=NaN; 551 for i=1:3 552 dresp(idresp).pdf(ipdf,i)=tokens{1}{i}; 553 end 554 fline=fgetl(fidi); 555 end 556 end 557 end 558 559 display(sprintf(' Number of Dakota response functions=%d.',... 560 length(dresp))); 561 562 end % }}} 563 function [cmat]=corrmat_read(fidi,cmstr,fline) % {{{ 564 %% function to find and read a correlation matrix 565 566 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 567 [fline]=findline(fidi,cmstr); 568 if ~ischar(fline) 569 cmat=struct([]); 570 return 571 end 572 end 573 574 display(['Reading ''' fline '''.']); 575 576 cmat.title=fline; 577 578 while ~isempty(fline) 579 fline=fgetl(fidi); 580 if ~ischar(fline) 581 break; 582 end 583 584 % process column headings of matrix 585 586 [ntokens,tokens]=fltokens(fline); 587 cmat.column=cell(1,ntokens); 588 cmat.row =cell(1,1); 589 cmat.matrix=zeros(1,ntokens); 590 591 for i=1:ntokens 592 cmat.column(1,i)=cellstr(tokens{1}{i}); 593 end 594 595 % process rows of matrix, reading until blank line 596 597 nrow=0; 598 while 1 599 fline=fgetl(fidi); 600 if isempty(fline) 601 break; 602 end 603 [ntokens,tokens]=fltokens(fline); 604 605 % add row heading to matrix 606 607 nrow=nrow+1; 608 cmat.row (nrow,1)=cellstr(tokens{1}{1}); 609 610 % add row values to matrix 611 612 for i=2:ntokens 613 cmat.matrix(nrow,i-1)=tokens{1}{i}; 614 end 615 end 616 end 617 618 end % }}} 619 function [dresp]=mvstats_read(fidi,dresp,fline) % {{{ 620 %% function to find and read the MV statistics 621 622 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 623 [fline]=findline(fidi,'MV Statistics for '); 624 if ~ischar(fline) 625 return 626 end 627 end 628 629 display('Reading MV statistics for response functions:'); 630 ndresp=0; 631 632 while ischar(fline) && ~isempty(fline) && ... 633 strncmpi(fline,'MV Statistics for ',18) 634 635 % add new response function and moments 636 637 [ntokens,tokens]=fltokens(fline); 638 dresp(end+1).descriptor=tokens{1}{4}; 639 display(sprintf(' %s',dresp(end).descriptor)); 640 fline=fgetl(fidi); 641 [ntokens,tokens]=fltokens(fline); 642 dresp(end ).mean =tokens{1}{5}; 643 fline=fgetl(fidi); 644 [ntokens,tokens]=fltokens(fline); 645 dresp(end ).stddev =tokens{1}{7}; 646 647 % read and add importance factors to response function 648 649 idvar=0; 650 fline=fgetl(fidi); 651 if ~ischar(fline) 652 break; 653 end 654 655 while ischar(fline) && ~isempty(fline) && ... 656 strncmpi(fline,' Importance Factor for variable ',33) 657 [ntokens,tokens]=fltokens(fline); 658 idvar=idvar+1; 659 dresp(end).var (idvar,1)=cellstr(tokens{1}{ 5}); 660 dresp(end).impfac(idvar,1)= tokens{1}{ 7}; 661 if (ntokens >= 10) 662 dresp(end).sens (idvar,1)= tokens{1}{10}; 663 else 664 dresp(end).sens (idvar,1)=NaN; 665 end 666 667 fline=fgetl(fidi); 668 end 669 670 % if importance factors missing, skip to cdf 671 672 if ~idvar 673 display(' Importance Factors not available.'); 674 dresp(end).var ={}; 675 dresp(end).impfac=[]; 676 dresp(end).sens =[]; 677 while ischar(fline) && ... 678 ~strncmpi(fline,'Cumulative Distribution Function',32) && ... 679 ~strncmpi(fline,'MV Statistics for ',18) && ... 680 ~strncmp (fline,'-',1) 681 fline=fgetl(fidi); 682 end 683 end 684 685 % process header line of cdf 686 687 icdf=0; 688 689 while ischar(fline) && ~isempty(fline) && ... 690 strncmpi(fline,'Cumulative Distribution Function',32) 691 [ntokens,tokens]=fltokens(fline); 692 693 % find response function associated with cdf 694 695 idresp=0; 696 for i=1:length(dresp) 697 if strcmpi(tokens{1}{ 6},dresp(i).descriptor) 698 idresp=i; 699 break; 700 end 701 end 702 if ~idresp 703 idresp=length(dresp)+1; 704 dresp(idresp).descriptor=tokens{1}{ 6}; 705 display(sprintf(' %s',dresp(idresp).descriptor)); 706 end 707 708 % skip column headings of cdf 709 710 fline=fgetl(fidi); 711 fline=fgetl(fidi); 712 713 % read and add cdf table to response function 714 715 fline=fgetl(fidi); 716 while ~isempty(fline) && ... 717 ~strncmpi(fline,'MV Statistics for ',18) && ... 718 ~strncmp (fline,'-',1) 719 [ntokens,tokens]=fltokens(fline); 720 icdf=icdf+1; 721 dresp(idresp).cdf(icdf,1)=tokens{1}{1}; 722 dresp(idresp).cdf(icdf,2)=tokens{1}{2}; 723 if (ntokens == 4) 724 dresp(idresp).cdf(icdf,3)=tokens{1}{3}; 725 dresp(idresp).cdf(icdf,4)=tokens{1}{4}; 726 else 727 dresp(idresp).cdf(icdf,3)=NaN; 728 dresp(idresp).cdf(icdf,4)=NaN; 729 end 730 fline=fgetl(fidi); 731 end 732 end 733 734 % if cdf missing, skip to end of response function 735 736 if ~icdf 737 display(' Cumulative Distribution Function not available.'); 738 dresp(ndresp).cdf=[]; 739 while ischar(fline) && ... 740 ~strncmpi(fline,'MV Statistics for ',18) && ... 741 ~strncmp (fline,'-',1) 742 fline=fgetl(fidi); 743 end 744 end 745 746 end 747 748 display(sprintf(' Number of Dakota response functions=%d.',... 749 length(dresp))); 750 751 end % }}} 752 function [dresp]=best_read(fidi,dresp,fline) % {{{ 753 %% function to find and read the best evaluation 754 755 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 756 [fline]=findline(fidi,'<<<<< Best '); 757 if ~ischar(fline) 758 return 759 end 760 end 761 762 if isempty(dresp) 763 dresp(end+1).best=[]; 764 end 765 display('Reading values for best function evaluation:'); 766 767 while ischar(fline) && ~isempty(fline) && ... 768 strncmpi(fline,'<<<<< Best ',11) 769 [ntokens,tokens]=fltokens(fline); 770 771 % read and add best parameter(s) 772 773 if strncmpi(cellstr(tokens{1}{3}),'parameter', 9) 774 display([' ' deblank(fline)]); 775 776 fline=fgetl(fidi); 777 dresp.best.param =[]; 778 dresp.best.descriptor={}; 779 780 while ischar(fline) && ~isempty(fline) && ... 781 ~strncmpi(fline,'<<<<< Best ',11) 782 [ntokens,tokens]=fltokens(fline); 783 dresp.best.param (end+1,1)= tokens{1}{1}; 784 dresp.best.descriptor(end+1,1)=cellstr(tokens{1}{2}); 785 fline=fgetl(fidi); 786 end 787 788 % read and add best objective function(s) 789 790 elseif strncmpi(cellstr(tokens{1}{3}),'objective', 9) && ... 791 strncmpi(cellstr(tokens{1}{4}),'function' , 8) 792 display([' ' deblank(fline)]); 793 794 fline=fgetl(fidi); 795 dresp.best.of=[]; 796 797 while ischar(fline) && ~isempty(fline) && ... 798 ~strncmpi(fline,'<<<<< Best ',11) 799 [ntokens,tokens]=fltokens(fline); 800 dresp.best.of(end+1,1)= tokens{1}{1}; 801 fline=fgetl(fidi); 802 end 803 804 % read and add best residual norms 805 806 elseif strncmpi(cellstr(tokens{1}{3}),'residual', 8) && ... 807 strncmpi(cellstr(tokens{1}{4}),'norm' , 4) 808 display([' ' deblank(fline)]); 809 dresp.best.norm = tokens{1}{ 6}; 810 dresp.best.hnormsq= tokens{1}{11}; 811 812 fline=fgetl(fidi); 813 814 while ischar(fline) && ~isempty(fline) && ... 815 ~strncmpi(fline,'<<<<< Best ',11) 816 fline=fgetl(fidi); 817 end 818 819 % read and add best residual term(s) 820 821 elseif strncmpi(cellstr(tokens{1}{3}),'residual', 8) && ... 822 strncmpi(cellstr(tokens{1}{4}),'term' , 4) 823 display([' ' deblank(fline)]); 824 825 fline=fgetl(fidi); 826 dresp.best.res=[]; 827 828 while ischar(fline) && ~isempty(fline) && ... 829 ~strncmpi(fline,'<<<<< Best ',11) 830 [ntokens,tokens]=fltokens(fline); 831 dresp.best.res(end+1,1)= tokens{1}{1}; 832 fline=fgetl(fidi); 833 end 834 835 % read and add best constraint value(s) 836 837 elseif strncmpi(cellstr(tokens{1}{3}),'constraint',10) && ... 838 strncmpi(cellstr(tokens{1}{4}),'value' , 5) 839 display([' ' deblank(fline)]); 840 841 fline=fgetl(fidi); 842 dresp.best.nc=[]; 843 844 while ischar(fline) && ~isempty(fline) && ... 845 ~strncmpi(fline,'<<<<< Best ',11) 846 [ntokens,tokens]=fltokens(fline); 847 dresp.best.nc(end+1,1)= tokens{1}{1}; 848 fline=fgetl(fidi); 849 end 850 851 % read and add best data captured 852 853 elseif strncmpi(cellstr(tokens{1}{3}),'data' , 4) && ... 854 strncmpi(cellstr(tokens{1}{4}),'captured', 8) 855 display([' ' deblank(fline)]); 856 dresp.best.eval= tokens{1}{8}; 857 858 fline=fgetl(fidi); 859 860 while ischar(fline) && ~isempty(fline) && ... 861 ~strncmpi(fline,'<<<<< Best ',11) 862 fline=fgetl(fidi); 863 end 864 865 % read until next best or blank or end 866 867 else 868 display([' ' deblank(fline) ' (ignored)']); 869 870 fline=fgetl(fidi); 871 872 while ischar(fline) && ~isempty(fline) && ... 873 ~strncmpi(fline,'<<<<< Best ',11) 874 fline=fgetl(fidi); 875 end 876 end 877 end 878 879 end % }}} 880 function [dresp]=vum_read(fidi,dresp,fline) % {{{ 881 %% function to find and read the volumetric uniformity measures 882 883 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 884 [fline]=findline(fidi,'The following lists volumetric uniformity measures'); 885 if ~ischar(fline) 886 return 887 end 888 end 889 890 if isempty(dresp) 891 dresp(end+1).vum=[]; 892 end 893 display('Reading measures for volumetric uniformity.'); 894 895 fline=fgetl(fidi); 896 fline=fgetl(fidi); 897 898 while ischar(fline) && ~isempty(fline) 899 [ntokens,tokens]=fltokens(fline); 900 switch lower(tokens{1}{1}) 901 case 'chi' 902 dresp.vum.chi=tokens{1}{4}; 903 case 'd' 904 dresp.vum.d =tokens{1}{4}; 905 case 'h' 906 dresp.vum.h =tokens{1}{4}; 907 case 'tau' 908 dresp.vum.tau=tokens{1}{4}; 909 end 910 fline=fgetl(fidi); 911 end 912 913 end % }}} 914 function [method]=itcomp_read(fidi,fline) % {{{ 915 %% function to find and read the iterator completion 916 917 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 918 while 1 919 [fline]=findline(fidi,'<<<<< Iterator '); 920 if ~ischar(fline) 921 return 922 end 923 if (length(fline) > 26) && ... 924 ~isempty(strfind(fline(16:end),' completed.')) 925 break 926 end 927 end 928 end 86 929 87 930 [ntokens,tokens]=fltokens(fline); 88 931 method=tokens{1}{3}; 89 display(sprintf('Dakota methodName=''%s''.',method)); 90 end 91 92 dresp=struct([]); 93 scm =struct([]); 94 pcm =struct([]); 95 srcm=struct([]); 96 prcm=struct([]); 97 98 %% loop through the file to find the function evaluation summary 99 100 fline=''; 101 [nfeval]=nfeval_read(fidi,fline); 102 fline=fgetl(fidi); 103 104 %% process each results section based on content of the file 105 106 while ischar(fline) 107 % ipos=ftell(fidi); 108 if isempty(fline) 109 elseif strncmp(fline,'<<<<< Function evaluation summary',33) 110 [nfeval]=nfeval_read(fidi,fline); 111 elseif strncmp(fline,'Statistics based on ',20) 112 [nsamp]=nsamp_read(fidi,fline); 113 elseif strncmp(fline,'Moments for each response function',34) 114 [dresp]=moments_read(fidi,dresp,fline); 115 elseif strncmp(fline,'Moment-based statistics for each response function',50) 116 [dresp]=mbstats_read(fidi,dresp,fline); 117 elseif strncmp(fline,'95% confidence intervals for each response function',51) 118 [dresp]=cis_read(fidi,dresp,fline); 119 elseif strncmp(fline,'Probabilities for each response function',40) || ... 120 strncmp(fline,'Level mappings for each response function',41) 121 [dresp]=cdfs_read(fidi,dresp,fline); 122 elseif strncmp(fline,'Probability Density Function (PDF) histograms for each response function',72) 123 [dresp]=pdfs_read(fidi,dresp,fline); 124 elseif strncmp(fline,'Simple Correlation Matrix',25) 125 [scm]=corrmat_read(fidi,'Simple Correlation Matrix',fline); 126 elseif strncmp(fline,'Partial Correlation Matrix',26) 127 [pcm]=corrmat_read(fidi,'Partial Correlation Matrix',fline); 128 elseif strncmp(fline,'Simple Rank Correlation Matrix',30) 129 [srcm]=corrmat_read(fidi,'Simple Rank Correlation Matrix',fline); 130 elseif strncmp(fline,'Partial Rank Correlation Matrix',31) 131 [prcm]=corrmat_read(fidi,'Partial Rank Correlation Matrix',fline); 132 elseif strncmp(fline,'MV Statistics for ',18) 133 [dresp]=mvstats_read(fidi,dresp,fline); 134 elseif strncmp(fline,'<<<<< Best ',11) 135 [dresp]=best_read(fidi,dresp,fline); 136 elseif strncmp(fline,'The following lists volumetric uniformity measures',50) 137 [dresp]=vum_read(fidi,dresp,fline); 138 elseif strncmp(fline,'<<<<< Iterator ',15) && ... 139 (length(fline) > 26) && ... 140 ~isempty(strfind(fline(16:end),' completed.')) 141 [method]=itcomp_read(fidi,fline); 142 elseif strncmp(fline,'-----',5) 143 else 144 display(['Unexpected line: ' deblank(fline)]); 145 end 146 fline=fgetl(fidi); 147 % fseek(fidi,ipos,'bof'); 148 end 149 150 %% loop through the file to verify the end 151 152 % [fline]=findline(fidi,'<<<<< Single Method Strategy completed'); 153 % if ~ischar(fline) 154 % return 155 % end 156 display('End of file successfully reached.'); 157 fclose(fidi); 158 159 end 160 161 %% function to parse the dakota tabular output file 162 163 function [dresp]=dak_tab_out(fidi,fline) 164 165 display('Reading Dakota tabular output file.'); 166 167 % process column headings of matrix (skipping eval_id) 168 169 [ntokens,tokens]=fltokens(fline); 170 171 % New file DAKOTA versions>6 172 if strncmpi(fline,'%eval_id interface',18) 173 offset=2; 174 else %DAKOTA versions<6 175 offset=1; 176 end 177 desc=cell (1,ntokens-offset); 178 data=zeros(1,ntokens-offset); 179 180 for i=1:ntokens-offset 181 desc(1,i)=cellstr(tokens{1}{i+offset}); 182 end 183 display(sprintf('Number of columns (Dakota V+R)=%d.',ntokens-2)); 184 185 % process rows of matrix 186 187 nrow=0; 188 while 1 189 fline=fgetl(fidi); 190 if ~ischar(fline) || isempty(fline) 191 break; 192 end 193 [ntokens,tokens]=fltokens(fline); 194 195 % add row values to matrix (skipping eval_id) 196 197 nrow=nrow+1; 198 for i=1:ntokens-offset 199 data(nrow,i)=tokens{1}{i+offset}; 200 end 201 end 202 display(sprintf('Number of rows (Dakota func evals)=%d.',nrow)); 203 204 % calculate statistics 205 206 % since normfit doesn't have a dim argument, and matlab isvector is true 207 % for a 1xn matrix, handle the case of one row explicitly 208 if (size(data,1) > 1) 209 %dmean =mean (data); 210 %dstddev=std (data,0); 211 [dmean,dstddev,dmeanci,dstddevci]=... 212 normfit_issm(data,0.05); 213 else 214 dmean =zeros(1,size(data,2)); 215 dstddev =zeros(1,size(data,2)); 216 dmeanci =zeros(2,size(data,2)); 217 dstddevci=zeros(2,size(data,2)); 218 for i=1:size(data,2) 219 [dmean(1,i),dstddev(1,i),dmeanci(:,i),dstddevci(:,i)]=... 220 normfit_issm(data(:,i),0.05); 221 end 222 end 223 224 dmin =min (data,[],1); 225 dquart1=prctile_issm(data,25,1); 226 dmedian=median (data,1); 227 dquart3=prctile_issm(data,75,1); 228 dmax =max (data,[],1); 229 dmin95=prctile_issm(data,5,1); 230 dmax95=prctile_issm(data,95,1); 231 232 % same as Dakota scm, Excel correl 233 dcorrel=corrcoef(data); 234 235 % divide the data into structures for consistency 236 237 for i=1:length(desc) 238 dresp(i).descriptor=char(desc(i)); 239 dresp(i).sample =data(:,i); 240 dresp(i).mean =dmean(i); 241 dresp(i).stddev =dstddev(i); 242 dresp(i).meanci =dmeanci(:,i); 243 dresp(i).stddevci =dstddevci(:,i); 244 dresp(i).min =dmin(i); 245 dresp(i).quart1 =dquart1(i); 246 dresp(i).median =dmedian(i); 247 dresp(i).quart3 =dquart3(i); 248 dresp(i).max =dmax(i); 249 dresp(i).dmin95 =dmin95(i); 250 dresp(i).dmax95 =dmax95(i); 251 end 252 253 % draw box plot 254 255 % figure 256 % subplot(2,1,1) 257 % plot_boxplot(dresp); 258 259 % draw normal probability plot 260 261 % subplot(2,1,2) 262 % plot_normplot(dresp); 263 264 end 265 266 %% function to find and read the number of function evaluations 267 268 function [nfeval]=nfeval_read(fidi,fline) 269 270 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 271 [fline]=findline(fidi,'<<<<< Function evaluation summary'); 272 if ~ischar(fline) 273 return 274 end 275 end 276 277 [ntokens,tokens]=fltokens(fline); 278 nfeval=tokens{1}{5}; 279 display(sprintf(' Dakota function evaluations=%d.',nfeval)); 280 281 end 282 283 %% function to find and read the number of samples 284 285 function [nsamp]=nsamp_read(fidi,fline) 286 287 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 288 [fline]=findline(fidi,'Statistics based on '); 289 if ~ischar(fline) 290 return 291 end 292 end 293 294 [ntokens,tokens]=fltokens(fline); 295 nsamp=tokens{1}{4}; 296 display(sprintf(' Dakota samples=%d.',nsamp)); 297 298 end 299 300 %% function to find and read the moments 301 302 function [dresp]=moments_read(fidi,dresp,fline) 303 304 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 305 [fline]=findline(fidi,'Moments for each response function'); 306 if ~ischar(fline) 307 return 308 end 309 end 310 311 display('Reading moments for response functions:'); 312 313 while 1 314 fline=fgetl(fidi); 315 if isempty(fline) 316 break; 317 end 318 [ntokens,tokens]=fltokens(fline); 319 320 % add new response function and moments 321 322 dresp(end+1).descriptor=tokens{1}{ 1}; 323 display(sprintf(' %s',dresp(end).descriptor)); 324 dresp(end ).mean =tokens{1}{ 4}; 325 dresp(end ).stddev =tokens{1}{ 8}; 326 dresp(end ).coefvar =tokens{1}{13}; 327 end 328 329 display(sprintf(' Number of Dakota response functions=%d.',... 330 length(dresp))); 331 332 end 333 334 %% function to find and read the moment-based statistics 335 336 function [dresp]=mbstats_read(fidi,dresp,fline) 337 338 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 339 [fline]=findline(fidi,'Moment-based statistics for each response function'); 340 if ~ischar(fline) 341 return 342 end 343 end 344 345 display('Reading moment-based statistics for response functions:'); 346 347 % skip column headings of moment-based statistics 348 349 fline=fgetl(fidi); 350 351 while 1 352 fline=fgetl(fidi); 353 if isempty(fline) 354 break; 355 end 356 [ntokens,tokens]=fltokens(fline); 357 358 % add new response function and moment-based statistics 359 360 dresp(end+1).descriptor=tokens{1}{ 1}; 361 display(sprintf(' %s',dresp(end).descriptor)); 362 dresp(end ).mean =tokens{1}{ 2}; 363 dresp(end ).stddev =tokens{1}{ 3}; 364 dresp(end ).skewness =tokens{1}{ 4}; 365 dresp(end ).kurtosis =tokens{1}{ 5}; 366 end 367 368 display(sprintf(' Number of Dakota response functions=%d.',... 369 length(dresp))); 370 371 end 372 373 %% function to find and read the confidence intervals 374 375 function [dresp]=cis_read(fidi,dresp,fline) 376 377 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 378 [fline]=findline(fidi,... 379 '95% confidence intervals for each response function'); 380 if ~ischar(fline) 381 return 382 end 383 end 384 385 display('Reading 95% confidence intervals for response functions:'); 386 387 while 1 388 fline=fgetl(fidi); 389 if isempty(fline) 390 break; 391 end 392 [ntokens,tokens]=fltokens(fline); 393 394 % check for column headings in Dakota 5.2 395 396 if (ntokens == 4) 397 fline=fgetl(fidi); 398 if isempty(fline) 399 break; 400 end 401 [ntokens,tokens]=fltokens(fline); 402 end 403 404 % find response function associated with confidence intervals 405 406 idresp=0; 407 for i=1:length(dresp) 408 if strcmpi(tokens{1}{ 1},dresp(i).descriptor) 409 idresp=i; 410 break; 411 end 412 end 413 if ~idresp 414 idresp=length(dresp)+1; 415 dresp(idresp).descriptor=tokens{1}{ 1}; 416 display(sprintf(' %s',dresp(idresp).descriptor)); 417 end 418 419 % add confidence intervals to response functions 420 421 if (ntokens == 14) 422 dresp(i).meanci (1,1)=tokens{1}{ 5}; 423 dresp(i).meanci (2,1)=tokens{1}{ 6}; 424 dresp(i).stddevci(1,1)=tokens{1}{12}; 425 dresp(i).stddevci(2,1)=tokens{1}{13}; 426 else 427 dresp(i).meanci (1,1)=tokens{1}{ 2}; 428 dresp(i).meanci (2,1)=tokens{1}{ 3}; 429 dresp(i).stddevci(1,1)=tokens{1}{ 4}; 430 dresp(i).stddevci(2,1)=tokens{1}{ 5}; 431 end 432 end 433 434 display(sprintf(' Number of Dakota response functions=%d.',... 435 length(dresp))); 436 437 end 438 439 %% function to find and read the cdf's 440 441 function [dresp]=cdfs_read(fidi,dresp,fline) 442 443 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 444 [fline]=findline(fidi,'Probabilities for each response function'); 445 if ~ischar(fline) 446 [fline]=findline(fidi,'Level mappings for each response function'); 447 if ~ischar(fline) 448 return 449 end 450 end 451 end 452 453 display('Reading CDF''s for response functions:'); 454 455 while ischar(fline) && ~isempty(fline) 456 fline=fgetl(fidi); 457 if ~ischar(fline) 458 break; 459 end 460 461 % process header line of cdf 462 463 while ischar(fline) && ~isempty(fline) 464 [ntokens,tokens]=fltokens(fline); 465 466 % find response function associated with cdf 467 468 idresp=0; 469 for i=1:length(dresp) 470 if strcmpi(tokens{1}{ 6},dresp(i).descriptor) 471 idresp=i; 472 break; 473 end 474 end 475 if ~idresp 476 idresp=length(dresp)+1; 477 dresp(idresp).descriptor=tokens{1}{ 6}; 478 display(sprintf(' %s',dresp(idresp).descriptor)); 479 end 480 481 % skip column headings of cdf 482 483 fline=fgetl(fidi); 484 fline=fgetl(fidi); 485 486 % read and add cdf table to response function 487 488 fline=fgetl(fidi); 489 icdf=0; 490 while ischar(fline) && ~isempty(fline) && ... 491 ~strncmpi(fline,'Cumulative Distribution Function',32) 492 [ntokens,tokens]=fltokens(fline); 493 icdf=icdf+1; 494 dresp(idresp).cdf(icdf,1:4)=NaN; 495 % in later versions of Dakota, uncalculated columns are now blank 496 itoken=0; 497 for i=1:length(fline)/19 498 if ~isempty(deblank(fline((i-1)*19+1:i*19))) 499 itoken=itoken+1; 500 dresp(idresp).cdf(icdf,i)=tokens{1}{itoken}; 501 end 502 end 503 fline=fgetl(fidi); 504 end 505 end 506 end 507 508 display(sprintf(' Number of Dakota response functions=%d.',... 509 length(dresp))); 510 511 end 512 513 %% function to find and read the pdf's 514 515 function [dresp]=pdfs_read(fidi,dresp,fline) 516 517 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 518 [fline]=findline(fidi,'Probability Density Function (PDF) histograms for each response function'); 519 if ~ischar(fline) 520 return 521 end 522 end 523 524 display('Reading PDF''s for response functions:'); 525 526 while ischar(fline) && ~isempty(fline) 527 fline=fgetl(fidi); 528 if ~ischar(fline) 529 break; 530 end 531 532 % process header line of pdf 533 534 while ischar(fline) && ~isempty(fline) 535 [ntokens,tokens]=fltokens(fline); 536 537 % find response function associated with pdf 538 539 idresp=0; 540 for i=1:length(dresp) 541 if strcmpi(tokens{1}{ 3},dresp(i).descriptor) 542 idresp=i; 543 break; 544 end 545 end 546 if ~idresp 547 idresp=length(dresp)+1; 548 dresp(idresp).descriptor=tokens{1}{ 3}; 549 display(sprintf(' %s',dresp(idresp).descriptor)); 550 end 551 552 % skip column headings of pdf 553 554 fline=fgetl(fidi); 555 fline=fgetl(fidi); 556 557 % read and add pdf table to response function 558 559 fline=fgetl(fidi); 560 ipdf=0; 561 while ischar(fline) && ~isempty(fline) && ... 562 ~strncmpi(fline,'PDF for', 7) 563 [ntokens,tokens]=fltokens(fline); 564 ipdf=ipdf+1; 565 dresp(idresp).pdf(ipdf,1:3)=NaN; 566 for i=1:3 567 dresp(idresp).pdf(ipdf,i)=tokens{1}{i}; 568 end 569 fline=fgetl(fidi); 570 end 571 end 572 end 573 574 display(sprintf(' Number of Dakota response functions=%d.',... 575 length(dresp))); 576 577 end 578 579 %% function to find and read a correlation matrix 580 581 function [cmat]=corrmat_read(fidi,cmstr,fline) 582 583 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 584 [fline]=findline(fidi,cmstr); 585 if ~ischar(fline) 586 cmat=struct([]); 587 return 588 end 589 end 590 591 display(['Reading ''' fline '''.']); 592 593 cmat.title=fline; 594 595 while ~isempty(fline) 596 fline=fgetl(fidi); 597 if ~ischar(fline) 598 break; 599 end 600 601 % process column headings of matrix 602 603 [ntokens,tokens]=fltokens(fline); 604 cmat.column=cell(1,ntokens); 605 cmat.row =cell(1,1); 606 cmat.matrix=zeros(1,ntokens); 607 608 for i=1:ntokens 609 cmat.column(1,i)=cellstr(tokens{1}{i}); 610 end 611 612 % process rows of matrix, reading until blank line 613 614 nrow=0; 615 while 1 616 fline=fgetl(fidi); 617 if isempty(fline) 618 break; 619 end 620 [ntokens,tokens]=fltokens(fline); 621 622 % add row heading to matrix 623 624 nrow=nrow+1; 625 cmat.row (nrow,1)=cellstr(tokens{1}{1}); 626 627 % add row values to matrix 628 629 for i=2:ntokens 630 cmat.matrix(nrow,i-1)=tokens{1}{i}; 631 end 632 end 633 end 634 635 end 636 637 %% function to find and read the MV statistics 638 639 function [dresp]=mvstats_read(fidi,dresp,fline) 640 641 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 642 [fline]=findline(fidi,'MV Statistics for '); 643 if ~ischar(fline) 644 return 645 end 646 end 647 648 display('Reading MV statistics for response functions:'); 649 ndresp=0; 650 651 while ischar(fline) && ~isempty(fline) && ... 652 strncmpi(fline,'MV Statistics for ',18) 653 654 % add new response function and moments 655 656 [ntokens,tokens]=fltokens(fline); 657 dresp(end+1).descriptor=tokens{1}{4}; 658 display(sprintf(' %s',dresp(end).descriptor)); 659 fline=fgetl(fidi); 660 [ntokens,tokens]=fltokens(fline); 661 dresp(end ).mean =tokens{1}{5}; 662 fline=fgetl(fidi); 663 [ntokens,tokens]=fltokens(fline); 664 dresp(end ).stddev =tokens{1}{7}; 665 666 % read and add importance factors to response function 667 668 idvar=0; 669 fline=fgetl(fidi); 670 if ~ischar(fline) 671 break; 672 end 673 674 while ischar(fline) && ~isempty(fline) && ... 675 strncmpi(fline,' Importance Factor for variable ',33) 676 [ntokens,tokens]=fltokens(fline); 677 idvar=idvar+1; 678 dresp(end).var (idvar,1)=cellstr(tokens{1}{ 5}); 679 dresp(end).impfac(idvar,1)= tokens{1}{ 7}; 680 if (ntokens >= 10) 681 dresp(end).sens (idvar,1)= tokens{1}{10}; 682 else 683 dresp(end).sens (idvar,1)=NaN; 684 end 685 686 fline=fgetl(fidi); 687 end 688 689 % if importance factors missing, skip to cdf 690 691 if ~idvar 692 display(' Importance Factors not available.'); 693 dresp(end).var ={}; 694 dresp(end).impfac=[]; 695 dresp(end).sens =[]; 696 while ischar(fline) && ... 697 ~strncmpi(fline,'Cumulative Distribution Function',32) && ... 698 ~strncmpi(fline,'MV Statistics for ',18) && ... 699 ~strncmp (fline,'-',1) 700 fline=fgetl(fidi); 701 end 702 end 703 704 % process header line of cdf 705 706 icdf=0; 707 708 while ischar(fline) && ~isempty(fline) && ... 709 strncmpi(fline,'Cumulative Distribution Function',32) 710 [ntokens,tokens]=fltokens(fline); 711 712 % find response function associated with cdf 713 714 idresp=0; 715 for i=1:length(dresp) 716 if strcmpi(tokens{1}{ 6},dresp(i).descriptor) 717 idresp=i; 718 break; 719 end 720 end 721 if ~idresp 722 idresp=length(dresp)+1; 723 dresp(idresp).descriptor=tokens{1}{ 6}; 724 display(sprintf(' %s',dresp(idresp).descriptor)); 725 end 726 727 % skip column headings of cdf 728 729 fline=fgetl(fidi); 730 fline=fgetl(fidi); 731 732 % read and add cdf table to response function 733 734 fline=fgetl(fidi); 735 while ~isempty(fline) && ... 736 ~strncmpi(fline,'MV Statistics for ',18) && ... 737 ~strncmp (fline,'-',1) 738 [ntokens,tokens]=fltokens(fline); 739 icdf=icdf+1; 740 dresp(idresp).cdf(icdf,1)=tokens{1}{1}; 741 dresp(idresp).cdf(icdf,2)=tokens{1}{2}; 742 if (ntokens == 4) 743 dresp(idresp).cdf(icdf,3)=tokens{1}{3}; 744 dresp(idresp).cdf(icdf,4)=tokens{1}{4}; 745 else 746 dresp(idresp).cdf(icdf,3)=NaN; 747 dresp(idresp).cdf(icdf,4)=NaN; 748 end 749 fline=fgetl(fidi); 750 end 751 end 752 753 % if cdf missing, skip to end of response function 754 755 if ~icdf 756 display(' Cumulative Distribution Function not available.'); 757 dresp(ndresp).cdf=[]; 758 while ischar(fline) && ... 759 ~strncmpi(fline,'MV Statistics for ',18) && ... 760 ~strncmp (fline,'-',1) 761 fline=fgetl(fidi); 762 end 763 end 764 765 end 766 767 display(sprintf(' Number of Dakota response functions=%d.',... 768 length(dresp))); 769 770 end 771 772 %% function to find and read the best evaluation 773 774 function [dresp]=best_read(fidi,dresp,fline) 775 776 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 777 [fline]=findline(fidi,'<<<<< Best '); 778 if ~ischar(fline) 779 return 780 end 781 end 782 783 if isempty(dresp) 784 dresp(end+1).best=[]; 785 end 786 display('Reading values for best function evaluation:'); 787 788 while ischar(fline) && ~isempty(fline) && ... 789 strncmpi(fline,'<<<<< Best ',11) 790 [ntokens,tokens]=fltokens(fline); 791 792 % read and add best parameter(s) 793 794 if strncmpi(cellstr(tokens{1}{3}),'parameter', 9) 795 display([' ' deblank(fline)]); 796 797 fline=fgetl(fidi); 798 dresp.best.param =[]; 799 dresp.best.descriptor={}; 800 801 while ischar(fline) && ~isempty(fline) && ... 802 ~strncmpi(fline,'<<<<< Best ',11) 803 [ntokens,tokens]=fltokens(fline); 804 dresp.best.param (end+1,1)= tokens{1}{1}; 805 dresp.best.descriptor(end+1,1)=cellstr(tokens{1}{2}); 806 fline=fgetl(fidi); 807 end 808 809 % read and add best objective function(s) 810 811 elseif strncmpi(cellstr(tokens{1}{3}),'objective', 9) && ... 812 strncmpi(cellstr(tokens{1}{4}),'function' , 8) 813 display([' ' deblank(fline)]); 814 815 fline=fgetl(fidi); 816 dresp.best.of=[]; 817 818 while ischar(fline) && ~isempty(fline) && ... 819 ~strncmpi(fline,'<<<<< Best ',11) 820 [ntokens,tokens]=fltokens(fline); 821 dresp.best.of(end+1,1)= tokens{1}{1}; 822 fline=fgetl(fidi); 823 end 824 825 % read and add best residual norms 826 827 elseif strncmpi(cellstr(tokens{1}{3}),'residual', 8) && ... 828 strncmpi(cellstr(tokens{1}{4}),'norm' , 4) 829 display([' ' deblank(fline)]); 830 dresp.best.norm = tokens{1}{ 6}; 831 dresp.best.hnormsq= tokens{1}{11}; 832 833 fline=fgetl(fidi); 834 835 while ischar(fline) && ~isempty(fline) && ... 836 ~strncmpi(fline,'<<<<< Best ',11) 837 fline=fgetl(fidi); 838 end 839 840 % read and add best residual term(s) 841 842 elseif strncmpi(cellstr(tokens{1}{3}),'residual', 8) && ... 843 strncmpi(cellstr(tokens{1}{4}),'term' , 4) 844 display([' ' deblank(fline)]); 845 846 fline=fgetl(fidi); 847 dresp.best.res=[]; 848 849 while ischar(fline) && ~isempty(fline) && ... 850 ~strncmpi(fline,'<<<<< Best ',11) 851 [ntokens,tokens]=fltokens(fline); 852 dresp.best.res(end+1,1)= tokens{1}{1}; 853 fline=fgetl(fidi); 854 end 855 856 % read and add best constraint value(s) 857 858 elseif strncmpi(cellstr(tokens{1}{3}),'constraint',10) && ... 859 strncmpi(cellstr(tokens{1}{4}),'value' , 5) 860 display([' ' deblank(fline)]); 861 862 fline=fgetl(fidi); 863 dresp.best.nc=[]; 864 865 while ischar(fline) && ~isempty(fline) && ... 866 ~strncmpi(fline,'<<<<< Best ',11) 867 [ntokens,tokens]=fltokens(fline); 868 dresp.best.nc(end+1,1)= tokens{1}{1}; 869 fline=fgetl(fidi); 870 end 871 872 % read and add best data captured 873 874 elseif strncmpi(cellstr(tokens{1}{3}),'data' , 4) && ... 875 strncmpi(cellstr(tokens{1}{4}),'captured', 8) 876 display([' ' deblank(fline)]); 877 dresp.best.eval= tokens{1}{8}; 878 879 fline=fgetl(fidi); 880 881 while ischar(fline) && ~isempty(fline) && ... 882 ~strncmpi(fline,'<<<<< Best ',11) 883 fline=fgetl(fidi); 884 end 885 886 % read until next best or blank or end 887 888 else 889 display([' ' deblank(fline) ' (ignored)']); 890 891 fline=fgetl(fidi); 892 893 while ischar(fline) && ~isempty(fline) && ... 894 ~strncmpi(fline,'<<<<< Best ',11) 895 fline=fgetl(fidi); 896 end 897 end 898 end 899 900 end 901 902 %% function to find and read the volumetric uniformity measures 903 904 function [dresp]=vum_read(fidi,dresp,fline) 905 906 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 907 [fline]=findline(fidi,'The following lists volumetric uniformity measures'); 908 if ~ischar(fline) 909 return 910 end 911 end 912 913 if isempty(dresp) 914 dresp(end+1).vum=[]; 915 end 916 display('Reading measures for volumetric uniformity.'); 917 918 fline=fgetl(fidi); 919 fline=fgetl(fidi); 920 921 while ischar(fline) && ~isempty(fline) 922 [ntokens,tokens]=fltokens(fline); 923 switch lower(tokens{1}{1}) 924 case 'chi' 925 dresp.vum.chi=tokens{1}{4}; 926 case 'd' 927 dresp.vum.d =tokens{1}{4}; 928 case 'h' 929 dresp.vum.h =tokens{1}{4}; 930 case 'tau' 931 dresp.vum.tau=tokens{1}{4}; 932 end 933 fline=fgetl(fidi); 934 end 935 936 end 937 938 %% function to find and read the iterator completion 939 940 function [method]=itcomp_read(fidi,fline) 941 942 if ~exist('fline','var') || isempty(fline) || ~ischar(fline) 943 while 1 944 [fline]=findline(fidi,'<<<<< Iterator '); 945 if ~ischar(fline) 946 return 947 end 948 if (length(fline) > 26) && ... 949 ~isempty(strfind(fline(16:end),' completed.')) 950 break 951 end 952 end 953 end 954 955 [ntokens,tokens]=fltokens(fline); 956 method=tokens{1}{3}; 957 display(sprintf('Dakota iterator ''%s'' completed.',method)); 958 959 end 960 932 display(sprintf('Dakota iterator ''%s'' completed.',method)); 933 934 end % }}} 935 function [fline]=findline(fidi,string) % {{{ 961 936 %% function to find a file line starting with a specified string 962 937 963 function [fline]=findline(fidi,string) 964 965 ipos=ftell(fidi); 966 967 while 1 968 fline=fgetl(fidi); 969 if ~ischar(fline) 970 break; 971 else 972 if (strncmpi(fline,string,length(string))) 973 return; 974 end 975 end 976 end 977 978 % issue warning and reset file position 979 980 warning('findline:str_not_found',... 981 'String ''%s'' not found in file.',string); 982 fseek(fidi,ipos,'bof'); 983 984 end 985 938 ipos=ftell(fidi); 939 940 while 1 941 fline=fgetl(fidi); 942 if ~ischar(fline) 943 break; 944 else 945 if (strncmpi(fline,string,length(string))) 946 return; 947 end 948 end 949 end 950 951 % issue warning and reset file position 952 953 warning('findline:str_not_found',... 954 'String ''%s'' not found in file.',string); 955 fseek(fidi,ipos,'bof'); 956 957 end % }}} 958 function [ntokens,tokens]=fltokens(fline) % {{{ 986 959 %% function to parse a file line into tokens 987 960 988 function [ntokens,tokens]=fltokens(fline) 989 990 if ~ischar(fline) 991 ntokens=-1; 992 tokens={}; 993 return; 994 end 995 if isempty(fline) 996 ntokens=0; 997 tokens={}; 998 return; 999 end 1000 1001 strings=textscan(fline,'%s','delimiter',' :'); 1002 %for i=1:length(strings{1}) 1003 % display(sprintf('i=%d; strings{1}{%d}=%s',i,i,strings{1}{i})) 1004 %end 1005 ntokens=0; 1006 tokens{1}{length(strings)}=''; 1007 1008 for i=1:length(strings{1}) 1009 if isempty(strings{1}{i}) 1010 continue 1011 end 1012 ntokens=ntokens+1; 1013 inum=sscanf(strings{1}{i},'%f'); 1014 if isempty(inum) 1015 tokens{1}{ntokens}=strings{1}{i}; 1016 % display(sprintf('i=%d; tokens{1}{%d}=%s',... 1017 % i,ntokens,tokens{1}{ntokens})) 1018 else 1019 tokens{1}{ntokens}=inum; 1020 % display(sprintf('i=%d; tokens{1}{%d}=%f',... 1021 % i,ntokens,tokens{1}{ntokens})) 1022 end 1023 end 1024 1025 end 961 if ~ischar(fline) 962 ntokens=-1; 963 tokens={}; 964 return; 965 end 966 if isempty(fline) 967 ntokens=0; 968 tokens={}; 969 return; 970 end 971 972 strings=textscan(fline,'%s','delimiter',' :'); 973 %for i=1:length(strings{1}) 974 % display(sprintf('i=%d; strings{1}{%d}=%s',i,i,strings{1}{i})) 975 %end 976 ntokens=0; 977 tokens{1}{length(strings)}=''; 978 979 for i=1:length(strings{1}) 980 if isempty(strings{1}{i}) 981 continue 982 end 983 ntokens=ntokens+1; 984 inum=sscanf(strings{1}{i},'%f'); 985 if isempty(inum) 986 tokens{1}{ntokens}=strings{1}{i}; 987 % display(sprintf('i=%d; tokens{1}{%d}=%s',... 988 % i,ntokens,tokens{1}{ntokens})) 989 else 990 tokens{1}{ntokens}=inum; 991 % display(sprintf('i=%d; tokens{1}{%d}=%f',... 992 % i,ntokens,tokens{1}{ntokens})) 993 end 994 end 995 996 end % }}}
Note:
See TracChangeset
for help on using the changeset viewer.