Challenge

Project 1 - Parsing NASA thermodynamic data

clear all
close all
clc
%assigning the file name and reading the file

f1=fopen('THERMO.dat','r');

%for reading the file from line no 01 to line no 05
for i=1:5
  fgetl(f1);
end

for i=1:53
%after reading till line no 05 we can proceed for line no 6 to we use fgetl
%again for that.

line1 = fgetl(f1);

%now from line no 6 we have to find the first species name that is 'O', so will split the line by

tline1=strsplit(line1,' ');
%can find it by
species = char(tline1(1));

%now we will take dot (.) as a reference which is common in line 6 for
%furthur findings

find_dot=strfind(line1,'.');
local_low_temp=str2double(line1(find_dot(1)-3:find_dot(1)));
local_high_temp=str2double(line1(find_dot(2)-4:find_dot(2)));
local_mid_temp=str2double(line1(find_dot(3)-4:find_dot(3)));

%now we have to find the coefficients from next line onwards and for that
%first we have to find the reference common point that is E position

line2=fgetl(f1);
line3=fgetl(f1);
line4=fgetl(f1);

%finding the position of E in all three remaining lines of coefficient of
%species O

a=strfind(line2,'E');
b=strfind(line3,'E');
c=strfind(line4,'E');

%finding all the coefficients of high temperature
a1=str2double(line2(1:a(1)+3));
a2=str2double(line2(a(1)+4:a(2)+3));
a3=str2double(line2(a(2)+4:a(3)+3));
a4=str2double(line2(a(3)+4:a(4)+3));
a5=str2double(line2(a(4)+4:a(5)+3));
a6=str2double(line3(1:b(1)+3));
a7=str2double(line3(b(1)+4:b(2)+3));

%finding all the coefficient of low temperature
a8=str2double(line3(b(2)+4:b(3)+3));
a9=str2double(line3(b(3)+4:b(4)+3));
a10=str2double(line3(b(4)+4:b(5)+3));
a11=str2double(line4(1:c(1)+3));
a12=str2double(line4(c(1)+4:c(2)+3));
a13=str2double(line4(c(2)+4:c(3)+3));
a14=str2double(line4(c(3)+4:c(4)+3));

%finding specific heat for the first seven high-temperature coeffi and last
%seven low temp coefficient. here we use the if loop because due to condition of
%high and low temperature

T=linspace(local_low_temp,local_high_temp,100);
R=8.314  ;             %(Universal gas constant in j/k-mol)
if T> local_mid_temp
% for first a1 to a7 seven coeff
Cp=(a1+(a2*T)+(a3*(T.^2))+(a4*(T.^3))+(a5*(T.^4))).*R;         %Cp=specific heat 
else
% for last a8 to a14 seven coeff
Cp=(a8+(a9*T)+(a10*(T.^2))+(a11*(T.^3))+(a12*(T.^4))).*R;
% Cp=((a8+a9.*T+a10.*T.^2+a11.*T.^3+a12.*T.^4).*R);
end

%finding Enthalpy for first seven high-temperature coeffi and last
%seven low temp coefficient. here we use the if loop because due to the condition of
%high and low temperature.
if T>local_mid_temp
%for first a1 to a7 seven coefficient
H = (a1+(a2.*T./2)+(a3.*T.^2/3)+(a4.*T.^3/4)+(a5.*T.^4/5)+(a6./T).*R.*T); %H=enthalpy
else
% for last a8 to a14 seven coeff
H = (a8+(a9.*T./2)+(a10.*T.^2/3)+(a11.*T.^3/4)+(a12.*T.^4/5)+(a13./T).*R.*T);
end 

%finding Entropy for first seven high-temperature coeffi and last
%seven low temp coefficient. here we use the if loop because due to the condition of
%high and low temperature.

if T>local_mid_temp
%for first a1 to a7 seven coefficient
    S = ((a1*log(T)+(a2.*T)+(a3.*T.^2/2)+(a4.*T.^3/3)+(a5.*T.^4/4)+a7).*R); %S=entropy
else
  %for first a8 to a14 seven coefficient
S = ((a8*log(T)+(a9.*T)+(a10.*T.^2/2)+(a11.*T.^3/3)+(a12.*T.^4/4)+a13).*R) ;
end

%finding the molecular weight of all the species
m_wt=Molecular_wt_of_species(species);

%creating the folder for the species
t=sprintf('%s %s',species);
mkdir(t)


%going inside the species folder
cd(t)


%plotting

figure(1)
plot(Cp,T,'linewidth',3,'color','r') 
ylabel('Temperature');
xlabel('Cp');
saveas(1,'CP.jpg')

figure(2)
plot(H,T,'LineWidth',3,'color','b')
ylabel('Temperature');
xlabel('Enthaply');
saveas(2,'H.jpg')

figure(3)
plot(S,T,'linewidth',3,'color','y');
ylabel('Temperature');
xlabel('Entropy');    
saveas(3,'S.jpg')


%going back into the main folder
cd ..
end



function program to find the molecular weight

function molecular_wt=Molecular_wt_of_species(species)
elements = ['H','C','O','N','R'];
Atomic_weight=[1,12,16,14,40];

molecular_wt=0;
for i=1:length(species);
    for j=1:length(elements);
if strcmp(species(i),elements(j));
    molecular_wt=molecular_wt+Atomic_weight(j);
end
    end
end
end





all output curve for oxygen

all output curves for nitrogen

all output curves for co2

output folders of 53 species

error faced while coding

error 1

error 2

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.