Challenge

Project 1 - Parsing NASA thermodynamic data

FILE PARSING PROGRAM :

clear all
close all
clc

% Opening of NASA's thermodtnamic datas
f1 = fopen('THERMO.dat','r');
fgetl(f1);

%Obtaining of global max, min and medium temperature
global_temp = fgetl(f1);
temp_range = str2num(global_temp);
global_min_temp =temp_range(1);
global_mid_temp =temp_range(2);
global_max_temp =temp_range(3);

fgetl(f1);
fgetl(f1);
fgetl(f1);

for i=1:53

tline = fgetl(f1);
tline = strsplit(tline,' ');

species = tline{1};

local_low_temp =tline{end-3};
local_low_temp =str2num(local_low_temp);
local_mid_temp =tline{end-1};
local_mid_temp =str2num(local_mid_temp);
local_high_temp =tline{end-2};
local_high_temp =str2num(local_high_temp);

%Range of temperature
T = linspace(local_low_temp, local_high_temp);
R = 8.314;
line1 = fgetl(f1);
p1 = findstr(line1,'E');
a1 = str2num(line1(1:p1(1) + 3));
a2 = str2num(line1(p1(1)+4:p1(2)+3));
a3 = str2num(line1(p1(2)+4:p1(3)+3));
a4 = str2num(line1(p1(3)+4:p1(4)+3));
a5 = str2num(line1(p1(4)+4:p1(5)+3));
line2 = fgetl(f1);
p2 = findstr(line2,'E');
a6 = str2num(line2(1:p2(1) + 3));
a7 = str2num(line2(p2(1)+4:p2(2)+3));
a8 = str2num(line2(p2(2)+4:p2(3)+3));
a9 = str2num(line2(p2(3)+4:p2(4)+3));
a10 = str2num(line2(p2(4)+4:p2(5)+3));
line3 = fgetl(f1);
p3 = findstr(line3,'E');
a11 = str2num(line3(1:p3(1) + 3));
a12 = str2num(line3(p3(1)+4:p3(2)+3));
a13 = str2num(line3(p3(2)+4:p3(3)+3));
a14 = str2num(line3(p3(3)+4:p3(4)+3));


T = linspace(local_low_temp , local_high_temp,1000)

if T < local_mid_temp
cp = (a8 +a9 * T + a10 * T.^2 + a11 * T.^3 + a12 * T.^4) * R
H = (a8 + a9 *T/2 + a10 *T.^2/3 + a11 *T.^3/4 + a12 * T.^4/5 +a13./T) *R.*T
S = (a8 * log(T) + a9 * T + a10 * T.^2/2 +a11 *T.^3/3 +a12*T.^4/4 +a14) * R
else
cp = (a1 +a2 * T + a3 * T.^2 + a4 * T.^3 + a5 * T.^4) * R
H = (a1 + a2 *T/2 + a3 *T.^2/3 + a4 *T.^3/4 + a5 * T.^4/5 +a6./T) *R.*T
S = (a1 * log(T) + a2 * T + a3 * T.^2/2 +a4 *T.^3/3 +a5*T.^4/4 +a7) * R
end

figure (1)
plot(T,cp)
grid on
xlabel('Temperature')
ylabel('specific_heat')
title(species)

figure(2)
plot(T,H)
grid on
xlabel('Temperature')
ylabel('Enthalpy')
title(species)

figure(3)
plot(T,S)
grid on
xlabel('Temperatute')
ylabel('Entropy')
title(species)

mkdir(species)
cd (species)
saveas(1,'T vs CP','jpg')
saveas(2,'T vs H','jpg')
saveas(3,'T vs S','jpg')
cd ..
end

------------------------------------------------------------------------------------------------------------------------------------------

FUNCTION FOR FILE PARSING :

function MW = molecular_weight(name)
atoms = ['H', 'C', 'O', 'N', 'Ar'];
atomic_weights = [1.00784, 12.0107, 15.999, 14.0067, 39.948];

MW = 0;
for i = 1 : length(name)
for j = 1 : length(atoms)
if species(i)==atomic_names(j)
MW = MW + atomic_weight(j);
position = j;
end
end
n = str2num(name(i));
if n>1
MW = MW + atomic_weight(position) * (n-1);
end
end

------------------------------------------------------------------------------------------------------------------------------------------

CODE EXPLANATION :

Step 1 - Start the program with clear all, close all, and clc by using tis commands we can reduce unwanted overcodes in the edittor, workspace and command windows.

Step 2 - Open NASA's thermodynamic data using the specific code , make sure that the code and the NASA data should be in the same folder.

Step 3 - Obtain the global minimum, global maximun and global medium temperatures.

Step 4 - Generate the for loop and generate tline foe local minimum, local medium and local maximun temperatures.

Step 5 - Describe the range of temperatures foe P1, P2 And P3.

Step 6 - Plot the values in the formule given,

cp = (a1 +a2 * T + a3 * T.^2 + a4 * T.^3 + a5 * T.^4) * R
H = (a1 + a2 *T/2 + a3 *T.^2/3 + a4 *T.^3/4 + a5 * T.^4/5 +a6./T) *R.*T
S = (a1 * log(T) + a2 * T + a3 * T.^2/2 +a4 *T.^3/3 +a5*T.^4/4 +a7) * R

and find the values for CP, H and s.

Step 7 - Plot T vs CP as figure 1, plot T vs H as figure 2, plot T vs S as figure 3.

Step 8 - Make sure the condition is ended .

Step 9 - Generate a function to find the molecular weight.

Step 10 - Eloborate the atoms and their atomic weight as ,

atoms = ['H', 'C', 'O', 'N', 'Ar'];
atomic_weights = [1.00784, 12.0107, 15.999, 14.0067, 39.948] .

Step 11 - End the function and save the function in the same folder where the program is saved.

Step 12 - Run the main program.

------------------------------------------------------------------------------------------------------------------------------------------

ERRORS FACED WHILE PROGRAMMING :

i) While doing the range of temperatures I had a big problem in eloborating P1, P2, P3.

ii) While doing the formulae for CP, H & S I had faced many errors in the paranthesis.

------------------------------------------------------------------------------------------------------------------------------------------

STEPS TO OVERCOME THE ERROR:

Step 1 - Continuously I had red the code from top to bottom and debug the code.

Step 2 - The stafs helped me during the period through google meet.

------------------------------------------------------------------------------------------------------------------------------------------

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.