The script that calls the xfoil script is something like this
Options=optimset('Display','iter','DiffMinChange',0.01,'TolCon',0.01)[rootWeightsSQP,rootDragSQP]=fmincon(@drag,goodrootweights,[],[],[],[],zeros(1,14),ones(1,14),@thicknessconstraint,Options);meanError=getstartweights(rootWeightsSQP,1);[cd,cl,rootAlpha]=drag(rootWeightsSQP);
and the script whichs opens xfoil is
function [cd,cl,alpha]=drag(w) global wingParameters constants % control points
p0=[1 0]'; p1=[0.8 w(1)*0.2-0.05]'; %p1=[0.8 w(1)*0.2-0.1]';
p2=[0.3 w(2)*0.15]'; %p2=[0.3 w(2)*0.2-0.05]';
p3=[0 -0.1]'; q1=[0 0.1]'; q2=[0.4 w(3)*0.2+0.1]'; q3=[0.8 w(4)*0.2-0.05]'; q4=[1 0]'; if length(w)<5 w=[w wingParameters.bezierw]; end % weights
zp=[w(5)*1.9+0.1 w(6)*1.9+0.1 w(7)*1.9+0.1 w(8)*1.9+0.1 w(9)*1.9+0.1]; zq=[w(10)*1.9+0.1 w(11)*1.9+0.1 w(12)*1.9+0.1 w(13)*1.9+0.1 w(14)*1.9+0.1]; % calculate connection point
p4=(4/(4+4))*p3+(4/(4+4))*q1; q0=p4; % calculate rational cubic Bezier for t[0,1]
lower=bezier([p0 p1 p2 p3 p4]',zp); upper=bezier([q0 q1 q2 q3 q4]',zq); fid=fopen('aerofoil.dat','w'); for i=1:101 fprintf(fid,'%20.18f %20.18f\n',lower(i,1),lower(i,2)); end for i=2:101 fprintf(fid,'%20.18f %20.18f\n',upper(i,1),upper(i,2)); end fclose(fid); a=340.3; %speed of sound
v=constants.V; %velocity
M=v/a; %Mach number
nu=0.00001461; %kinematic viscosity
L=wingParameters.localChord; %local chord length of wing section airfoil
Re=v*L/nu; %local Reynold's number
fid=fopen('commands.in','w'); fprintf(fid,'load %saerofoil.dat\n',constants.file_path); fprintf(fid,'GuyMartin\n'); fprintf(fid,'panel\n'); fprintf(fid,'plop\nG\n\n'); fprintf(fid,'oper\n'); fprintf(fid,'visc %f\n',Re); fprintf(fid,'M %f\n',M); fprintf(fid,'type 1\n'); fprintf(fid,'pacc\n'); fprintf(fid,'%spolar.dat\n',constants.file_path); fprintf(fid,'\n'); fprintf(fid,'iter\n250\n'); fprintf(fid,'cl %f\n',wingParameters.CL2d); fprintf(fid,'\n'); fprintf(fid,'\n'); fprintf(fid,'quit\n'); fclose(fid); run_xfoil_command=[constants.xfoil_path 'xfoil < ' constants.file_path 'commands.in > dump.out' ]; setenv('GFORTRAN_STDIN_UNIT','5'); %only for matlab on mac
setenv('GFORTRAN_STDOUT_UNIT','6'); %only for matlab on mac setenv('GFORTRAN_STDERR_UNIT','0'); %only for matlab on mac try system(run_xfoil_command) fid=fopen('polar.dat'); for i=1:13 tline = fgetl(fid); disp(tline); end fclose(fid); cl=str2num(tline(12:17)); cd=str2num(tline(20:28)); alpha=str2num(tline(3:8)); catch me cl=777; cd=777; alpha=777; end setenv('GFORTRAN_STDIN_UNIT','-1'); %only for matlab on mac setenv('GFORTRAN_STDOUT_UNIT','-1'); %only for matlab on mac setenv('GFORTRAN_STDERR_UNIT','-1'); %only for matlab on mac delete polar.dat
I am running this script on a windows 10 machine and I am using Xfoil 6.99. Do let me know if you have any idea what could have gone wrong because I have spent ages rectifying it and the error seems intermittent
Best Answer