Challenge

Project 1 - Parsing NASA thermodynamic data

Objectives :

To Write a program in Matlab to parse the NASA thermodynamics data file and then calculate thermodynamics properties of various species.

Requirements :

  • To write a function that extracts 14 co-efficient and calculate enthalpy,entropy and specific heat for all species in data file.
  • calculate Molecular weight of each species and displaying it in command window.
  • Plotting enthalpy , entropy , Cp for local temperature range specific for each species.
  • Save the plots as images with appropriate names and dump them in separate folders for each species with suitable name. All these should be generated automatically.
  • The main program that you will submit will just take the "THERMO.dat" file as an input and generate Cp, H and S plots.
  • Please write a detailed report to describe your logic.

Introductions :

  • Parsing means to make something understandable. for programming this means to convert information represented is one form into another form thats easier to work with.
  • This is done by partially analysing the data,understanding its underlying structure and then explicity representing that structure in the code.
  • a data stream of some sort and building an in memory model of the sematic content of the data.
  • this aims at facilitating performing some kind of transformation on the data.

Equations :

from the given themodyanic data it is clear that their are 53 species and each species their are 14 coefficient and for each species their ia a unique low,mid and high temperatureranges.

Where,

Cp = Specific Heat

R = Molor gas Constant

T =temperature

S = Entropy

H = Enthalpy

a = Coefficients

Defnations :

1) Specific Heat :

It is a ratio of the quantity of heat required o raise the temp. of a body one degree to that required to raise the temp. of an equal mass of water one degree.

2) Enathalpy :

it is a thermodynamics system is defined as the sun of its internal energy and the work required to achieve its pressure and volume.

3) Entropy :

it is a measure of degree of disorderness of the system.

Code : Explanation

main code

clear all
close all
clc
%Main code
%reading data
f1=fopen('THERMO.dat','r')
file_name=fgetl(f1)
t_line=fgetl(f1);
A=strsplit(t_line,' ');
%define the temerature extracted
global_low_temp=str2double(A{2});
global_mid_temp=str2double(A{3});
global_high_temp=str2double(A{4});
for i=(1:3)
comments=fgetl(f1);
end
for i=1:53
%extracting species name
species=fgetl(f1);
species_name=species(1:6);
%extracting coe from 1st line
line_1=fgetl(f1);
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)));
% Etracting coefficient from second line
line_2=fgetl(f1);
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)));
% Etracting coefficient from Third line
line_3=fgetl(f1);
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)));
% Creating folder
mkdir(['C:species',species_name]);
T=linspace(global_low_temp,global_high_temp,500);
% Calling thermodynamics function
[cp,h,s]=coeff(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T);
% Plot between temp and specific heat
figure(1)
plot(T,cp,'linewidth',3,'color','b')
title(species_name)
xlabel('temperature')
ylabel('specific heat')
% Plot between temp and Enthalpy
figure(2)
plot(T,h,'linewidth',3,'color','g')
title(species_name)
xlabel('temperature')
ylabel('enthalpy')
% Plot between temp and Entropy
figure(3)
plot(T,s,'linewidth',3,'color','c')
title(species_name)
xlabel('temperature')
ylabel('entropy')
directory = (['C:species',species_name]);
cd(directory)
% saving plots
saveas(1,'specific_heat.png')
saveas(2,'enthalpy.png')
saveas(3,'entropy.png')
% Changing directory for calculating moleular weight
cd('C:species');
molecular_weight = mole_wt(species_name);
end
fclose(f1)
Function code
%calculating thermodynamic properties
function [cp,h,s]=coeff(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T)
R=8.314
for j=1:length(T)
if T(j)<300
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;
else
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;
end
end
end
%calculating molecular weight
function [molecular_weight]=mole_wt(species_name)
species=upper(species_name)
constituents={'H','C','N','O','A'};
atomic_weight=[1 12 14 16 40]
molecular_weight=0;
for i=length(species)
for j=1:length(constituents)
if strcmp(species(i),constituents(j))
molecular_weight= molecular_weight+atomic_weight(j);
u=j;
end
end
n=str2double(species(i));
if n>1
molecular_weight=molecular_weight+atomic_weight(u)*(n-1);
end
end
fprintf('molecular_weigth of %s:- \',species_name)
fprintf('%d\n',molecular_weight)
fprintf(' \n')
fprintf('amu \n')
fprintf('n')
end

Explanation :

  • Initially the value of R is being defined.
  • then we use a command to open the file 'THERMO.dat'
  • Further we use the 'fget1' to start reading the lines and after reading the first two lines, from the second line converting the strings to numbers and assigning global temperatures.
  • Then we have written a command to get the temperature range for calculation and plotting purpose.
  • again using the fgetl command to go to thel next 3 lines ans skipping it
  • We use a for loop to get 53 species and their temperatures and the 14 coefficients.
  • in the for loop we again use the fgetl command and then the next line is read and from that line species name, the three local temperatures are read and stored.
  • we use fgetl command to go further line and get first 7 coefficients and store them. using the fgetl command we move to the next two lines and get the reamining coefficients.
  • after getting the 14 coefficients we use thease coefficients and by calling the functions we calculatecp,H,S.
  • In this plotting we use the figure command to get the thre different plots and saveas command to save the figures in
  • again we change our directory to start the loop , So loop continues to function till get all the 53 species and then gets terminated.

output

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.