Challenge

Project 1 - Parsing NASA thermodynamic data

MATLAb code for parse the data from NASA thermodynamics data for various properties of the gas properties

1. To write a function that extracts the 14 coefficients and calculates that enthalpy,entropy and specific heat for all the species in the thermodynamic data file i.e 'Thermo.dat'.

Where

R is the Unvisersal Gas constant

T is the temperture

2.To claculate the molecular weight for each species and display in the command window

3. To plot the cp,entropy and enthalpy for the local temperture range specific for each species

4. To save the plots as images with approprite name and dump them in separate floder for each species with Suitabble name automatically.

File Parsing

File parsing is used to information can be read from a particular text file or ant type of file and how that information can be used in a programm

1. Define the function.

2.Create an input parse object.

3.Add inputs to the scheme

4.set properties to adjust parsing.

5.parse the inputs

6.input in function

7.calling function

NASA Thermodynamic file

THERMO.dat file is containing the 53 differnt elements and 14 coefficients given by NASA.These coeffisients are utilized to calculate the specific heat,enthalpy,entropy,for particular element,below screenshot of the THERMO.dat file displayed.

.

Code Function:

1. SPecific heat

its is the ammount of heat added in the form of heat, to one unit of mass of the substance in order to cause an increase of one unit in its temperture.

% Function of the Specific heat

Function Cp = Specificheat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,Temp,R,global_medium_temp);

% CHecking for temperture

if Temp <= global _medium_temp

Cp = R*(a8+(a9*Temp) + (a10*(Temp).^2) + (a11*(Temp).^3) +(a12*(Temp).^4));

else

Cp = R*(a1+(a2*Temp) + (a3*(Temp).^2) + (a5**Temp).^4));

end

2.Entropy

Entropy, the measure of a system thermal energy per unit temperture that is unavailable for doing useful work.Beacuse work is obtained from ordered molecular motion,the ammount of entropy is also system.The concet of entropy provides deep insight into the direrctio of spontaneous for many every day .

% function of the entropy

finction S = entropy_S(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,Temp,R,global_medium_temp);

%checking for the temperture

if Temp <=global _medium_temp

S = R.*(a8.*log(Temp) + (a9.*Temp) + (a10*((Temp).^2)/2) + (a11*((Temp.3)/3) + (a12((Temp.^4)/4) +a14);

else

S = R.*(a1.*log(Temp) + (a2.*Temp) + (a3*((Temp).^2)/2) + (a4*((Temp).^3)/3) + (a5*((Temp).^4)/4) +a7);

end

3.Enthalpy

Enthalpy a prooperty of thermodynamic system is equal to the system internal energy plus the product of its pressure and volume. In a system enclosed so as prevent the mass transfer fo r process at constant pressure and heat absorbed or released equals the change in enthalpy

%Function of enthalpy

function H = enthalpy_H(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,Temp,R,global_medium_temp);

% checking for the temperture

% temperture coefficients

if Temp <= global_medium_temp

H = R*Temp.*(a8+((a9*Temp)/2) + ((a10*(Temp).^2)/3)+ ((a11*(Temp).^3)/4) + ((a12*(Temp).^4)/5) + ((a13./TEmp)));

else

H = R*Temp.*(a1+((a2*Temp)/2) + ((a3*(Temp).^2)/3)+ ((a4*(Temp).^3)/4) + ((a5*(Temp).^4)/5) + ((a6./TEmp)));

end

3.molecular weight

function Molecularweight = molecular_weight(Species_sp)

% standared - Atomic name

fprintf('molecular Weight of ');

fprint(Species_sp);

fprint(':');

Atomic _Weight = [1.008 12.011 15.99 14.999 14.007 39.948];

MolecularWeight = 0

for i = length(Species_sp)

for j = 1:length(atomic_name)

if strcmpi(Species_sp(i),atomic_name(j))

Molecularweight = Molecularweight + Atomic_Weight(j);

position = j;

end

end

n = str2num(Speeies_sp(i));

if n>1

Molecularweight = Molecularweight + atomic_Weight(position)*(n-1);

end

end

fprintf('molecular weight %s',Specied_sp);

fprintf('%d',Moleccularweight);

disp(' ');

end

Main code

clear all

clc

close all

% make directory

mkdir 'c:desktopskilllyncNAS file parsing

% reading data file NASA thermodynamic

%open a file & 'r' open the file reading

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

first_line = fget(f1);

% Obtaing temperture - by reading header information

global_temp = fgetl(f1);

% spliting

t = strspilt(global_temp);

%converting string cell to numnber using str2num

global_low_temp = str2num(t{2});

global_medium_temp = str2num(t{3});

global_high_temp = str2num(t{4});

% temperture range & gas constant

% temperture range assumed

Temp = linspace(global_low_temp,global_high_temp,1000);

% universal gas constant j/(mol-k)

R = 8.314:

% skipping three comment line in the file

for i = 1:3

gt = fget1(f1);

end

for i =1.53

gt = fget1(gt,' ');

Species_sp = (A{1});

line_1 = fgetlf1);

a = strfind(line_1,'E');

% Extracting higher and lower temperture coefficients

% Extracting first 7 coefficients i.e high temperture cofficients

a1 = line_1(1:a(1)+3);

a1 = str2num(a1);

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

a2 = str2num(a2);

a3 = line_1(a(2)+4:a(3)+3);

a3 = str2num(a3);

a4 = line_1(a(3)+4:a(4)+3);

a4 = str2num(a4);

a5 = line_1(a(4)+4:a(5)+3);

a5 = str2num(a5);

line_2 = fget1(f1)

b = str2find(line_1,'E');

a6= line_2(1:b(1)+4);

a6= str2num(a6);

a7= line_2(a(1)+4:b(2)+3);

a7 = str2num(a7);

% extractibng Second 7 coefficients - low temperture coefficients

a8 = line_2(b(2)+4:b(3)+3);

a8 = str2num(a8);

a9 = line_2(b(3)+4:b(4)+3);

a9 = str2num(a9);

a10 = line_2(b(4)+4:b(5)+3);

a10 = str2num(a10);

line_3 = fget1(f1)

c = str2find(line_1,'E');

a11= line_3(1:c(1)+3);

a11= str2num(a11);

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

a12 = str2num(a12);

a13 = line_3(c(2)+4:c(3)+3);

a13 = str2num(a13);

a14 = line_3(c(1)+4:c(2)+3);

a14 = str2num(a14);

%specific heat calculation

Cp = Specificheat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,Temp,R,global_medium_temp);

% entropy calculation

S = entropy_S(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,Temp,R,global_medium_temp);

% enthalpy calculation

H = enthalpy_H(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,Temp,R,global_medium_temp);

% calculating molecular weight of species

molcularweight(i) = fopen('molecular weight.txt','a+');

% read and 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 floder

curr_dir = pwd

mkdir(Species_sp);

% plot 1 Specific heat cp vs temperture range

figure(1)

plot (Temp,cp,'linewidth',4,'color','b')

xlabel('temperture[k]');

ylabel('Specific heat[kj]');

gird on

saveas(figure(1),'specific heat .jpg')

% plot 2 enthalpy vs tempertyre range

figure(2)

plot (Temp,H,'linewidth',4,'color','b')

xlabel('temperture[k]');

ylabel('Enthalpy[kj/mol]');

gird on

saveas(figure(2),'enthalpy .jpg')

% plot 3 enthalpy vs tempertyre range

figure(3)

plot (Temp,S,'linewidth',2,'color','b')

xlabel('temperture[k]');

ylabel('Entropy[kj/mol-k]');

gird on

saveas(figure(3),'enthalpy .jpg')

cd(curr_dir);

M = Molecular_weight(Species_sp);

f2 = fopen('molecular mass','w');

fprintf('%s n %s n', 'species','molecular mass',M)

fclose(f2)

end

Expalnation iof the code

1. starting with clear all close all and clc .

2.Making a directory using mkdir with location address

3. After that reading the text file THERMO.dat file and opening it by using fopen and r as reading command

4.For reading the line in a text using fgetl.

5.To obtain the temperture range ffrom the Thermo.dat file using strspilt to split the temperture into a particular string cell

6.Using thr str2num for converting string to number.

7.Divided the temperture into string and then converted to a number so that temperture valves are used seperately to slove the NASA thermodynamics

8.Using for& end loops to skip the next comment lines in the text file

9.Reading all the 53 specie to plot specific heat(cp),enthalpy(H),entropy (S),with the temperture valves and to find molecular weights.

10.Used for loop to read 53 sopecies

11.Used str2find to find string

12.Using linspace specified the temperture range feom low to high

13.Adding Universal gas consatantvalve R

14Extracted higher and lower temperture coefficients by reading libe from species.

15.calling specificheat,enthalp,entropy function codes.

16.Calculating molecular weight

Results

plots:

Results for the plots of O2

Plots for co2

Plots for NO2

Attachment:

conculosion

The specific heat,enthalpyand entropy for all species are calculated and plotted aganist the local tempertures range.

The molecular weight is calculated for all the species

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.