0001 function status= call_netgen(geo_file, vol_file, msz_file, finelevel)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 if nargin<3
0024 msz_file= '';
0025 end
0026
0027 if ~isempty(msz_file)
0028 eidors_msg('call_netgen: Warning. Using an *.msz file. netgen rarely uses this file without care. Use the MSZPOINTS option in ng_write_opt instead.');
0029 end
0030
0031 if nargin<4
0032
0033
0034 finelevel= eidors_default('get','call_netgen_finelevel');
0035 end
0036
0037
0038 cache_path = eidors_cache('cache_path');
0039 eidors_path= eidors_cache('eidors_path');
0040 if isunix
0041
0042
0043
0044 if isfile([cache_path,'/ng.sh'])
0045 ng_name = [cache_path,'/ng.sh'];
0046 elseif isdir([eidors_path,'/../Netgen-5.3_x64/bin'])
0047
0048
0049 netgen_path = [eidors_path,'/../Netgen-5.3_x64/bin'];
0050 ng_name = [cache_path, '/ng.sh'];
0051
0052 fprintf('Creating batch file to access Netgen. Ensure wine is installed\n')
0053 [status] = system('wine --version');
0054 if status~=0;
0055 error('<wine> must be installed to use provided netgen.exe');
0056 end
0057 fid= fopen(ng_name,'w');
0058 if fid<0; error('Unable to write to %s',cache_path); end
0059 fprintf(fid,['NETGEN="',netgen_path,'" NETGENDIR="',netgen_path, ...
0060 '" wine "',netgen_path,'/netgen.exe" $1 $2 $3\n']);
0061 fclose(fid);
0062 system(['chmod a+x "',ng_name,'"']);
0063 else
0064 ng_name = 'netgen';
0065 end
0066 else
0067
0068
0069
0070 if isfile([cache_path,'/ng.bat'])
0071 ng_name = [cache_path,'/ng.bat'];
0072 elseif isdir([eidors_path,'/../Netgen-5.3_x64/bin'])
0073
0074
0075 netgen_path = [eidors_path,'/../Netgen-5.3_x64/bin'];
0076 ng_name = [cache_path, '/ng.bat'];
0077 fprintf('Creating batch file to access Netgen. Ensure wine is installed\n')
0078 fid= fopen(ng_name,'w');
0079 if fid<0; error('Unable to write to %s',cache_path); end
0080 fprintf(fid,'set NETGEN=%s\n', netgen_path);
0081 fprintf(fid,'set NETGENDIR=%s\n', netgen_path);
0082 fprintf(fid,'"%s/netgen.exe" %%*\n', netgen_path);
0083 fclose(fid);
0084 else
0085 ng_name = 'netgen.exe';
0086 end
0087 end
0088
0089 if ~isempty(msz_file)
0090 warning('EIDORS:Deprecated', 'Use ng_write_opt instead of specifying a meshsize file');
0091 warning('Overwriting ng.opt file');
0092 fid= fopen('ng.opt','w');
0093 if fid==-1
0094 error(['Netgen requires writing files in the current directory(%s). ', ...
0095 'Unfortunately, you don''t have permission. ' ...
0096 'Your options are: 1) change your working directory to one in which you have write permission, or ' ...
0097 '2) change the permissions on the current working directory.'], pwd);
0098 end
0099
0100
0101
0102 fprintf(fid,'options.meshsizefilename= %s\n',msz_file);
0103 fclose(fid);
0104 end
0105
0106 while( 1 )
0107 if ~isunix
0108
0109
0110 oldpath = getenv('NETGEN_USER_DIR');
0111 setenv('NETGEN_USER_DIR', cd);
0112 end
0113
0114 if eidors_debug('query','call_netgen')
0115 sys_cmd = sprintf('"%s" %s -geofile=%s -meshfile=%s ', ...
0116 ng_name, finelevel,geo_file,vol_file);
0117 else
0118 sys_cmd = sprintf('"%s" %s -batchmode -geofile="%s" -meshfile="%s" ', ...
0119 ng_name, finelevel,geo_file,vol_file);
0120 end
0121 status= system_cmd( sys_cmd );
0122
0123 if status==0; break; end
0124 try
0125 if isunix
0126 global eidors_objects;
0127 ignore_errors = 0;
0128 try
0129 ignore_errors = eidors_objects.ng_ignore_errors;
0130 end
0131 fprintf(['It seems that netgen has not worked (on linux). ' ...
0132 'If you downloaded a eidors-v??-ng, check <wine> is installed. ' ...
0133 'Otherwise, Check that netgen is installed and on the path. ' ...
0134 'Check the environment variable NETGENDIR is set. ' ...
0135 ' This can be set via the following commands:\n' ...
0136 ' setenv(''NETGENDIR'',''/path/to/netgen/bin'');\n' ...
0137 ' setenv(''PATH'',[''/path/to/netgen/bin:'',getenv(''PATH'')]);\n' ...
0138 'Please enter a new netgen file name\n' ]);
0139 if ignore_errors == 1;
0140 eidors_msg('Ignoring Netgen Error (as requested)',1);
0141 break;
0142 end
0143 ng_name = input( ...
0144 'netgen file name (with path)? [or i=ignore, e=error, a=always ignore]','s');
0145 if strcmp(ng_name,'i'); break;end
0146 if strcmp(ng_name,'a');
0147 eidors_objects.ng_ignore_errors = 1;
0148 break;
0149 end
0150 if strcmp(ng_name,'e'); error('user requested'),end;
0151 else
0152
0153
0154 netgen_path = [eidors_path,'/../Netgen-5.3_x64/bin'];
0155 if exist(netgen_path)
0156 fprintf('Creating batch file to access Netgen.\n')
0157 fid= fopen([cache_path, '/ng.bat'],'w');
0158 if fid<0; error('Unable to write to %s',cache_path); end
0159 fprintf(fid,'set TCL_LIBRARY=%s/lib/tcl8.3\n', netgen_path);
0160 fprintf(fid,'set TIX_LIBRARY=%s/lib/tix8.1\n', netgen_path);
0161 fprintf(fid,'set NETGENDIR=%s\n', netgen_path);
0162 fprintf(fid,'"%s/netgen.exe" %%*\n', netgen_path);
0163 fclose(fid);
0164 else
0165 fprintf([ ...
0166 'Netgen call failed. Is netgen installed and on the search path?\n' ...
0167 'If you are running under windows, I can attempt to create\n' ...
0168 'a batch file to access netgen.\n' ...
0169 'Please enter the directory in which to find netgen.exe.\n' ...
0170 'A typical path is "C:\\Program Files (x86)\\Netgen-5.0_x64\\bin"\n' ...
0171 'If you don''t have a copy, download it from' ...
0172 'http://sourceforge.net/projects/netgen-mesher/ \n\n']);
0173 netgen_path = input('netgen_path? [or i=ignore, e=error] ','s');
0174 if strcmp(netgen_path,'i'); break;end
0175 if strcmp(netgen_path,'e'); error('user requested'),end;
0176 if exist( sprintf('%s/netgen.exe',netgen_path) , 'file' ) || ...
0177 exist( sprintf('%s/bin/netgen.exe',netgen_path) , 'file' )
0178 disp('Found netgen version 4.4 or higher');
0179 netgen_exe = netgen_path;
0180 if exist( sprintf('%s/bin/netgen.exe',netgen_path) , 'file' )
0181 netgen_exe = [netgen_path '/bin'];
0182 end
0183
0184 fid= fopen([cache_path, '/ng.bat'],'w');
0185 if fid<0; error('Unable to write to %s',cache_path); end
0186 fprintf(fid,'set TCL_LIBRARY=%s/lib/tcl8.3\n', netgen_path);
0187 fprintf(fid,'set TIX_LIBRARY=%s/lib/tix8.1\n', netgen_path);
0188 fprintf(fid,'set NETGENDIR=%s\n', netgen_path);
0189 fprintf(fid,'"%s/netgen.exe" %%*\n', netgen_exe);
0190 fclose(fid);
0191 elseif exist( sprintf('%s/ng431.exe',netgen_path) , 'file' )
0192 disp('Found netgen version 4.3.1');
0193 fid= fopen([cache_path, '/ng.bat'],'w');
0194 if fid<0; error('Unable to write to %s',cache_path); end
0195 fprintf(fid,'set TCL_LIBRARY=%s/lib/tcl8.3\n', netgen_path);
0196 fprintf(fid,'set TIX_LIBRARY=%s/lib/tcl8.2\n', netgen_path);
0197 fprintf(fid,'"%s/ng431.exe" %%*\n', netgen_path);
0198 fclose(fid);
0199 else
0200 warning(['cannot find a version of netgen that I know about\n' ...
0201 'Install netgen or check the path\n']);
0202 end
0203 end
0204 end
0205 catch e
0206 if strncmp(computer,'PC',2)
0207
0208 setenv('NETGEN_USER_DIR', oldpath);
0209 end
0210 rethrow(e)
0211 end
0212 end