Challenge

Project 1 - Parsing NASA thermodynamic data

AIM:- Performing file parsing operation of NASA'S thermodynamic data in MATLAB

OBJECTIVE:-

 1:- Write a function that extract all 14 co_efficient data and calculate enthalpy,entropy and specific heat for all the species in the data file

2:- Calculate the molecular weight of each species and display in the command window

3:- plot the graph for enthalpy, entropy and specific heat with respect to local temprature range

4:- save the plots in speperate folder for each species with approprate name, all this should generated automatically

5:- attach the screenshot of plots of species of O2, N2 and CO2 separately 

INTRODUCTION

FILE PARSING

parsing means to make something understandable, in the programing sence, it means to convert the information represented into one form to another form, this is done by partially analysing the data, understanding its structure by making some assumptions baised on what you are expecting to see and then representing that structure in a code

 for example consider the equation 2+3

the computer dosent know that the meaning of '2, '+' and ,'3'  and  for computer to perform the calculation it must be parse the equation and must understand the calculation to be performe, the parse file identify the above equation 2 and 3 are numbers and '+' is  as addition sign that two numbers should be added together 

DATA FILE

LINK OF THE DATA FILE 

https://drive.google.com/file/d/1AikCHDlz9s_fu8whE81qee_GD4AyYpCP/view

FORMULA

In the above formula

Cp= specific heat

H= enthalpy

S= entropy

R= universal gas constant

T = temprature

SPECIFIC HEAT

the specific heat is define as the amount of heat required to raise the temprature of 1 gm of substance by 1C the unit of specific heat is usually calories or joules per gram per celsius degree

ENTHALPY

It is define as the total amount of heat energy is stored in the system which is equavalant of sum of total energy and resulting energy due to its pressure and volume its unit is joules

ENTROPY

entropy is define as a measure of randomness or disorder of a system 

from the thermodynamic point of view we do not consider the miscroscopic details of a system. itead entropy is used to describe the behaviour of a system in terms of thermodymanic properties, such as temprature, pressure,entropy and heat capacity. this thermodynamic discription took into consideration that state of equilibrium of the systems

MAIN PROGRAM

close all
clear 
clc
f1= fopen('THERMO.dat','r');

%reading the first line
fgetl(f1);

% reading the header data
temp_data=fgetl(f1);
A= strsplit(temp_data,' ');
global_low_temp= str2double(A{2});
global_mid_temp= str2double(A{3});
global_high__temp= str2double(A{4});

% reading the 3 comments
for i=1:3  
comments=fgetl(f1);
end

% extracting all the species using for loop
for i=1:53
a=fgetl(f1);
b=strsplit(a,' ');

%extracting species name
species_name= b{1};

%extracting local temprature
local_low_temp=str2double(b(end-3));
local_high_temp=str2double(b(end-2));
local_mid_temp= str2double (b(end-1));
%creating an array for temprature 
T= linspace(local_low_temp,local_high_temp,1000);
R= 8.314;


% extracting the  coefficients of 1st line
co_eff1= fgetl(f1);

pos1= strfind(co_eff1,'E'); % finding the position of exponential 


a1=str2double(co_eff1(1:(pos1(1)+3)));
a2=str2double(co_eff1(pos1(1)+4:pos1(2)+3));
a3=str2double(co_eff1(pos1(2)+4:pos1(3)+3));
a4=str2double(co_eff1(pos1(3)+4:pos1(4)+3));
a5=str2double(co_eff1(pos1(4)+4:pos1(5)+3));

% extracting the coefficient of 2nd line

co_eff2= fgetl(f1);
pos2=strfind(co_eff2,'E');

a6=str2double(co_eff2(1:(pos2(1)+3)));
a7=str2double(co_eff2(pos2(1)+4:pos2(2)+3));
a8=str2double(co_eff2(pos2(2)+4:pos2(3)+3));
a9=str2double(co_eff2(pos2(3)+4:pos2(4)+3));
a10=str2double(co_eff2(pos2(4)+4:pos2(5)+3));

%extracting the coefficient from 3rd line
 co_eff3= fgetl(f1);
 pos3=strfind(co_eff3,'E');

 a11=str2double(co_eff3(1:(pos3(1)+3)));
a12=str2double(co_eff3(pos3(1)+4:pos3(2)+3));
a13=str2double(co_eff3(pos3(2)+4:pos3(3)+3));
a14=str2double(co_eff3(pos3(3)+4:pos3(4)+3));

for j= 1: length(T)
     t= T(j);
           if t

STEP WISE EXPLANATION

initially close, clear and clc command is ues to erase all the data of workspece command window and figures, so that your program looks clean and close all the unnessery windows so that program runs smoothly

after that we have to open the file in  that we have downloaded from the source, and then use 'r' that means we are reading  so there we use fopen command followed by the file name and stored in the variable f1

we have to read the data from the file, there is special command fgetl(f1), this syntax says that read the line of file which we stored in f1 vairable, fgetl reads only single line in file i case of readig multiple lines we have to use tis command multiple times so that we can read the file line by line,we use this comand multiple times in the program 

READING FIRST FIVE LINES OF THE FILE

 

first line is the name of the file which is not importent for us so we just use fgetl command to read it in the next line is these three values are noting but the global temprature values these temprature values are string andatually not the numbers stored in cell array so we have to convert it into number with the help of str2double command that convers string into number next three lines initiated by ! sign are just comments so we read it as it is 

READING NEXT LINES

 in the next line the first letter of the first line is nothing but the name of species O stand for oxygen and the last 3 numbers are nothing but local temprature ranges so, we stored the first latter of the line as species name and indexing last three values as local tempratures by converting it into numbers with the help of str2double command

next three lines holds the data of temprature coefficients the first 7 values are high tempreture coefficients and next 7 are low temprature coefficients, here is the logic that we have E in every lines first we find the position each E  in the first line by using findstr  this command gives us the position of each E in the next step using indexing operation we extract the data and convert it into number 

a1=str2double(co_eff1(1:(pos1(1)+3)));

the above line states that indexing from one upto the position of E and after that there are 3 more charecters so add +3 that extract the first temprature coefficient after that convert the string into number by using str2double command followed the same logic for next values the same process in repated for next two lines so that we extrect all the 14 co_efficients 

same method is is used for remaning species  

after extracting all the species we have to use these coefficient for calculating the values of specific heat, enthapy and entropy, by using given formulas, remember here we have to use local temprature values not the global temprature values 

 

 the simple logic of for loop is used here, we know that the first 7 coefficients are low temprature coefficient, if else condtion is used here if given temprature is low then calculate with the help of first 7 coefficients else use last 7 coefficients  

we have to save the each species in different directory, so that for creating a new folder we use mkdir  command to create a folder for each species after that we have to change the program directory because species folder is in different directory so we have to bring the program in same directory with the hepl of cd command followed by 

ploting the graph between cp vs t,h vs t and s vs t and save it by using saveas command

FUNCTION OF MOLECULAR WEIGHT

function [mol_wt]= molecular_weight(species_name)

element= ['O','H','C','N','A'];
atomic_wt= [16,1,12,15,40];
mol_wt=0;
for i = 1: length(species_name)
   for j= 1:length(element)
    if strcmp(species_name(i),element(j))
        mol_wt=mol_wt+atomic_wt(j);
        index=j;

    end
end
        n =str2double(species_name(i));
        if n>1
            mol_wt=mol_wt+atomic_wt(index)*(n-1);
        end
        
    
end

 program function for calculating molecular weight is slightly different first we define our input vairable species name, in the next step we create an vector of elements and atomic weight of that element 

after that we use nasted for loop to calculate molecular weight, in outer for loop we run it as species name,inside for loop runs upto the element vector, then we have to compair the species with the help of strcmp command name array with the element vector if it matches the molecular weight of the species is stored in vairable mol_wt,

if the species name contains more than one element of same name such as CO2, we have to  add O two times so first we convert species name into string by using str2double and stored it in vairable called n 

if (n>1)  that means if there is more than one element then this  condition used to multiply the privious position (n-1) so that it adds previous postion one more time 

PLOTS OF REQUIRED SPECIES

OUTPUT OF MOLECULAR WEIGHT

OUTPOT OF WORKSPACE

ERROR

calling function error

calling output vairable with differnt name i.e M, the output vairable of the function is mol_wt and we assign it as M in first line of function 

by changing vairable from M to mol_wt the above error get solved

CONCLUSION 

the program runs sucessfully and our desired output is achived 

REFERENCES

https://en.wikipedia.org/wiki/Parsing

https://www.quora.com/What-does-it-means-to-parse-a-file

https://www.youtube.com/watch?v=t0oNbYJn2Mw&t=500s

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.