Project 1 - Parsing NASA thermodynamic data
clear all
close all
clc
R= 8.314;% gas constant
%opening and reading of file
f1= fopen('THERMO.dat','r')
get= fgetl(f1);
temp=fgetl(f1);
%splitting
s= strsplit(temp);
%converting strings cells into numbers
templow= str2num(s{2});
tempmid= str2num(s{3});
temphigh= str2num(s{4});
%temperature range
T=linspace(templow,temphigh,1000);
% skipping comment lines
for i= 1:3
get = fgetl(f1);
end
for j=1:53
tline= fgetl(f1);
A= strsplit(tline,' ');
species= (A{1});
%converting strings cells into numbers
lowtemp= str2num(A{end-3});
midtemp= str2num(A{end-2});
hightemp= str2num(A{end-1});
tline1= fgetl(f1);
a= strfind(tline1,'E');
%finding the higher coefficients
a1= tline1(1:a(1)+3);
a1= str2num(a1);
a2= tline1(a(1)+4:a(2)+3);
a2=str2num(a2);
a3= tline1(a(2)+4:a(3)+3);
a3=str2num(a3);
a4= tline1(a(3)+4:a(4)+3);
a4=str2num(a4);
a5= tline1(a(4)+4:a(5)+3);
a5= str2num(a5);
tline2= fgetl(f1);
b= strfind(tline2,'E');
a6=tline2(1:b(1)+3);
a6= str2num(a6);
a7= tline2(b(1)+4:b(2)+3);
a7 = str2num(a7);
%finding lower coefficients
a8= tline2(b(2)+4:b(3)+3);
a8=str2num(a8);
a9= tline2(b(3)+4:b(4)+3);
a9=str2num(a9);
a10= tline2(b(4)+4:b(5)+3);
a10= str2num(a10);
tline3= fgetl(f1);
c= strfind(tline3,'E');
a11= tline(1:c(1)+3);
a11=str2num(a11);
a12= tline3(c(1)+4:c(2)+3);
a12= str2num(12);
a13= tline3(c(2)+4:c(3)+3);
a13=str2num(a13);
a14= tlines3(c(3)+4:c(4)+3);
a14= str2num(a14);
%calculate specific heat
cp= specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,T,R,tempmid);
%calculate entropy
S= entropy(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,a14,T,R,tempmid);
%calculate enthalpy
H= enthalpy(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,a13,T,R,tempmid);
MW= molecular_weight(species);
MW_file= fopen('molecular weight.txt','w');
fprintf(MW_file,'molecular weight of %s is %d ',species,MW);
fclose(MW_file);
%plotting cp,H& S with temp
cd('C:/users/karth/week4 test2/species')
mkdir(species);
cd(species);
figure(1)
plot(T,cp,'linewidth',3,'color','r');
xlabel('temperature (k)');
ylabel('specific heat (kj)');
title(sprintf('specific heat vs temperature range of %s',species));
grid on
saveas(figure(1),'specific heat.jpg');
figure(2)
plot(T,S,'linewidth',3,'color','g');
xlabel('temperature (k)');
ylabel('entropy (kj/mol-k)');
title(sprintf('entropy vs temperature range of %s',species));
grid on
saveas(figure(2),'sentropy.jpg');
figure(3)
plot(T,H,'linewidth',3,'color','b');
xlabel('temperature (k)');
ylabel('enthalpy (kj/mol)');
title(sprintf('enthalpy vs temperature range of %s',species));
grid on
saveas(figure(3),'enthalpy.jpg');
cd('C:/users/karth')
MW = molecular_weight(species)
end
discrepition for project
firstly code is written for reading the data , coefficient and constant were assigned.
new folder is called - species and which help to generate plots and molecular weight function value are diplayed on command window