function periodTable
output='scrn'; fOut=1;
if output=='file' fOut=fopen('planetPeriods.txt','wt'); end
fprintf('\n\n');
fprintf(fOut,'PLANETARY PROPERTIES TABLE\n');
fprintf(fOut,'========= ========== =====\n\n');
formatData='%5s %7.2f %9.2E %6.3f \n';
formatHeadings='%5s %7s %9s %6s \n';
fprintf(fOut,formatHeadings,'Name','Radius','Radius', 'Period');
fprintf(fOut,formatHeadings,' ',' (AU) ',' (km) ', '(year)');
fprintf(fOut,formatHeadings,'----','------','------', '------');
fIn=fopen('massAndRadius.txt','r');
rEarth=150E6;
secondsPerYear=365.25*3600*24;
while 1
line = fgetl(fIn);
if ~ischar(line), break, end
[token, remain] = strtok(line); planet=token;
if planet(1)=='%', continue, end
[garbage, remain]= strtok(remain); [garbage, remain]= strtok(remain);
radiusAU=str2double(strtok(remain)); radiusKm=rEarth*radiusAU;
period=keplersThird(1000*radiusKm); periodYears=period/secondsPerYear;
fprintf(fOut,formatData,planet,radiusAU,radiusKm,periodYears);
end
fclose(fIn);
if output=='file' fclose(fOut); end
end
function period=keplersThird(R)
G=6.67E-11; mSun=1.99E30;
period=sqrt(4*pi^2*R^3/(G*mSun));
end