Invalid identifier, the code is unable to use the fprintf function

4 views (last 30 days)
% XROTOR COMMAND FILE WRITER
disp('XROTOR command file writer begin!')
disp(['BATCH # ' num2str(batch_cntr) '.Iteration # ' num2str(iteration_number) '.'])
%Make text file with XROTOR commands
clear fid
fid = fopen([case_working_dir '\command.dat'],'wt');
%ACCEPT DEF FILE
fprintf(fid,'\n'); % Error Line, "Invalid file identifier".
%AERODYNAMICS Menu - Blade Section Properties
if rotor_choice == 1 || rotor_choice == 2
fprintf(fid,'aero\n');
fprintf(fid,'new\n'); % Create a new aero section
fprintf(fid,'1\n'); % Enter r/R for new section
fprintf(fid,'edit\n');
fprintf(fid,'1\n'); % Enter index of aero section 1 to process
fprintf(fid,'1\n'); % select Zero-lift alpha (deg)
fprintf(fid,[num2str(zero_lift_alpha) '\n']);
fprintf(fid,'2\n'); % select d(Cl)/d(alpha)
fprintf(fid,[num2str(dcl_dalpha) '\n']);
fprintf(fid,'3\n'); % select d(Cl)/d(alpha)@stall
fprintf(fid,[num2str(dcl_dalpha_stall) '\n']);
fprintf(fid,'4\n'); % select Maximum Cl
fprintf(fid,[num2str(max_cl) '\n']);
fprintf(fid,'5\n'); % select Minimum Cl
fprintf(fid,[num2str(min_cl) '\n']);
fprintf(fid,'6\n'); % select Cl increment to stall
fprintf(fid,[num2str(cl_inc_stall) '\n']);
fprintf(fid,'7\n'); % select Minimum Cd
fprintf(fid,[num2str(min_cd) '\n']);
fprintf(fid,'8\n'); % select Cl at minimum Cd
fprintf(fid,[num2str(cl_min_cd) '\n']);
fprintf(fid,'9\n'); % select d(Cd)/d(Cl**2)
fprintf(fid,[num2str(dcd_dcl2) '\n']);
fprintf(fid,'10\n'); % select Reference Re number
fprintf(fid,[num2str(Reynolds) '\n']);
fprintf(fid,'11\n'); % select Re scaling exponent
fprintf(fid,[num2str(REexp) '\n']);
fprintf(fid,'12\n'); % select Cm - pitching moment coefficient
fprintf(fid,[num2str(cm) '\n']);
fprintf(fid,'13\n'); % select Mcrit - critical Mach number
fprintf(fid,[num2str(mcrit) '\n']);
fprintf(fid,'\n');
fprintf(fid,'edit\n');
fprintf(fid,'2\n'); % Enter index of aero section 2 to process
fprintf(fid,'1\n'); % select Zero-lift alpha (deg)
fprintf(fid,[num2str(zero_lift_alpha) '\n']);
fprintf(fid,'2\n'); % select d(Cl)/d(alpha)
fprintf(fid,[num2str(dcl_dalpha) '\n']);
fprintf(fid,'3\n'); % select d(Cl)/d(alpha)@stall
fprintf(fid,[num2str(dcl_dalpha_stall) '\n']);
fprintf(fid,'4\n'); % select Maximum Cl
fprintf(fid,[num2str(max_cl) '\n']);
fprintf(fid,'5\n'); % select Minimum Cl
fprintf(fid,[num2str(min_cl) '\n']);
fprintf(fid,'6\n'); % select Cl increment to stall
fprintf(fid,[num2str(cl_inc_stall) '\n']);
fprintf(fid,'7\n'); % select Minimum Cd
fprintf(fid,[num2str(min_cd) '\n']);
fprintf(fid,'8\n'); % select Cl at minimum Cd
fprintf(fid,[num2str(cl_min_cd) '\n']);
fprintf(fid,'9\n'); % select d(Cd)/d(Cl**2)
fprintf(fid,[num2str(dcd_dcl2) '\n']);
fprintf(fid,'10\n'); % select Reference Re number
fprintf(fid,[num2str(Reynolds) '\n']);
fprintf(fid,'11\n'); % select Re scaling exponent
fprintf(fid,[num2str(REexp) '\n']);
fprintf(fid,'12\n'); % select Cm - pitching moment coefficient
fprintf(fid,[num2str(cm) '\n']);
fprintf(fid,'13\n'); % select Mcrit - critical Mach number
fprintf(fid,[num2str(mcrit) '\n']);
fprintf(fid,'\n');
fprintf(fid,'\n');
end
%LOAD ROTOR
if rotor_choice == 1
fprintf(fid,'arbi\n');
fprintf(fid,[num2str(nb) '\n']); % define number of blades
fprintf(fid,[num2str(vs) '\n']); % define flight speed(m/s)
fprintf(fid,[num2str(rt) '\n']); % define tip radius
fprintf(fid,[num2str(rh) '\n']); % define hub radius
fprintf(fid,[num2str(number_radial_stations) '\n']); % define number of radial stations
fprintf(fid,[num2str(span1) ' ' num2str(chord1) ' ' num2str(angle1) '\n']); %set SPAN, CHORD and ANGLE of station 1
fprintf(fid,[num2str(span2) ' ' num2str(chord2) ' ' num2str(angle2) '\n']); %set SPAN, CHORD and ANGLE of station 2
fprintf(fid,[num2str(span3) ' ' num2str(chord3) ' ' num2str(angle3) '\n']); %set SPAN, CHORD and ANGLE of station 3
fprintf(fid,[num2str(span4) ' ' num2str(chord4) ' ' num2str(angle4) '\n']); %set SPAN, CHORD and ANGLE of station 4
fprintf(fid,[num2str(span5) ' ' num2str(chord5) ' ' num2str(angle5) '\n']); %set SPAN, CHORD and ANGLE of station 5
fprintf(fid,[num2str(span6) ' ' num2str(chord6) ' ' num2str(angle6) '\n']); %set SPAN, CHORD and ANGLE of station 6
fprintf(fid,[num2str(span7) ' ' num2str(chord7) ' ' num2str(angle7) '\n']); %set SPAN, CHORD and ANGLE of station 7
fprintf(fid,[num2str(span8) ' ' num2str(chord8) ' ' num2str(angle8) '\n']); %set SPAN, CHORD and ANGLE of station 8
fprintf(fid,[num2str(span9) ' ' num2str(chord9) ' ' num2str(angle9) '\n']); %set SPAN, CHORD and ANGLE of station 9
fprintf(fid,[num2str(span10) ' ' num2str(chord10) ' ' num2str(angle10) '\n']); %set SPAN, CHORD and ANGLE of station 10
fprintf(fid,[num2str(span11) ' ' num2str(chord11) ' ' num2str(angle11) '\n']); %set SPAN, CHORD and ANGLE of station 11
fprintf(fid,[num2str(span12) ' ' num2str(chord12) ' ' num2str(angle12) '\n']); %set SPAN, CHORD and ANGLE of station 12
fprintf(fid,'n\n'); % no corrections
elseif rotor_choice == 2
if lift_const == 1
fprintf(fid,'desi\n'); % go to design menu
fprintf(fid,'inpu\n'); % input design parameters
fprintf(fid,[num2str(nb) '\n']); % define number of blades
fprintf(fid,[num2str(rt) '\n']); % define tip radius
fprintf(fid,[num2str(rh) '\n']); % define hub radius
fprintf(fid,[num2str(rw) '\n']); % define hub wake displacement body radius
fprintf(fid,[num2str(vs) '\n']); % define airspeed(m/s)
fprintf(fid,[num2str(r_adv_desi) '\n']); % define advance ratio - (0 to prescribe rpm)
fprintf(fid,[num2str(rpm_desi) '\n']); % define RPM
fprintf(fid,[num2str(thrust_desi) '\n']); % define thrust(N) - (0 to prescribe power)
fprintf(fid,[num2str(power_desi) '\n']); % define power(W)
fprintf(fid,[num2str(lift_cc) '\n']); % define lift coefficient constant
fprintf(fid,'\n');
fprintf(fid,'\n');
fprintf(fid,'\n');
fprintf(fid,'oper\n'); %go to OPER menu
fprintf(fid,['angl ' num2str(angle_ba) '\n']); %change/set blade pitch angle
fprintf(fid,'\n');
elseif lift_const == 0
fprintf(fid,'desi\n'); % go to design menu
fprintf(fid,'inpu\n'); % input design parameters
fprintf(fid,[num2str(nb) '\n']); % define number of blades
fprintf(fid,[num2str(rt) '\n']); % define tip radius
fprintf(fid,[num2str(rh) '\n']); % define hub radius
fprintf(fid,[num2str(rw) '\n']); % define hub wake displacement body radius
fprintf(fid,[num2str(vs) '\n']); % define airspeed(m/s)
fprintf(fid,[num2str(r_adv_desi) '\n']); % define advance ratio - (0 to prescribe rpm)
fprintf(fid,[num2str(rpm_desi) '\n']); % define RPM
fprintf(fid,[num2str(thrust_desi) '\n']); % define thrust(N) - (0 to prescribe power)
fprintf(fid,[num2str(power_desi) '\n']); % define power(W)
fprintf(fid,'\n');
fprintf(fid,'cl\n'); % select linear lift coefficient
fprintf(fid,[num2str(root_cl) '\n']); % define root lift coefficient
fprintf(fid,[num2str(tip_cl) '\n']); % define tip lift coefficient
fprintf(fid,'\n');
fprintf(fid,'\n');
fprintf(fid,'\n');
fprintf(fid,'oper\n'); %go to OPER menu
fprintf(fid,['angl ' num2str(angle_ba) '\n']); %change/set blade pitch angle
fprintf(fid,'\n');
end
elseif rotor_choice == 3
fprintf(fid,['load external_rotor_' num2str(batch_cntr) '.txt\n']);
fprintf(fid,'oper\n'); %go to OPER menu
fprintf(fid,['angl ' num2str(angle_ba) '\n']); %change/set blade pitch angle
fprintf(fid,'\n');
end
%SAVE FINAL GEOMETRY
fprintf(fid,'save rotor_geometry.txt\n'); %save rotor to restart file
fprintf(fid,'y\n'); %output override
% AERODYNAMIC INPUTS
if standard_atmo == 1 %Set fluid properties from standard atmosphere
fprintf(fid,['atmo ' num2str(f_alt) '\n']); %go to ATMO menu and define flight altitude (km)
elseif stardard_atmo == 0
fprintf(fid,['vsou ' num2str(ca) '\n']); %set fluid speed of sound, m/s
fprintf(fid,['dens ' num2str(rho) '\n']); %set fluid density, kg/m^3
fprintf(fid,['visc ' num2str(mu) '\n']); %set (absolute) dynamic viscosity, kg/m-s
end
%Operation Menu - Viscous Mode
fprintf(fid,'oper\n'); %go to operation menu
fprintf(fid,'iter 450\n');%define maximum number of iterations
fprintf(fid,'N\n'); %change number of radial points
fprintf(fid,[num2str(number_radial_points) '\n']);
fprintf(fid,['name ' name '\n']); % set/change case name
fprintf(fid,['velo ' num2str(vs) '\n']); %change/set flight speed(m/s)
fprintf(fid,'form\n'); %select slipstream and velocity formulation
% fprintf(fid,'vrtx\n');
fprintf(fid,'pot\n'); %Potential Formulation selected
fprintf(fid,'\n'); %go back to OPER menu
%rpms sweeps or single rpm
if rpm_sweep_on == 0
fprintf(fid,['rpm ' num2str(rpm) '\n']);
elseif rpm_sweep_on == 1
fprintf(fid,['rseq ' num2str(rpm_start) ' ' num2str(rpm_end) ' ' num2str(rpm_step) '\n']); % define sequences of rpms
if fixed_pitch == 1
fprintf(fid,'A\n');
elseif fixed_power == 1
fprintf(fid,'P\n');
elseif fixed_thrust == 1
fprintf(fid,'T\n');
end
end
%save AERO data
fprintf(fid,'writ general_data.txt\n'); % write current operating point to disk file
%save VELOCITY data
fprintf(fid,'wvel\n'); %write velocity data to disk file
fprintf(fid,'N\n'); %new file
fprintf(fid, 'veloc_data_xrotor.txt\n'); %output filename
% PLOTING - operation menu
fprintf(fid,'plot 1\n'); % plot geometry
fprintf(fid,'hard\n'); %hardcopy current plot
fprintf(fid,'plot 2\n'); % plot axial geometry (all blades)
fprintf(fid,'hard\n'); % hardcopy current plot
fprintf(fid,'plot 3\n'); % plot radial distributions for current case
fprintf(fid,'hard\n'); % hardcopy current plot
fprintf(fid,'plot 4\n'); % plot radial distributions plus geometry
fprintf(fid,'hard\n'); % hardcopy current plot
fprintf(fid,'plot 5\n'); % plot radial distributions for all cases
fprintf(fid,'hard\n'); % hardcopy current plot
fprintf(fid,'plot 6\n'); % plot case sequence parameters
fprintf(fid,'hard\n'); % hardcopy current plot
fprintf(fid,'plot 7\n'); % plot induced velocities on blade vs r/R
fprintf(fid,'hard\n'); % hardcopy current plot
fprintf(fid,'plot 8\n'); % plot induced velocities in slipstream vs r/R
fprintf(fid,'hard\n');
fprintf(fid,'plot 9\n'); % plot velocity triangles
fprintf(fid,'hard\n'); % hardcopy current plot
% fprintf(fid,'plot 10\n'); % plot external slipstream velocity profiles
% fprintf(fid,'hard\n'); % hardcopy current plot
% fprintf(fid,'plot 11\n'); % plot
% fprintf(fid,'hard\n'); % hardcopy current plot
fprintf(fid,'plot 12\n'); %plot blade data (Gam,CL,CD,etc) vs r/R
fprintf(fid,'h\n'); %hardcopy plot reference x,y data
fprintf(fid,'w\n'); %write plot data to file
fprintf(fid,'blade_data.txt\n'); %plot data save filename
fprintf(fid,'\n');
fprintf(fid,'cput blade_currentcase.txt\n'); %Write current case accumulator to file
fprintf(fid,'\n');
% fprintf(fid,'vput slipstream_velocities.txt\n'); %Save slipstream velocity profiles
fprintf(fid,'quit\n');
%End file write
status = fclose(fid);
%disp(['BATCH # ' num2str(batch_cntr) '. Iteration # ' num2str(iteration_number) '.'])
disp('XFOIL command file writer end!')
% Code written by Tais Carneiro
% Mechanical engineering undergraduate at Federal University of Rio de
% Janeiro
% e-mail: tais.carneiro.castro@poli.ufrj.br
%% Getting Following Error
Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
  10 Comments
Walter Roberson
Walter Roberson on 18 Feb 2020
(We can already predict that the directory does not exist. So you need to examine the directory name and figure out why not.
Adam
Adam on 18 Feb 2020
Whatever you pass to fopen needs to be something you could also locate by pastinig the path part of it into Windows Explorer and finding the name.extension part within that folder. If you can't then you need to change it so that you can.

Sign in to comment.

Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!