Challenge

Project 1 - Parsing NASA thermodynamic data

close all
clear all
clc

% opening and reading required file
file=fopen('THERMO.dat','r');

%heading
line1=fgetl(file);

% globel temperature values
line2=fgetl(file);

% next three line comments
des_1=fgetl(file);
des_2=fgetl(file);
des_3=fgetl(file);
A=strsplit(line2,' ');

globel_low_temperature=str2num(A{2});
globel_mid_temperature=str2num(A{3});
globel_high_temperature=str2num(A{4});

% specific information
for i=1:3
species=fgetl(file);
species_name=species(1:6);

Line_1=fgetl(file);

L1=strfind(Line_1,'E');

c1=str2num(Line_1(1:(L1(1)+3)));

c2=str2num(Line_1((L1(1)+4):(L1(2)+3)));

c3=str2num(Line_1((L1(2)+4):(L1(3)+3)));

c4=str2num(Line_1((L1(3)+4):(L1(4)+3)));

c5=str2num(Line_1((L1(4)+4):(L1(5)+3)));


Line_2=fgetl(file);

L2=strfind(Line_2,'E')

c6=str2num(Line_2(1:(L2(1)+3)));

c7=str2num(Line_2((L2(1)+4):(L2(2)+3)));

c8=str2num(Line_2((L2(2)+4):(L2(3)+3)));

c9=str2num(Line_2((L2(3)+4):(L2(4)+3)));

c10=str2num(Line_2((L2(4)+4):(L2(5)+3)));

Line_3=fgetl(file);

L3=strfind(Line_3,'E');

c11=str2num(Line_3(1:(L3(1)+3)));

c12=str2num(Line_3((L3(1)+4):(L3(2)+3)));

c13=str2num(Line_3((L3(2)+4):(L3(3)+3)));

c14=str2num(Line_3((L3(3)+4):(L3(4)+3)));
end


% creating folder for species

mkdir([' Users/Rahul/File parsing NASA/species/',species_name]);

% temperature range are assumed for calculation purpose

temperature=linspace(300,5000,100);

% universal gas constant
R=8.314;

% calculation of porperties based on lower and upper temperature
for j=1:length(temperature)
if temperature(j)<3000
Cp=(c1+c2.*temperature+c3.*temperature.^2+c4.*temperature.^3+c5.*temperature^4).*R;

H=(c1+(c2.*temperature)./2+(c3.*temperature.^2)/3+(c4.*temperature.^3)/4+(c5.*temperature^4/5)+c6.temperature).*temperature.*R;

S=(c1*log(temperature)+c2.*temperature+(c3.*temperature.^2)/2+(c4.*temperature^3)/3+(c5.*temperature.^4)/4+c7).*R;
else

Cp=(c8+c9.*temperature+c10.*temperature.^2+c11.*temperature.^3+c12.*temperature^4).*R;

H=(c8+(c9.*temperature)./2+(c10.*temperature.^2)/3+(c11.*temperature.^3)/4+(c12.*temperature^4/5)+c13./temperature).*temperature.*R;

S=(c8*log(temperature)+c9.*temperature+(c10.*temperature.^2)/2+(c11.*temperature^3)/3+(c12.*temperature.^4)/4+c14).*R;

end
end

%plotting

% temperature vs entropy
figure(1)
plot(temperature,S,'LineWidth',4,'color','b')
title(species_name)
xlabel('temperature')
ylabel('entropy')

% temperature vs enthalpy

figure(2)
plot(temperature,H,'LineWidth',4,'color','k')
title(species_name)
xlabel('temperature')
ylabel('enthalpy')

% temperature vs specific heat
figure(2)
plot(temperature,Cp,'LineWidth',4,'color','y')
title(species_name)
xlabel('temperature')
ylabel('specific heat')


directory=(['A: Users\Rahul\File parsing NASA\species\',species_name]);

% changing the filepath to save the plots cd(directory)
% saving the plots


saveas(1,'entropy.jpg')
saveas(2,'enthalpy.jpg')
saveas(3,'specific heat.jpg')

cd('A: Users\Rahul\File parsing NASA\species\')

%swiching the directory back to read thermodat file for molecular mass
%calculation

MM=molecular_mass(species_name);


fclose(file);

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.