📄 saveeng.m
字号:
function saveeng(motor,info,fname)
%SAVEENG Save rocket motor data to wRASP file.
% SAVEENG(MOTOR,INFO[,FNAME]) displays a file selection window
% where you can select the file to which you which to write
% the rocket motor data to. INFO is a cellstr with three elements
% which contains information regarding the motor, testing, manufacturer,
% and copyright info etc. MOTOR have to be a structure:
%
% MOTOR.NAME : the motor code
% MOTOR.MANUF : the manufacturer
% MOTOR.D : the diameter [mm]
% MOTOR.L : the length [mm]
% MOTOR.DELAY : delay charge(s) [s]
% MOTOR.MF : mass of fuel [kg]
% MOTOR.MM : mass of empty motor [kg]
% MOTOR.THRUST : the thrust curve (Nx2) matrix
% 1st col. in [s], 2:nd col. in [N]
%
% The wRASP file generated will then be placed in the directory
% .../motor/eng/
%
% See also LOADENG, PLOTENG, RCKSIM.
% Copyright (c) 2003-01-12, B. Rasmus Anthin.
% Revision: 2003-01-16,
% 2003-06-19 - 2003-06-20.
%GET FILE NAME
godir(mfilename)
cd(fullfile('motor','eng'))
error(nargchk(2,3,nargin))
if nargin==2 | isempty(fname)
fname='*.eng';
elseif ~any(fname=='.')
fname=[fname '.eng'];
end
[fname,path]=uiputfile(fname,'Save Motor Data');
godir
%ERROR CONTROL
if ~iscellstr(info)
error('Parameter INFO must be cell string.')
end
names=fieldnames(motor);
if length(names)~=8
error('Motor structure must contain proper elems.')
end
if ~ischar(motor.name)
error('Field ''name'' must be a string.')
elseif ~ischar(motor.manuf)
error('Field ''manuf'' must be a string.')
elseif ~isnumeric(motor.D)
error('Field ''D'' must be numeric.')
elseif ~isnumeric(motor.L)
error('Field ''L'' must be numeric.')
elseif ~isnumeric(motor.delay)
error('Field ''delay'' must be numeric.')
elseif ~isnumeric(motor.mf)
error('Field ''mf'' must be numeric.')
elseif ~isnumeric(motor.mm)
error('Field ''mm'' must be numeric.')
elseif ~isnumeric(motor.thrust)
error('Field ''thrust'' must be numeric.')
end
if length(motor.D)~=1
error('Field ''D'' must have exactly one element.')
elseif length(motor.L)~=1
error('Field ''L'' must have exactly one element.')
elseif ~length(motor.delay)
error('Field ''delay'' must be non-empty.')
elseif length(motor.mf)~=1
error('Field ''mf'' must have exactly one element.')
elseif length(motor.mm)~=1
error('Field ''mm'' must have exactly one element.')
elseif size(motor.thrust,2)~=2
error('Field ''thrust'' must be a Nx2 matrix.')
end
%CREATE FILE OR OVERWRITE
if ~sum(fname)
warning('Cancelled by user.')
else
fp=fopen(fullfile(path,fname),'w');
for i=1:length(info)
fprintf(fp,['; ' info{i} '\n']);
end
name=motor.name;
D=num2str(motor.D);
L=num2str(motor.L);
delay=delaycat(motor.delay);
mf=num2str(motor.mf);
m0=num2str(motor.mm + motor.mf); %launch/full/total mass
manuf=motor.manuf;
T=motor.thrust;
fprintf(fp,strbcat(name,D,L,delay,mf,m0,manuf));
i=0;
for i=1:size(T,1)
fprintf(fp,' %.3f %.3f\n',T(i,:));
end
fprintf(fp,';');
fclose(fp);
end
function str=strbcat(varargin)
str='';
for i=1:length(varargin)
str=[str varargin{i} ' '];
end
str=[deblank(str) '\n'];
function str=delaycat(delay)
str='';
for i=1:length(delay)
str=[str '-' num2str(delay(i))];
end
str=str(2:end);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -