Project

Project 1 - Parsing NASA thermodynamic data

Main program

clear all
close all
clc

% Universal gas constant (J/K.mol)
R = 8.314 ;          

% Reading header from given file
f1 = fopen(\'THERMO.dat\',\'r\');
Header = fgetl(f1);

% Reading global temperatures
A = fscanf(f1,\'%f \\n\',[1 3]);
global_low_temp = A(1);
global_mid_temp = A(2);
global_high_temp = A(3);

% skipping first 3 lines of the file
line1= fgetl(f1);
line2= fgetl(f1);
line3= fgetl(f1);

for i= 1:53
name_line = fgetl(f1);
% Reading a line and extracting the name of species
species = name_line(1:6);     
% Reading coefficients using \'for\' loop for the given species
tline1 = fgetl(f1);
% Extracting coefficients using \'E\' as a seperator
y1 = strfind(tline1,\'E\');  
a1 = tline1(1:y1(1)+3);
a1 = str2double(a1);
a2 = tline1((y1(1)+4: (y1(2)+3)));
a2 = str2double(a2);
a3 = tline1(y1(2)+4: (y1(3)+3));
a3= str2double(a3);
a4= tline1 (y1(3)+4: (y1(4)+3));
a4= str2double(a4);
a5= tline1(y1(4)+4: (y1(5)+3));
a5= str2double(a5);
tline2= fgetl(f1);
y2 = strfind(tline2,\'E\');
a6 = tline2(1:(y2(1)+3));
a6 = str2double(a6);
a7 = tline2((y2(1)+4): (y2(2)+3));
a7= str2double(a7);
a8= tline2((y2(2)+4):(y2(3)+3));
a8=str2double(a8);
a9= tline2((y2(3)+4):(y2(4)+3));
a9=str2double(a9);
a10= tline2((y2(4)+4): y2(5)+3);
a10= str2double(a10);
tline3 = fgetl(f1);
y3 = strfind(tline3,\'E\');
a11 = tline3(1: (y3(1)+3));
a11 = str2double(a11);
a12 = tline3((y3(1)+4):(y3(2)+3));
a12=str2double(a12);
a13=tline3((y3(2)+4):(y3(3)+3));
a13=str2double(a13);
a14=tline3((y3(3)+4):(y3(4)+3));
a14=str2double(a14);

% Creating folders with species name
subfolder_name = species;
mkdir([\'D:/vignesh/1/MATlab/Project1_parsing data/Test1/species files\',subfolder_name]);

T = linspace(1,5000,50);
%Function for calculating specific heat
Cp=specific_heat(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,global_low_temp,global_mid_temp,global_high_temp);

%Function for calculating Enthalpy
H=enthalpy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,global_low_temp,global_mid_temp,global_high_temp);

%Function for calculating Entropy
S=entropy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,global_low_temp,global_mid_temp,global_high_temp);

% Plotting the graphs

%figure(1)
%plotting for T vs specific heat
plot(T,Cp,\'linewidth\',3,\'color\',\'b\')
title(subfolder_name)
xlabel(\'Temp\')
ylabel(\'Specific Heat\')

%figure(2)
%plotting for T vs enthalpy
plot(T,H,\'linewidth\',3,\'color\',\'r\')
title(species)
xlabel(\'Temp\')
ylabel(\'Enthalpy\')

%figure(3)
%plotting for T vs entropy
plot(T,S,\'linewidth\',3,\'color\',\'g\')
title(species)
xlabel(\'Temp\')
ylabel(\'Entropy\')


% Changing the directory
cd(\'D:/vignesh/1/MATlab/Project1_parsing data/Test1\')

% Function for molecular_mass
mm=molecular_mass(species);

% Changing directory to save the graphs in respective species folder
filepath = ([\'D:/vignesh/1/MATlab/Project1_parsing data/Test1/species files\',subfolder_name]);
cd (filepath)
saveas (1,\'T vs specific heat.jpg\')
saveas (2,\'T vs enthalpy.jpg\')
saveas (3,\'T vs entropy.jpg\')

% Saving the molecular mass in .txt file
f2 = fopen(\'Molecular mass.txt\',\'w\');
fprintf(f2, \'%s \\n %s %f \\n\',species,\'Molecular mass\',mm);

fclose(f2);

end

fclose(f1);

Function code for calculating specific heat

%function for calculating specific heat

function Cp=specific_heat(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,global_low_temp,global_mid_temp,global_high_temp)
if T<=1000
    Cp=(a1+a2.*(T)+a3.*(T.^2)+a4.*(T.^3)+a5.*(T.^4))*R;
else
    Cp=(a8+a9.*(T)+a10.*(T.^2)+a11.*(T.^3)+a12.*(T.^4))*R;
end

Function code for calculating enthalpy.

%funcTion for enthalpy

function H=enthalpy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,global_low_temp,global_mid_temp,global_high_temp)
if T<=1000
    H=(a1.*T+a2.*(T.^2)./2+a3.*(T.^3)./3+a4.*(T.^4)./4+a5.*(T.^5)./5+a6)*R;
else
    H=(a8.*T+a9.*(T.^2)./2+a10.*(T.^3)./3+a11.*(T.^4)./4+a12.*(T.^5)./5+a13)*R;
end

 

Function code for calculating entropy

%funcTion for Entropy

function S=entropy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,global_low_temp,global_mid_temp,global_high_temp)
if T<=1000
    S=(a1.*log(T)+a2.*T+a3.*(T.^2)./2+a4.*(T.^3)./3+a5.*(T.^4)./4+a7)*R;
else
    S=(a8.*log(T)+a9.*T+a10.*(T.^2)./2+a11.*(T.^3)./3+a12.*(T.^4)./4+a14)*R;
end

Function code for calculating Molecular mass

function[mm]=molecular_mass(species)

% A program for calculating molecular mass of each species
atoms = {\'H\',\'C\',\'N\',\'O\',\'AR\'};          
% atomic weights
aw = [1,12,14,16,40]; 
% initial value for molecular mass
mm=0;                          

for i=1:4
for j= 1:4
if (strcmp(species(i),atoms(j))==1);

mm= mm+aw(j);
end
end
end

% Adding the weights of the repeating atoms
for g = 1:length(species)
n=str2double(species(g));
if n>1
p=(g-1);
mm=mm+aw(p)*(n-1);
end
end
% Atomic weight of argon
for l=1:length(species)
if strcmp(species(l),\'R\')
mm=mm+38.8;
end
end

Attachments

Screenshot of the window where all the folders are saved

Plot for o2

plot for N2

plot for Co2

Link for the report for the project is given below

https://drive.google.com/open?id=1eZ7_dDpo9m_GH8PNCCcD9Asz1UMfnWZw

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.