

















close all
clear all
clc
% C:\matlab_program\images\
f=fopen('THERMO.dat','r');
%file header
fileheader=fgetl(f);
% for second line
S=fgetl(f);
% second line data is split using command
S=strsplit(S,' ');
% in numeric values it is converted
global_low_temp=str2num(S{2});
global_mid_temp=str2num(S{3});
global_high_temp=str2num(S{4});
% skipping lines
for j=1:3
fgetl(f);
end
mkdir('nasa')
cd(sprintf('nasa'))
% extracting all species data
for i=1:53
% to get line
species=fgetl(f);
% finding string by separater = '.'
% String temperatures are determined by .. Assuming 3, 4, 4 digit
% temperatures
% O L 1/90O 1 G 200.000 3500.000 1000.000
a=strfind(species,'.');
% t variable for temperature(
T1 =species((a(1)-3):(a(1)+3));
% local low temperature
T_low=str2double(T1);
T2 =species(a(2)-4:a(2)+3);
% local mid temperature
T_mid =str2double(T2);
T3 = species(a(3)-4:a(3)+3);
% local high temperature
T_high = str2double(T3);
% longest name has 6 alphabets, for short string extra spaces will be
% included in variable
species_name=species(1:6)
% fprintf("debug %s" ,species_name)
% getting first line of species
line_1=fgetl(f);
% extracting constant from species with Separater = 'E'
L1 = strfind(line_1,'E');
a1=str2double(line_1(1:(L1(1)+3)));
a2=str2double(line_1((L1(1)+4):(L1(2)+3)));
a3=str2double(line_1((L1(2)+4):(L1(3)+3)));
a4=str2double(line_1((L1(3)+4):(L1(4)+3)));
a5=str2double(line_1((L1(4)+4):(L1(5)+3)));
% reading second species line
Line_2 = fgetl(f);
% extracting line 2
L2=strfind(Line_2,'E');
a6=str2double(Line_2(1:(L2(1)+3)));
a7=str2double(Line_2((L2(1)+4):(L2(2)+3)));
a8=str2double(Line_2((L2(2)+4):(L2(3)+3)));
a9=str2double(Line_2((L2(3)+4):(L2(4)+3)));
a10=str2double(Line_2((L2(4)+4):(L2(5)+3)));
% reading 3rd line of species
Line_3 = fgetl(f);
%extracting 3rd line
L3=strfind(Line_3,'E');
a11=str2double(Line_3(1:(L3(1)+3)));
a12=str2double(Line_3((L3(1)+4):(L3(2)+3)));
a13=str2double(Line_3((L3(2)+4):(L3(3)+3)));
a14=str2double(Line_3((L3(3)+4):(L3(4)+3)));
% taking 1000 values
Temperature =linspace(T_low,T_high,1000);
% universal gas constant
R=8.314;
k=1:length(Temperature);
if Temperature(k)>T_mid
% high temperature coefficient
specific_heat = (a1+a2.*Temperature+a3.*Temperature.^2+a4.*Temperature.^3+a5.*Temperature.^4).*R;
Enthalpy=(a1+(a2.*Temperature)./2+(a3.*Temperature.^2)./3+(a4.*Temperature.^3)./4+(a5.*Temperature.^2)./5+a6./Temperature).*Temperature.*R;
Entropy=(a1.*log(Temperature)+a2.*Temperature+(a3.*Temperature.^2)/2+(a4.*Temperature.^3)./3+(a5.*Temperature.^4)/4+a7).*R;
else
specific_heat = (a8+a9.*Temperature+a10.*Temperature.^2+a11.*Temperature.^3+a12.*Temperature.^4).*R;
Enthalpy=(a8+(a9.*Temperature)./2+(a10.*Temperature.^2)./3+(a11.*Temperature.^3)./4+(a12.*Temperature.^2)./5+a13./Temperature).*Temperature.*R;
Entropy=(a8.*log(Temperature)+a9.*Temperature+(a10.*Temperature.^2)/2+(a11.*Temperature.^3)./3+(a12.*Temperature.^4)/4+a14).*R;
end
elements = ['H','C','O','N','A','S'];
% atomic weight value
atomic_weight = [1.0079 12.0107 15.999 14.0067 39.948 32.065];
% molecular to be zero
mol_mass = 0;
for x = 1:length(species_name)
for y = 1:length(atomic_weight)
if strcmp (species_name(x),elements(y))
mol_mass = mol_mass+atomic_weight(y);
position = y;
end
end
n=str2double(species_name(x));
if n>1
mol_mass = mol_mass+atomic_weight(position)*(n-1);
end
end
fprintf('ans = molecular_weight of %s:%fu', species_name ,mol_mass);
% creating to new Dir Species_Name
mkdir(sprintf("%s", species_name))
% Switching to new Dir Species Name
cd (sprintf("%s", species_name))
figure(1);
plot(Temperature,specific_heat);
grid on
title(["Specific Heat of ", species_name]);
xlabel('Temperature')
ylabel('specific_heat')
saveas(figure(1),'cp vs temp.png');
figure(2)
plot(Temperature,Enthalpy);
grid on
title(["Enthalpy of ", species_name]);
xlabel('Temperature')
ylabel('Enthalpy')
saveas(figure(2),'H vs temp.png');
figure(3)
plot(Temperature,Entropy);
grid on
title(["Entrophy of ", species_name]);
xlabel('Temperature')
ylabel('Entropy')
saveas(figure(3),'S vs temp.png');
% switching to Dir nasa
cd ('..\')
end
fclose(f);
