Challenge

Project 1 - Parsing NASA thermodynamic data

*Report of Parsing NASA thermodynamic data

*challenge_skill lync-ganesh katkar

AIM : To write matlab code to parsing NASA thermodynamic data.

OBJECTIVE :  

  1. To write a program to extracts the 14 co-efficients and calculates the enthalpy,entropy and specific heats for all the species in the data file.
  2. Calculate the molecular weight of each species.
  3. Plot the Cp, Enthalpy and Entropy for the local temperature range (low temperature: high temperature) specific for each species.

File parsing :

Parsing a file means reading in a data stream and building a memory model of the content of that data. This aims at facilitating perfoming some kind of transformation on the data. Parsing splits a file or other input into pieces of data that can be easily stored or manipulated.

Enthalpy (H) :

When a process takes place at constant pressure, the heat absorbed or released is equal to the Enthalpy change. Enthalpy is sometimes known as “heat content”, but “enthalpy” is an interesting and unusual word, so most people like to use it. Etymologically, the word “entropy” is derived from the Greek, meaning “turning” and “enthalpy” is derived from the Greek meaning “warming”. As for pronunciation, Entropy is usually stressed on its first syllable, while enthalpy is usually stressed on the second.

H = U + pV

Where,

 H = Enthalpy of the system

U = Internal energy of the system

p = Pressure of the system

V = Volume of the system

Entropy (S) :

The entropy of an object is a measure of the amount of energy which is unavailable to do work. Entropy is also a measure of the number of possible arrangements the atoms in a system can have. In this sense, entropy is a measure of uncertainty or randomness.

S = (qrev)/t

S – Entropy

S – change in Entropy

qrev – refers to the reveres of heat

t – refers to the temperature in kelvin

Gas constant:

The constant of proportionality in the gas equation. It is equal to 8.314 joule kelvin−1 mole−1.

Formula for calculating Specific heat, Entropy and Enthalpy:

The above equations are used in the NASA thermodynamic data to plot the graph in the main functions.

Procedure

  1. The term file parsing is nothing but extracting the data form a given file, that means to read a particular given file.
  2. This parsing is done to get all the values from the data file into the program so with these data we can proceed with our calculations.
  3. In this program we are parsing the NASA’s thermodynamic data to calculate thermodynamics properties of various gas species
  4. The data file consists of 53 gas species with their local temperature ranges and 14 temperature coefficients for each species in which the first seven are high temperature coefficients and the second seven are high temeprature coefficients.
  5. Our aim is to write a function that extracts the 14 co-efficients and calculates the enthalpy, entropy and specific heats for all the species in the data file.

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;

wheres ,

R=universal gas constant

T=temperature

Cp=specific heat(k)

S=entropy(kj/mol-k)

H=enthalpy(kj/mol)

a=coefficient where

,i 1 to 14

Started the matlab program

 First of all type the variable to save and run the program.

clear all

close all

clc

% input

R = 8.314; %gas constant

%open file and reading THERMO.dat file

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

get = fgetl(f1);

%now reading temperature from this file

temp = fgetl(f1);

%slpiting

 x = strsplit(temp);

%converting string into numbers

 templow = str2num(x{2});

tempmid = str2num(x{3});

temphigh = str2num(x{4});

%temperature range

T = linspace(templow,temphigh,1000);

%skipping comment lines

for i = 1:3

   get = fgetl(f1);

end  

% reading the species

for i = 1:53

    tline=fgetl(f1);

 A=strsplit(tline,' ');   %splitting into cell

 species = (A{1});

 %converting string into number

   lowtemp = str2num(A{end-3});

   midtemp = str2num(A{end-2});

   hightemp = str2num(A{end-1});

 t1= lowtemp;

 t2= midtemp;

 t3= hightemp;

 tline1 = fgetl(f1);

 % to find the position of E from line 1

 a = strfind(tline1,'E');

%to extract the 14 coefitients

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

   a1 = str2double(a1);

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

   a2=str2double(a2);

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

   a3=str2double(a3);

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

   a4=str2double(a4);

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

   a5=str2double(a5);

   tline2 = fgetl(f1);  %getting line 2

   b=strfind(tline2,'E');

   a6=tline2(1:b(1)+3);

   a6=str2double(a6);

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

   a7=str2double(a7);

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

   a8=str2double(a8);

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

   a9=str2double(a9);

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

   a10=str2double(a10);

   tline3=fgetl(f1);

   c=strfind(tline3,'E');

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

   a11=str2double(a11);

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

   a12=str2double(a12);

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

   a13=str2double(a13);

   a14=tline3(c(3)+4:c(4)+3);

   a14=str2double(a14);

   mkdir(['C:\Users\DELL\Documents\MATLAB\species\',species])

    for k=1:length(t3)

    if T(k)>t2

    %high temperature coefficients.

  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;

  else

  %low temperature coefficients.

   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;

   end   

   end

%plotting graphs

 figure(1);

 plot(T,cp);

 grid on ;

 title(species);

 xlabel('temperature');

 ylabel('specific heat');

  figure(2);

 plot(T,H);

 grid on ;

 title(species);

 xlabel('temperature');

 ylabel('Enthalpy');

  figure(3);

 plot(T,s);

 grid on ;

 title(species);

 xlabel('temperature');

 ylabel('Entropy');

 %changing the directory and saving the file

 cd(['C:\Users\DELL\Documents\MATLAB\species\',species])

 saveas(1,'secific heat','jpg');

 saveas(2,'enthalpy','jpg');

 saveas(3,'entropy','jpg');

 %molecular  weight calculation

 elements=['H','C','O','N','A'];

 atomic_weight=[1.0079 12.0107 15.999 14.00673 39.948];

 mol_mass=0

 for i=1:length(species)

 for m=1:length(atomic_weight)

 if strcmp(species(1),elements(m))

 mol_mass=mol_mass+atomic_weight(m);

 position=m

 end

 end

 n=str2double(species(1));

 if n>1

 mol_mass=mol_mass+atomic_weight(position)*(n-1);

 end

  end

sprintf('molecular weight of %s:%f u',species,mol_mass)

end

fclose(f1)

Errors:

1 File: file_parsing.m Line: 39 Column: 1

At least one END is missing. The statement beginning here does not have a matching end.

Step to overcome this error:

There is a error above is for one end missing foe loop

After adding final end the results are showing properly

  1. Dot indexing is not supported for variables of this type.

Error in file_parsing (line 128)   cp=(a8+a9.T+a10.*T.^2+a11.*T.^3+a12.*T.^4)*R;

Step to overcome this error:

The error is missing the operature *

After adding this operater the results are proper showing.

The molecular weight of all species:

'molecular weight of O:15.999000 u'

'molecular weight of O2:31.998000 u'

'molecular weight of H:1.007900 u'

'molecular weight of H2:2.015800 u'

'molecular weight of OH:31.998000 u'

'molecular weight of H2O:3.023700 u'

'molecular weight of HO2:3.023700 u'

'molecular weight of H2O2:4.031600 u'

'molecular weight of C:12.010700 u'

'molecular weight of CH:24.021400 u'

'molecular weight of CH2:36.032100 u'

'molecular weight of CH2(S):72.064200 u'

'molecular weight of CH3:36.032100 u'

'molecular weight of CH4:36.032100 u'

'molecular weight of CO:24.021400 u'

'molecular weight of CO2:36.032100 u'

'molecular weight of HCO:3.023700 u'

'molecular weight of CH2O:48.042800 u'

'molecular weight of CH2OH:60.053500 u'

'molecular weight of CH3O:48.042800 u'

'molecular weight of CH3OH:60.053500 u'

'molecular weight of C2H:36.032100 u'

'molecular weight of C2H2:48.042800 u'

'molecular weight of C2H3:48.042800 u'

'molecular weight of C2H4:48.042800 u'

'molecular weight of C2H5:48.042800 u'

'molecular weight of C2H6:48.042800 u'

'molecular weight of CH2CO:60.053500 u'

'molecular weight of HCCO:4.031600 u'

'molecular weight of HCCOH:5.039500 u'

'molecular weight of H2CN:4.031600 u'

'molecular weight of HCN:3.023700 u'

'molecular weight of HNO:3.023700 u'

'molecular weight of N:14.006730 u'

'molecular weight of NNH:42.020190 u'

'molecular weight of N2O:42.020190 u'

'molecular weight of NH:28.013460 u'

'molecular weight of NH2:42.020190 u'

'molecular weight of NH3:42.020190 u'

'molecular weight of NO:28.013460 u'

'molecular weight of NO2:42.020190 u'

'molecular weight of HCNO:4.031600 u'

'molecular weight of HOCN:4.031600 u'

'molecular weight of HNCO:4.031600 u'

'molecular weight of NCO:42.020190 u'

'molecular weight of CN:24.021400 u'

'molecular weight of HCNN:4.031600 u'

'molecular weight of N2:28.013460 u'

'molecular weight of AR:79.896000 u'

'molecular weight of C3H8:48.042800 u'

'molecular weight of C3H7:48.042800 u'

'molecular weight of CH2CHO:72.064200 u'

Plots of some species:

 Plot of Species O2(specific heat vs temperature)

Plot of Species O2( entropy vs temperature)

Plot of Species O2(enthalpy vs temperature)

Plot of Species N2(specific heat vs temperature)

Plot of Species N2(entropy vs temperature)

Plot of Species N2(enthalpy vs temperature)

Plot of Species CO2 (specific heat vs temperature)

Plot of Species CO2 (entropy vs temperature)

Plot of Species CO2 (enthalpy vs temperature)

Graph file of all species:

Conclusion:

Finally specific heat,enthalpy,entropy and molecular weight has been calculated for all given for all given species. Also plots Cp,H,S for temperature has been plotted for required specifcs and has been attached on this projects.

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.