Challenge

Project 1 - Parsing NASA thermodynamic data

Main code:

clear all
close all
clc


% Reading Data file - NASA Thermodynamic
% Open a file & 'r' Open the file for reading

f1 = fopen('THERMO.dat','r');
line1=fgetl(f1);
line2=fgetl(f1);
t = strsplit(line2,'');
R = 8.314;

% obtaining temperature by reading header information

for i = 1:3
fgetl(f1);
end

for i = 1:1

get = fgetl(f1);
A = strsplit(get, ' ');
species_sp = A{1};

len=length(A);

local_low_temp=str2double(A{len-3});
local_high_temp=str2double(A{len-2});
local_mid_temp=str2double(A{len-1});

temp = linspace(local_low_temp,local_high_temp,300);


tline_2 = fgetl(f1);
tline_3 = fgetl(f1);
tline_4 = fgetl(f1);

a = strfind(tline_2,'E');
b = strfind(tline_3,'E');
c = strfind(tline_4,'E');

% high temperature coefficients

a1 = str2double(tline_2(1:a(1)+3));

a2 = str2double(tline_2(a(1)+4:a(2)+3));


a3 = str2double(tline_2(a(2)+4:a(3)+3));


a4 = str2double(tline_2(a(3)+4:a(4)+3));

a5 = str2double(tline_2(a(4)+4:a(5)+3));


a6 = str2double(tline_3(1:b(1)+3));

a7 = str2double(tline_3(b(1)+4:b(2)+3));

% low temp coefficients

a8 = str2double(tline_3(b(2) + 4:b(3)+3));

a9 = str2double(tline_3(b(3) + 4:b(4)+3));

a10 = str2double(tline_3(b(4) + 4:b(5)+3));



a11 = str2double(tline_4(1:c(1)+3));

a12 = str2double(tline_4(c(1)+4:c(2)+3));

a13 = str2double(tline_4(c(2) + 4:c(3)+3));

a14 = str2double(tline_4(c(3)+4:c(4)+3));

% specific heat calculation
Cp = specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,temp,R,local_mid_temp);

% enthalpy calculation
H = enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,temp,R,local_mid_temp);

% entropy calculation
S = entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,temp,R,local_mid_temp);


% calculating molecular weight of species molecularweight (i) =
% molecular_weight(species_sp);


% % read & write molecular list
% molecular_list = fopen('molecular weight.txt','a+');
% fprintf(molecular_list,'molecular weight of %s is %d n',species_sp,molecular_weight);
% fclose(molecular_list);

%plotting (Cp , H, S, temp, Species_SP)
% saving as a folder

cur_dir = pwd;

cd(species_sp);

% plot 1,specific heat(cp) vs temperature range (temp)
figure(1)
plot(temp, Cp,'linewidth',2,'color','r');
xlabel('Temperature [K]');
ylabel('Specific heat [KJ]');
title (sprintf('varying specific heat with temperature range of % S', species_sp));
grid on
saveas(figure(1),'specific heat.jpg');

% plot 2, enthalpy (h) vs temperature range (temp)
figure(2)
plot(temp, H,'linewidth',2,'Color','g');
xlabel('Temperature [K]');
ylabel('Enthalpy in [KJ/(mol)]');
title (sprintf('varying enthalpy with temperatutre range of % S', species_sp));
grid on
saveas(figure(2),'enthalpy.jpg');

% plot 3, entropy(s) vs temperature range(temp)
figure(3)
plot (temp, S,'linewidth',2,'color','b');
xlabel('Temperature [K]');
ylabel('Entropy in [KJ/(mol-K)]');
title(sprintf('varying entropy with temperature range of % S',species_sp));
grid on
saveas(figure(3),'entropy.jpg');
cd(cur_dir);

% molecularweight

elements = ['H','C', 'O','N','A'];

% standard atomic number
atomic_weight = [1.007 12 16 14.007 39];

% starting range of molecule

molecular_weight = 0;
% adding atomic number to obtain particular value

for k = 1:length(species_sp)
for j = 1:length(elements)

if (species_sp(k)),(elements(j));

molecular_weight = molecular_weight + atomic_weight(j);
a =j;
end
end
n = str2double(species_sp(k));
if n>1
molecular_weight = molecular_weight + atomic_weight(a)*(n-1);
end

end

fprintf('molecular weight % S:', species_sp);
fprintf('%d', molecular_weight);
disp('');
f2 = fopen('molecular mass', 'W');
fprintf('% S n % S n % f', 'species','molecularmass','M');
fclose(f2);
end

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.