Project

Parsing NASA's thermodynamic data

AIM :

To write a program in MATLAB for parsing NASA thermodynamics data.

GOVERNING EQUATIONS USED:

OBJECTIVES:

  • To extract the 14 coefficients and calculate the Enthalpy, Entropy and Specific Heats for all the species in the data file.
  • To calculate the molecular weight of each species and display it in the command window.
  • To plot the Cp, Enthalpy and Entropy for the local temperature range,specific for each species.
  • To save the plots as images with appropriate names and dump them in separate folders for each species with suitable name.

THEORY:

File parsing:

The definition for prase is to split the file or other input into pieces or data which can be easily stored or manipulated. Here we will be splitting string into parts then recognize the parts to convert it into something simpler than string.

Here we extract the data from the given thermodynamic data file and will calculate the enthalpy, entropy and specific heat for all the species in data file. Also we calculate the molecular weight of each species.

The plots for enthalphy, enthropy and specific heat for each species will be plotted and will be stored in seperate file.

DEFINITIONS:

Specific heat: Specific heat is the thermodynamic property, which states the amount of heat required for a single unit of mass of a substance to be raised by one degree of temperature.

Enthalpy: Enthalpy is a thermodynamic property of a system. It is the sum of the internal energy added to the product of the pressure and volume of the system.

Entropy: Entropy is a thermodynamic property of a system. It is a measure of a system's thermal energy per unit temperature that is unavailable for doing useful work.

Molecular weight: The average weight of a molecule of an element or compound measured in units once based on the weight of one hydrogen atom taken as the standard or on 1/16 (0.0625) the weight of an oxygen atom, but after 1961 based on 1/12 (0.083) the weight of the carbon-12 atom; the sum of the atomic weights of all the atoms in a molecule.

PROCEDURE:

  1. First we open the given thermodynamic data and read the data in a file and store the data in the variable file.
  2. Then we read the header file of the thermodynamic data and calculate the global low, mid and high temperature.
  3. Header lines are skipped which were of no use.
  4. Using fgetl( ), strsplit( ), strfind and str2double( ) the value of local low, mid and high temperature were stored in the variable.
  5. Then the 14 coefficient of each element were stored in their respective variable by using for loop, fgetl( ), strsplit( ), strfind functions.
  6. First the for loop is executed for calculating 14 coefficients of each element.
  7. Fgetl( ) function is used to read coefficients in 1st line, then strfind( ) was used to find the exponent ‘E’ by using this we can store the coefficient in the respective variable.
  8. Once the coefficient was found out it was converted into decimal number using str2double() function.
  9. By doing the above steps we can store the coefficients into respective variables.
  10. Once the coefficients were found out, then we can calculate the specific heat, entropy and enthalpy by taking gas constant R=8.314 J/mol-k and temperature a linspace( ) function of lower temp to high temp.
  11. Once the value of specific heat, entropy and enthalpy is found out now we can plot graphs between specific heat vs temperature, enthalpy vs temperature and entropy vs temperature for each element.
  12. The three plots were stored in a folder having the name of the element.
  13. Finally molecular mass of each element was calculated and displayed in command window.

MAIN PROGRAM CODE:

%Parsing NASA's thermodynamic data
clear all
close all
clc

%finding and opening the file_in_loadpath
file=fopen('THERMO.dat','r');

%header
line1=fgetl(file);

%global temperature values
line2=fgetl(file);
A=strsplit(line2,' ');
global_min_temp=str2num(A{2});
global_mid_temp=str2num(A{3});
global_max_temp=str2num(A{4});

%skipping comments
fgetl(file);
fgetl(file);
fgetl(file);

%using the for loop to consider 53 elements
for i=1:53
  line3=fgetl(file);                %reading the file
  element=line3(1:6);               %naming first variable as element
  P=strfind(line3,'G');
  local_low_temp=line3(P+3:55);
  local_high_temp=line3(P+13:65);
  local_mid_temp=line3(P+23:75);
  lt=str2double(local_low_temp);    %creating low temp. variable
  ht=str2double(local_high_temp);   %creating high temp. variable
  mt=str2double(local_mid_temp);    %creating mid temp. variable
  
  %line 1 reading coefficients
  cfline1=fgetl(file);
  X=strfind(cfline1,'E');
  a1=cfline1(1:X(1)+3);
  a1=str2double(a1);                %storing 1st coefficients
  a2=cfline1(X(1)+4:X(2)+3);
  a2=str2double(a2);                %storing 2nd coefficients
  a3=cfline1(X(2)+4:X(3)+3);
  a3=str2double(a3);                %storing 3rd coefficients
  a4=cfline1(X(3)+4:X(4)+3);
  a4=str2double(a4);                %storing 4th coefficients
  a5=cfline1(X(4)+4:X(5)+3);
  a5=str2double(a5);  %storing 5th coefficients
  
  %line 2 reading coefficients
  cfline2=fgetl(file);
  Y=strfind(cfline2,'E');
  a6=cfline2(1:Y(1)+3);
  a6=str2double(a6);                %storing 6th coefficients
  a7=cfline2(Y(1)+4:Y(2)+3);
  a7=str2double(a7);                %storing 7th coefficients
  a8=cfline2(Y(2)+4:Y(3)+3);
  a8=str2double(a8);                %storing 8th coefficients
  a9=cfline2(Y(3)+4:Y(4)+3);
  a9=str2double(a9);                %storing 9th coefficients
  a10=cfline2(Y(4)+4:Y(5)+3);
  a10=str2double(a10);              %storing 10th coefficients
  
  %line 3 reading coefficients
  cfline3=fgetl(file);
  Z=strfind(cfline3,'E');
  a11=cfline3(1:Z(1)+3);
  a11=str2double(a11);              %storing 11th coefficients
  a12=cfline3(Z(1)+4:Z(2)+3);
  a12=str2double(a12);              %storing 12th coefficients
  a13=cfline3(Z(2)+4:Z(3)+3);
  a13=str2double(a13);              %storing 13th coefficients
  a14=cfline3(Z(3)+4:Z(4)+3);
  a14=str2double(a14);              %storing 14th coefficients
  
  %Creating the folder for each element
  mkdir('C:\Users\USER\Desktop\SKILL LYNC\NASA file parsing',element);
  
  %Universal gas constant
  R=8.314;
  
  %Ranging the temperature from low temperature to high temperature
  T=linspace(lt,ht,100);
  
  %Specific heat
  for j=1:length(T)
  if T(j)

FUNCTION TO CALCULATE THE MOLECULAR MASS OF ELEMENT:

%function for calculating molecular mass
function MM=molecular_mass(element)
  element_name=upper(element)
  atoms={'H','C','N','O','AR'};
  atomic_weight=[1 12 14 16 40];
  MM=0;
  for i=1:length(element)
    for j=1:length(atomic_weight)
      if strcmp(element_name(i),atoms(j))==1
        MM=MM+atomic_weight(j);
        u=j;
    end
  end
  %adding the weight of repeatating atom
  n=str2double(element_name(i));
  if n>1
    MM=MM+atomic_weight(u)*(n-1);
  end
  end
end

OUTPUT:

Command window:

Location of element folders:

Plots for O2:

Plots for N2:

Plots for CO2:

Remaining plots are uploaded in google drive:

https://drive.google.com/drive/folders/1C9WEs2H3daftzRvSebZmDidIvQDTCTU6?usp=sharing

ERRORS:

Made mistake while specifying directory.

CONCLUSION:

Through file parsing, we can read a file and make use of important data from it.

REFERENCE:

https://in.mathworks.com/matlabcentral/answers/86131-using-if-else-statements-to-find-molecular-weight-of-compounds-given-the-info-from-a-string

https://in.mathworks.com/matlabcentral/answers/106431-calculating-total-number-of-lines-in-a-file-opened-in-matlab

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.