Challenge

Project 1 - Parsing NASA thermodynamic data

clear all
close all
clc
% input
R = 8.314; % Gas constant
% Reading file data
f1 = fopen('THERMO.dat','r')
get = fgetl(f1);
% Reading temprature from this file
temp = fgetl(f1);
% spliting
s = strsplit(temp);
% converting string cells in to numbers
global_low_temp = str2num(s{2});
global_mid_temp = str2num(s{3});
global_high_temp = str2num(s{4});
% Temprature range
T = linspace(global_mid_temp,global_high_temp,1000);
% skipping comment lines
for i = 1:3;
get = fgetl(f1);
end
% Reading the species
for j = 1:53;
tline2 = fgetl(f1);
A = strsplit(tline2,'');
species = (A{1});
end
% Extracting higher and lower cofficent
tline2 = fgetl(f1);
tline3 = fgetl(f1);
tline4 = fgetl(f1);
A = strfind(tline2,'E');
B = strfind(tline3,'E');
C = strfind(tline4,'E');
% finding higher coffis
a1 = str2num(tline2(1:A(1)+3));
a2 = str2num(tline2(A(1)+4:A(2)+3));
a3 = str2num(tline2(A(2)+4:A(3)+3));
a4 = str2num(tline2(A(3)+4:A(4)+3));
a5 = str2num(tline2(A(4)+4:A(5)+3));
a6 = str2num(tline3(1:B(1)+3));
a7 = str2num(tline3(B(1)+4:B(2)+3));
% finding lower cofficent
b1 = str2num(tline3(B(2)+4:B(3)+3));
b2 = str2num(tline3(B(3)+4:B(4)+3));
b3 = str2num(tline3(B(4)+4:B(5)+3));
b4 = str2num(tline4(1:C(1)+3));
b5 = str2num(tline4(C(1)+4:C(2)+3));
b6 = str2num(tline4(C(2)+4:C(3)+3));
b7 = str2num(tline4(C(3)+4:C(4)+3));
% calculating specific heat ,entropy ,enthalpy for lower and highest coffis
% Function to find specific heat
function P = specificheat(a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,T,R,global_mid_temp);
if (T <= global_mid_temp)
cp = R.*(a1+a2.*T+a3.*T.^2+a4.*T.^3+a5.*T.^4);
else
cp = R.*(b1+b2.*T+b3.*T.^2+b4.*T.^3+b5.*T.^4);
end
% function to find entropy
function a = Entropy_calc(a1,a2,a3,a4,a5,a7,b1,b2,b3,b4,b5,b7,T,R,global_mid_temp);
if (T <= global_mid_temp)
a = R.*(a1.*log(T)+a2.*T+a3.*(T.^2)./2+a4.*(T.^3)./3+a5.*(T.^4)./4+a7);
else
a = R.*(b1.*log(T)+b2.*T+b3.*(T.^2)./2+b4.*(T.^3)./3+b5.*(T.^4)./4+b7);
end
% function to find enthalpy
function H = Enthalpy(a1,a2,a3,a4,a5,a6,b1,b2,b3,b4,b5,b6,T,R,global_mid_temp)
if (T <= global_mid_temp)
H =R.*(a1+a2.*T+a3.*T.^2+a4.*T.^3+a5.*T.^4);
else
H = R.*(b1+b2.*T+b3.*T.^2+b4.*T.^3+b5.*T.^4);
end
function W = Molecular_weight(species)
% Defining Atomic name of the species
atomic_name = ['H','C','O','N','Ar'];
% Defining Atomic masses of main species
atomic_weight = [1.008 12.011 15.999 14.007 39.948];
W=0; % Molecular weight starting range
for i=1:length(species)
for j=1:length(atomic_name)
if strcmp(species(i), atomic_name(j))
W = W + atomic_weight(j);
position = j;
end
end
n = str2num(species);
if n>1
W = W + atomic_weight(position)*(n-1);
end
end
fprintf('Molecular Weight of %s :- ',species);
fprintf('%f',W);
disp(' ')
end
plotting(cp,H,a,T,name)
end
end
end
Result
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.