Challenge

Project 1 - Parsing NASA thermodynamic data

AIM:-

1.) write a code in matlab to perform the parsing of NASA thermodynamic data file.

2.) Calculate the molecular weight of each species and display it in the command window.

3.) Plot the Cp, Enthalpy and Entropy for the local temperature range (low temperature : high temperature) specific for each species.

4.) 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 theermodynamic property Equations are given below:-

The FIRST 7 coefficients are HIGH-temperature coefficients and the SECOND 7 coefficients are LOW-temperature coefficients.

here 'R' is the universal gas constant.

'T' is temperature.

'S' is entropy.

'H' is enthalpy.

'Cp' is specific heat.

Specific Heat(Cp) :- Specific Heat is the amount of heat required to raise the temperature of a 1kg substance by 1 degree celcius.

Enthalpy(H):- Enthalpy is the total amount of Heat a system is having at a state. it is equal to the system's internal energy plus produc of pressure and volume.i.e.

Entropy(S) :- Entropy is a Thermodynamic quantity which represents the unavailablity of energy to do the mechanical work.

ALGORITHM:-

1.) program starts with the commands 'clear all','close all' and 'clc' to clear command window and workspace.

2.) we are then used the 'fopen' command to open the NASA file and then 'fgetl' to get info about the program file.

3.) the global minnimum,mid and maximum temperature values are obtained using 'str2double' comand easily and give them names.

4.)then we generate the code to extract the useful data from the file using 'fgetl' command and skipping some lines we have no use.we have successfully extracted 14 coefficints and specicies name.

5.)we generated then the 'for' loop and calculations for entropy , specific heat and enthalpy are done using the prescribed functions.

6.) now command for the 3 plots are given which are ' Entropy vs Temperature','Enthalpy vs Temperature' and 'Specific Heat vs Temperrature' and saved in seperate folder for all the 53 species.

7.) directory is been set and function for molecular weight is written to get hte values.

8.) closing the code with 'fclose(f1)'.

##MAIN CODE##

clear all
close all
clc
%input.
R = 8.314;

f1 = fopen('THERMO.dat','r')
line1 = fgetl(f1);
line2 = fgetl(f1);
A = strsplit(line2,' ');
%Global temperatures.
global_min_temp = str2double(A{2});
global_mid_temp = str2double(A{3});
global_max_temp = str2double(A{4});
%skipping the file comments.
line3 = fgetl(f1);
line4 = fgetl(f1);
line5 = fgetl(f1);

for j = 1:53
    species = fgetl(f1);
    species_name = species(1:6);


A1 = fgetl(f1);
B1 = strfind(A1,'E');
a1 = str2double(A1(1:(B1(1)+3)));
a2 = str2double(A1((B1(1)+4):(B1(2)+3)));
a3 = str2double(A1((B1(2)+4):(B1(3)+3)));
a4 = str2double(A1((B1(3)+4):(B1(4)+3)));
a5 = str2double(A1((B1(4)+4):(B1(5)+3)));

A2 = fgetl(f1);
B2 = strfind(A2,'E');
a6 = str2double(A2(1:(B2(1)+3)));
a7 = str2double(A2((B1(1)+4):(B2(2)+3)));
a8 = str2double(A2((B2(2)+4):(B2(3)+3)));
a9 = str2double(A2((B2(3)+4):(B2(4)+3)));
a10 = str2double(A2((B2(4)+4):(B2(5)+3)));

A3 = fgetl(f1);
B3 = strfind(A3,'E');
a11 = str2double(A3(1:(B3(1)+3)));
a12 = str2double(A3((B3(1)+4):(B3(2)+3)));
a13 = str2double(A3((B3(2)+4):(B3(3)+3)));
a14 = str2double(A3((B3(3)+4):(B3(4)+3)));

% folder of each species.
mkdir('F:/matlab practice skilllync/new folder/species',species_name)
Temp = [300 1000 5000];
temp = linspace(300,5000,100);
%Calculations.
for j = 1:length(temp)
    if temp(j)<3000
        Cp = (a1+a2.*temp+a3.*temp.^2+a4.*temp.^3+a5.*temp.^4).*R;
        H =(a1+(a2.*temp)./2+(a3.*temp.^2)./3+(a4.*temp.^3)./4+(a5.*temp.^4)./5+a6./temp).*temp.*R;
        S = (a1.*log(temp)+a2.*temp+(a3.*temp.^2)./2+(a4.*temp.^3)./3+(a5.*temp.^4)./4+a7).*R;
    else
        Cp = (a8+a9.*temp+a10.*temp.^2+a11.*temp.^3+a12.*temp.^4).*R;
        H =(a8+(a9.*temp)./2+(a10.*temp.^2)./3+(a11.*temp.^3)./4+(a12.*temp.^4)./5+a13./temp).*temp.*R;
        S = (a8.*log(temp)+a9.*temp+(a10.*temp.^2)./2+(a11.*temp.^3)./3+(a12.*temp.^4)./4+a14).*R;
    end
end
%plotting the graphs
%specific heat vs temperature
figure(1)
plot(temp,Cp,'linewidth',3,'color','r')
xlabel('Temperature[K]')
ylabel('Specific Heat[J/(kg.k)]')
title('Specific Heat vs Temperature')
%enthalpy vs temperature
figure(2)
plot(temp,H,'linewidth',3,'color','b')
xlabel('Temperature[K]')
ylabel('Enthalpy[joules]')
title('Enthalpy vs Temperature')
%entropy vs temperature
figure(3)
plot(temp,S,'linewidth',3,'color','g')
xlabel('Temperature[K]')
ylabel('Entropy[J/k]')
title('Entropy vs Temperature')

directory=(['F:/matlab practice skilllync/new folder/species/',species_name]);
cd(directory)

%saving plots
saveas(1,'Specific heat.jpg')
saveas(2,'Enthalpy.jpg')
saveas(3,'Entropy.jpg')
cd('F:/matlab practice skilllync')
 molar_wt = mol_wt(species_name);
end 
fclose(f1)










##Molecular weight function code##

function molar_wt = mol_wt(species_name)
species = upper(species_name);
element = {'H','O','N','Ar','C','S'};
atm_mass = [1.008,15.999,14.007,39.948,12.011,32.065];
molar_wt = 0;
for i = 1:length(species)
    for j = 1:length(element)
        if strcmp(species(i),element(j))
            molar_wt = molar_wt + atm_mass(j);
            a = j;
        end
    end
    b = str2double(species(i));
    if b>1 
        molar_wt = molar_wt + atm_mass(a)*(b-1);
    end
end
end

##Cp,H,S function code##

function [Cp,S,H] = Cp_H_S_function_(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,temp,R,global_mid_temp)
    if temp<=global_mid_temp
        Cp = (a8+(a9.*(temp))+(a10.*(temp.^2))+(a11.*(temp.^3))+(a12.*(temp.^4))).*R
        H = (a1+((a2.*temp)./2)+((a3.*temp.^2)./3)+((a4.*temp.^3)./4)+((a5.*temp.^4)./5)+(a6./temp)).*R.*temp
        S = (a1.*log(temp)+a2.*temp+((a3.*temp.^2)./2)+((a4.*temp.^3)./3)+((a5.temp.^4)./4)+a7).*R
    else
        Cp = (a8+(a9.*(temp))+(a10.*(temp.^2))+(a11.*(temp.^3))+(a12.*(temp.^4))).*R
        H = (a8+((a9.*temp)./2)+((a10.*temp.^2)./3)+((a11.*temp.^3)./4)+((a12.*temp.^4)./5)+(a13./temp)).*R.*temp
        S = ((a8.*log(temp))+(a9.*temp)+((a10.*temp.^2)./2)+((a11.*temp.^3)./3)+((a12.temp.^4)./4)+(a14)).*R
    end 
end

        

OUTPUT:-

output are shown below.

PLOTS:-

ERROR FACED DURING CODING:-

the error which is shown below is faced during callinf the function for molecular weight.to resolve this i have changed the variable name from 'mol_wt' to 'molar_wt'.

to reslove the error showing below first i have changed the file location secondely the '/' sign is not attached with species word,which is to be fixed.

#link of the drive folder where all the graphs of 53 components are saved :-

https://drive.google.com/drive/folders/1MRVjbyJNEVvnRPo-h1dVU3VuyaPoW6Je?usp=sharing

#Refrences:-

1.) https://in.mathworks.com/help/matlab/ref/mkdir.html#:~:text=status%20%3D%20mkdir(___)%20creates,combinations%20in%20the%20previous%20syntaxes.

2.) https://in.mathworks.com/help/matlab/ref/strcmp.html

3.) https://en.wikipedia.org/wiki/Enthalpy

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.