Project 1 - Parsing NASA thermodynamic data
close all
clear
clc
%Inputs
R= 8.314;
%Reading the data file
f1 = fopen('THERMO.dat','r');
%Reading the first line of the file
L1 = fgetl(f1);
%Getting the global minimum, maximum and mid temperatures
L2 = fgetl(f1);
t = strsplit(L2);
global_min = str2double(t{2});
global_mid = str2double(t{3});
global_max = str2double(t{4});
%Defining the temperature range
temp = linspace (global_min,global_max,500);
%Ignoring the comments in the file
for i=1:3
fgetl(f1);
end
for i=1:53
%Reading the first line which includes the information for species
l=fgetl(f1);
%Reading the name of the species
element_name=strtok(l);
%Reading the three lines which contains 7 high temp coefficients & 7 low temp
%coefficients
l1=fgetl(f1);
l2=fgetl(f1);
l3=fgetl(f1);
%Finding the position of E so that we can extract the coefficients
a=strfind(l1,'E');
b=strfind(l2,'E');
c=strfind(l3,'E');
%Extracting high temp coefficient
a1=str2double(l1(1:a(1)+3));
a2=str2double(l1(a(1)+3:a(2)+3));
a3=str2double(l1(a(2)+4:a(3)+3));
a4=str2double(l1(a(3)+4:a(4)+3));
a5=str2double(l1(a(4)+4:a(5)+3));
a6=str2double(l2(1:b(1)+3));
a7=str2double(l2(b(1)+4:b(2)+3));
%Extracting low temp coefficient
b1=str2double(l2(b(2)+4:b(3)+3));
b2=str2double(l2(b(3)+4:b(4)+3));
b3=str2double(l2(b(4)+4:b(5)+3));
b4=str2double(l3(1:c(1)+3));
b5=str2double(l3(c(1)+4:c(2)+3));
b6=str2double(l3(c(2)+4:c(3)+3));
b7=str2double(l3(c(3)+4:c(4)+3));
%Calculating specific heat
c_p = specific_heat(a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,R,temp,...
global_min,global_max,global_mid);
%Calculalting enthalpy
H = enthalpy(a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,R,temp,global_min,...
global_max,global_mid);
%calculating entropy
S = entropy(a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,R,temp,global_min,...
global_max,global_mid);
%Plotting graphs
plotting(c_p,H,S,temp,element_name);
%Calculating molecular weights
mol_wt(i) = Molecular_weight(element_name);
disp(mol_wt(i));
Molucular_Weight = strcat(mol_wt(i),element_name)
%Function to write molecular weight to a file
weight = mol_wt(i);
writing_to_file(element_name, weight);
end
fclose(f1)