ng_read_opt

PURPOSE ^

NG_READ_OPT Read Netgen's ng.opt

SYNOPSIS ^

function opt = ng_read_opt(fname)

DESCRIPTION ^

NG_READ_OPT Read Netgen's ng.opt 
  NG_READ_OPT, without inputs, reads ng.opt in current directory

  NG_WRITE_OPT(PATH) reads the file specified in PATH. IF PATH is a 
  directory, looks for ng.opt.
 
  See also NG_WRITE_OPT

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function opt = ng_read_opt(fname)
0002 %NG_READ_OPT Read Netgen's ng.opt
0003 %  NG_READ_OPT, without inputs, reads ng.opt in current directory
0004 %
0005 %  NG_WRITE_OPT(PATH) reads the file specified in PATH. IF PATH is a
0006 %  directory, looks for ng.opt.
0007 %
0008 %  See also NG_WRITE_OPT
0009 
0010 % (C) 2021 Bartlomiej Grychtol. License: GPL version 2 or version 3
0011 % $Id: ng_read_opt.m 6515 2022-12-30 20:17:23Z aadler $
0012 
0013 % if input is 'UNIT_TEST', run tests
0014 if nargin == 1 && ischar(fname) && strcmp(fname,'UNIT_TEST') 
0015    do_unit_test; return; end
0016 
0017 if nargin == 0 
0018     fname = 'ng.opt';
0019 end
0020 
0021 if exist(fname,'dir')
0022     fname = [fname filesep 'ng.opt'];
0023 end
0024 
0025 opt = struct();
0026 
0027 fid = fopen(fname,'r'); 
0028 tline = fgetl(fid);
0029 while ischar(tline)
0030     [key, val] = strtok(tline,' ');
0031 %   strval = strip(val); %% Matlab only
0032     strval= regexp(val,'\s*(.*\S)\s*','tokens');
0033     if isempty(strval)
0034        strval = '';
0035     else
0036        strval= strval{1}{1};
0037     end
0038     numval = str2double(strval);
0039     if isnan(numval)
0040         eval(sprintf('opt.%s = ''%s'';',key,strval));
0041     else
0042         eval(sprintf('opt.%s = %f;',key,numval));
0043     end
0044     tline = fgetl(fid);
0045 end
0046 fclose(fid);
0047 
0048 
0049 
0050 function do_unit_test
0051     opt = ng_write_opt();
0052     opt.meshoptions.fineness = 4;
0053     ng_write_opt(opt);
0054     opt = ng_read_opt();
0055     unit_test_cmp('simple test',opt.meshoptions.fineness, 4);
0056     
0057     path = cd();
0058     opt = ng_read_opt(path);
0059     unit_test_cmp('dir test',opt.meshoptions.fineness, 4);
0060     
0061     path = cd();
0062     opt = ng_read_opt([path filesep 'ng.opt']);
0063     unit_test_cmp('path test',opt.meshoptions.fineness, 4);
0064     
0065     
0066

Generated on Fri 30-Dec-2022 19:44:54 by m2html © 2005