0001 function opt = ng_write_opt(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 if nargin == 1 && ischar(varargin{1}) && strcmp(varargin{1},'UNIT_TEST')
0040 do_unit_test; return; end
0041
0042 if nargin == 1 && ischar(varargin{1})
0043 copyfile(varargin{1},'ng.opt');
0044 return
0045 end
0046
0047 opt = default_opt;
0048 if nargin == 0
0049 usr = struct;
0050 end
0051
0052 if nargin == 1 && isstruct(varargin{1})
0053 usr = varargin{1};
0054 end
0055 if nargin > 1
0056 usr = process_input(varargin{:});
0057 end
0058 opt = copy_field(opt,usr);
0059
0060 if nargout == 1
0061 return
0062 end
0063
0064
0065 write_ng_file(opt);
0066
0067 function opt = process_input(varargin)
0068 if mod(nargin,2)~=0
0069 error('EIDORS:WrongInput','Even number of inputs expected');
0070 end
0071 for i = 1:nargin/2
0072 idx = (i-1)*2 +1;
0073 val = varargin{idx+1};
0074 eval(sprintf('opt.%s = val;',varargin{idx}));
0075 end
0076
0077
0078
0079
0080 function opt = copy_field(opt,usr)
0081 optnms = fieldnames(opt);
0082 usrnms = fieldnames(usr);
0083 for i = 1:length(usrnms)
0084
0085 if ~ismember(usrnms{i},optnms)
0086 error('Unsupported option %s',usrnms{i});
0087 end
0088 if isstruct(usr.(usrnms{i}))
0089 opt.(usrnms{i}) = copy_field(opt.(usrnms{i}), usr.(usrnms{i}) );
0090 else
0091 opt.(usrnms{i}) = usr.(usrnms{i});
0092 end
0093 end
0094
0095
0096
0097 function write_ng_file(opt)
0098 fid = fopen('ng.opt','w');
0099 flds = fieldnames(opt);
0100 write_field(fid,opt,[]);
0101 fclose(fid);
0102
0103
0104
0105 function write_field(fid,s,str)
0106 if isstruct(s)
0107 if ~isempty(str)
0108 str = [str '.'];
0109 end
0110 flds = fieldnames(s);
0111 for i = 1:length(flds)
0112 write_field(fid,s.(flds{i}),[str flds{i}]);
0113 end
0114 elseif ischar(s)
0115 fprintf(fid,'%s %s\n', str, s);
0116 elseif round(s) == s
0117 fprintf(fid,'%s %d\n', str, s);
0118 else
0119 fprintf(fid,'%s %f\n', str, s);
0120 end
0121
0122
0123 function opt = default_opt
0124 opt.dirname = '.';
0125 opt.loadgeomtypevar = '"All Geometry types (*.stl,*.stlb,*.step,*.stp,...)"';
0126 opt.exportfiletype = '"Neutral Format"';
0127 opt.meshoptions.fineness = 3;
0128 opt.meshoptions.firststep = 'ag';
0129 opt.meshoptions.laststep = 'ov';
0130 opt.options.localh = 1;
0131 opt.options.delaunay = 1;
0132 opt.options.checkoverlap = 1;
0133 opt.options.checkchartboundary = 1;
0134 opt.options.startinsurface = 0;
0135 opt.options.blockfill = 1;
0136 opt.options.debugmode = 0;
0137 opt.options.dooptimize = 1;
0138 opt.options.parthread = 1;
0139 opt.options.elsizeweight = 0.2;
0140 opt.options.secondorder = 0;
0141 opt.options.elementorder = 1;
0142 opt.options.quad = 0;
0143 opt.options.inverttets = 0;
0144 opt.options.inverttrigs = 0;
0145 opt.options.autozrefine = 0;
0146 opt.options.meshsize = 1000;
0147 opt.options.minmeshsize = 0;
0148 opt.options.curvaturesafety = 0.2;
0149 opt.options.segmentsperedge = 1;
0150 opt.options.meshsizefilename = '';
0151 opt.options.badellimit = 175;
0152 opt.options.optsteps2d = 3;
0153 opt.options.optsteps3d = 5;
0154 opt.options.opterrpow = 2;
0155 opt.options.grading = 0.3;
0156 opt.options.printmsg = 2;
0157 opt.geooptions.drawcsg = 1;
0158 opt.geooptions.detail = 0.001;
0159 opt.geooptions.accuracy = 1e-6;
0160 opt.geooptions.facets = 20;
0161 opt.geooptions.minx = -1000;
0162 opt.geooptions.miny = -1000;
0163 opt.geooptions.minz = -1000;
0164 opt.geooptions.maxx = 1000;
0165 opt.geooptions.maxy = 1000;
0166 opt.geooptions.maxz = 1000;
0167 opt.viewoptions.specpointvlen = 0.3;
0168 opt.viewoptions.light.amb = 0.3;
0169 opt.viewoptions.light.diff = 0.7;
0170 opt.viewoptions.light.spec = 1;
0171 opt.viewoptions.light.locviewer = 0;
0172 opt.viewoptions.mat.shininess = 50;
0173 opt.viewoptions.mat.transp = 0.3;
0174 opt.viewoptions.colormeshsize = 0;
0175 opt.viewoptions.whitebackground = 1;
0176 opt.viewoptions.drawcolorbar = 1;
0177 opt.viewoptions.drawcoordinatecross = 1;
0178 opt.viewoptions.drawnetgenlogo = 1;
0179 opt.viewoptions.stereo = 0;
0180 opt.viewoptions.drawfilledtrigs = 1;
0181 opt.viewoptions.drawedges = 0;
0182 opt.viewoptions.drawbadels = 0;
0183 opt.viewoptions.centerpoint = 0;
0184 opt.viewoptions.drawelement = 0;
0185 opt.viewoptions.drawoutline = 1;
0186 opt.viewoptions.drawtets = 0;
0187 opt.viewoptions.drawprisms = 0;
0188 opt.viewoptions.drawpyramids = 0;
0189 opt.viewoptions.drawhexes = 0;
0190 opt.viewoptions.drawidentified = 0;
0191 opt.viewoptions.drawpointnumbers = 0;
0192 opt.viewoptions.drawededges = 1;
0193 opt.viewoptions.drawedpoints = 1;
0194 opt.viewoptions.drawedpointnrs = 0;
0195 opt.viewoptions.drawedtangents = 0;
0196 opt.viewoptions.shrink = 1;
0197 opt.stloptions.showtrias = 0;
0198 opt.stloptions.showfilledtrias = 1;
0199 opt.stloptions.showedges = 1;
0200 opt.stloptions.showmarktrias = 0;
0201 opt.stloptions.showactivechart = 0;
0202 opt.stloptions.yangle = 10;
0203 opt.stloptions.contyangle = 20;
0204 opt.stloptions.edgecornerangle = 0;
0205 opt.stloptions.chartangle = 0;
0206 opt.stloptions.outerchartangle = 120;
0207 opt.stloptions.usesearchtree = 0;
0208 opt.stloptions.chartnumber = 1;
0209 opt.stloptions.charttrignumber = 1;
0210 opt.stloptions.chartnumberoffset = 0;
0211 opt.stloptions.atlasminh = 0.1;
0212 opt.stloptions.resthsurfcurvfac = 1;
0213 opt.stloptions.resthsurfcurvenable = 0;
0214 opt.stloptions.resthatlasfac = 2;
0215 opt.stloptions.resthatlasenable = 1;
0216 opt.stloptions.resthchartdistfac = 1.5;
0217 opt.stloptions.resthchartdistenable = 0;
0218 opt.stloptions.resthlinelengthfac = 0.5;
0219 opt.stloptions.resthlinelengthenable = 1;
0220 opt.stloptions.resthcloseedgefac = 2;
0221 opt.stloptions.resthcloseedgeenable = 1;
0222 opt.stloptions.resthedgeanglefac = 1;
0223 opt.stloptions.resthedgeangleenable = 0;
0224 opt.stloptions.resthsurfmeshcurvfac = 2;
0225 opt.stloptions.resthsurfmeshcurvenable = 0;
0226 opt.stloptions.recalchopt = 1;
0227 opt.visoptions.subdivisions = 1;
0228
0229
0230 function do_unit_test
0231 opt.meshoptions.fineness = 6;
0232 ng_write_opt(opt);
0233 fid = fopen('ng.opt','r'); str= fread(fid,[1,inf],'uint8=>char'); fclose(fid);
0234 unit_test_cmp('fineness=6',isempty( ...
0235 strfind(str, 'meshoptions.fineness 6')), 0);
0236
0237 ng_write_opt('meshoptions.fineness',4,'meshoptions.firststep','aaa');
0238 fid = fopen('ng.opt','r'); str= fread(fid,[1,inf],'uint8=>char'); fclose(fid);
0239 unit_test_cmp('firststep=aaa',isempty( ...
0240 strfind(str, 'meshoptions.firststep aaa')), 0);
0241
0242
0243 opt = ng_write_opt('meshoptions.fineness',4,'meshoptions.firststep','bbb');
0244 fid = fopen('ng.opt','r'); str= fread(fid,[1,inf],'uint8=>char'); fclose(fid);
0245 unit_test_cmp('firststep=bbb',isempty( ...
0246 strfind(str, 'meshoptions.firststep bbb')), 1);