FILE PARSING -NASA thermodynamic data
FILE PARSING FOR NASA THERMODYNAMIC POLYNOMIALS:
The NASA has experimented the thermodynamic polynomial values for different temprature for most of the gaseous elements and listed in a .DAT file. we are going to extract the values and check it for various temprature properties like cp, enthalpy,entropy using MATLAB by file parsing method. The file parsing is a important option for us to extract the information from a file that contains experimented values. With this we can calculated our requirements from that readable file and even check whether the values are true. Even we can plot these in a graph and view its properties. From the graph we can we interpret the oscillation and difference between each values calculated.Here in this report we have calculated the values and also compared for low and high temprature, Because in earth, each and every location has different temprature gradients.The graphs are also attached.
clear all
close all
clc
f1=fopen('THERMO.DAT','r')
c=fgetl(f1)
o='300.000 1000.000 5000.000'
A=strsplit(o,' ')
for u=1:3
[O(u)]=str2num(A{u})
end
global_high_temp=max(O)
global_low_temp=min(O)
w1=fgetl(f1)
w2=fgetl(f1)
w3=fgetl(f1)
w4=fgetl(f1)
for k=1:159
if rem(k,4)==1
element=fgetl(f1)
if k==73
findG=findstr(element,'G')
temps=[element(findG(2)+4: findG(2)+30)]
local_low_temp=temps(1:7)
llt=str2num(local_low_temp) %the local low temp is made from string to number
local_high_temp=temps(10:17)
lht=str2num(local_high_temp)
elseif k==125
findG=findstr(element,'G')
temps=[element(findG(2)+4: findG(2)+30)]
local_low_temp=temps(1:7)
llt=str2num(local_low_temp) %the local low temp is made from string to number
local_high_temp=temps(10:17)
lht=str2num(local_high_temp)
else
findG=findstr(element,'G')
temps=[element(findG(1)+4: findG(1)+30)]
local_low_temp=temps(1:7)
llt=str2num(local_low_temp) %the local low temp is made from string to number
local_high_temp=temps(10:17)
lht=str2num(local_high_temp)%the local high temp is made from string to number
end
else
z=rem(k,4)
if z~=1
j=z
values1=fgetl(f1)
findE=findstr(values1,'E')
ac1=[values1(2:findE(1)+3)]
a1=str2num(ac1)
ac2=[values1(findE(1)+4:findE(2)+3)]
a2=str2num(ac2)
ac3=[values1(findE(2)+4:findE(3)+3)]
a3=str2num(ac3)
ac4=[values1(findE(3)+4:findE(4)+3)]
a4=str2num(ac4)
g=rem(k,4)
if g~=0
ac5=[values1(findE(4)+4:findE(5)+3)] %in third line there is no ac5 for every element
a5=str2num(ac5)
[cpl(k)]=a1+(a2*llt)+(a3*llt^2)+(a4*llt^3)+(a5*llt^4) %cp for low temp
[cph(k)]=a1+(a2*lht)+(a3*lht^2)+(a4*lht^3)+(a5*lht^4) %cp for high temp
[hl(k)]=a1+((a2*llt)/2)+((a3*llt^2)/3)+((a4*llt^3)/4)+((a5*llt^4)/5) %enthalphy for low temp
[hh(k)]=a1+((a2*lht)/2)+((a3*lht^2)/3)+((a4*lht^3)/4)+((a5*lht^4)/5) %enthalphy for high temp
[sl(k)]=(a1*log(llt))+(a2*llt)+((a3*llt^2)/2)+((a4*llt^3)/3)+((a5*llt^4)/4) %entropy of low temp
[sh(k)]=(a1*log(lht))+(a2*lht)+((a3*lht^2)/2)+((a4*lht^3)/3)+((a5*lht^4)/4) %entropy of high temp
end
if g==0
[cpl(k)]=a1+(a2*llt)+(a3*llt^2)+(a4*llt^3) %cp for low temp
[cph(k)]=a1+(a2*lht)+(a3*lht^2)+(a4*lht^3) %cp for high temp
[hl(k)]=a1+((a2*llt)/2)+((a3*llt^2)/3)+((a4*llt^3)/4) %enthalphy for low temp
[hh(k)]=a1+((a2*lht)/2)+((a3*lht^2)/3)+((a4*lht^3)/4) %enthalphy for high temp
[sl(k)]=(a1*log(llt))+(a2*llt)+((a3*llt^2)/2)+((a4*llt^3)/3) %entropy of low temp
[sh(k)]=(a1*log(lht))+(a2*lht)+((a3*lht^2)/2)+((a4*lht^3)/3)
end
end
end
end
figure(1)
plot(cpl,'color','r')
title('cp for low temprature')
figure(2)
plot(cph,'color','b')
title('cp for high temprature')
figure(3)
plot(hl,'color','k')
title('enthalpy for low temprature')
figure(4)
plot(hh,'color','c')
title('enthalpy for high temprature')
figure(5)
plot(sl,'color','g')
title('entropy for low temprature')
figure(6)
plot(sh,'color','m')
title('entropy for high temprature')
figure(7)
plot(cpl,cph,'linewidth',2,'color','r')
title('cpl vs cph')
xlabel('cp for low temprature')
ylabel('cp for high temprature')
figure(8)
plot(hl,hh,'linewidth',2,'color','c')
title('hl vs hh')
xlabel('enthalpy for low temprature')
ylabel('enthalpy for high temprature')
figure(9)
plot(sl,sh,'linewidth',2,'color','g')
title('sl vs sh')
xlabel('entropy for low temprature')
ylabel('entropyfor high temprature')
%the above graphs are determined with the help of the NASA thermodynamic
%experiment values
THE EXPLANATION OF THE CODE AND THE ERRORS FACED ARE ALSO MENTIONED.THE DAT FILE IS ALSO ATTACHED.
FILE PARSING FROM THE NASA THERMODYNAMIC VALUES
clear all
close all
clc
THE PREVIOUS MEMORY IS CLEARED HERE.
f1=fopen('THERMO.DAT','r')
THE FILE THERMO.DAT IS OPENED AND READ.MAKE SURE THE FILE AND THE MATLAB CODE IS IN THE SAME DIRECTORY.
c=fgetl(f1)
fgetl GETS THE FIRST LINE FROM THE FILE.THE FILE SHOULD BE READABLE.
o='300.000 1000.000 5000.000'
A=strsplit(o,' ')
Strsplit HELPS US IN SPLITING THE STRING THAT WE ENTERED IN ‘o’ IN THE PLACES WHERE ‘ ‘ IS PRESENT.
for u=1:3
[O(u)]=str2num(A{u})
End
THIS LINE CONERTS THE SPLITTED STRING INTO NUMBERS.
global_high_temp=max(O)
THE MAXIMUM NUMBER IS TAKEN HERE.
global_low_temp=min(O)
THE MINIMUM NUMBRER IS TAKEN HERE.
w1=fgetl(f1)
w2=fgetl(f1)
w3=fgetl(f1)
w4=fgetl(f1)
HERE THE FOUR LINES WHICH ARE COMMMENTS (CAN BE OMMITED HIS PRINTED AND STORED) AS IF fgetl IS EXECUTED, EACH TIME THE NEXT LINE IS READ.
for k=1:159
THIS LOOP IS FOR THE NEXT 159 LINES OF 53 ELEMENTS.
if rem(k,4)==1
THIS CHECKS THE WHETHER THE REMAINDER IS 1 0R NOT EACH TIME WHEN A LINE IS EXECUTED.
element=fgetl(f1)
if k==73
FOR CERTAIN LINES, DUE TO SOME CONSTRAINTS, THOSE LINES ARE MENTIONED SEPRATEDLY.THESE CONSTRAINTS WILL BE MENTIONED LATER IN THIS DOCUMENT.
findG=findstr(element,'G')
FINDS THE ALPHABET G IN THE STRING AND STORES ITS PLACE IN A MATRIX.
temps=[element(findG(2)+4: findG(2)+30)]
HERE THE STRING OF CERTAIN NUMBER OF VALUES IS STORED IN THE temps MATRIX.
local_low_temp=temps(1:7)
HERE THE STRING FROM 1 TO 7 IS STORED IN THE ASSIGNED VARIABLE.
llt=str2num(local_low_temp) %the local low temp is made from string to number
THE STRING THAT WAS STORED IS CONVERTED TO NUMBER(INTEGER).
local_high_temp=temps(10:17)
lht=str2num(local_high_temp)
AGAIN THE SAME IS DONE, FOR ANOTHER STRING POSITION
elseif k==125
findG=findstr(element,'G')
temps=[element(findG(2)+4: findG(2)+30)]
local_low_temp=temps(1:7)
llt=str2num(local_low_temp) %the local low temp is made from string to number
local_high_temp=temps(10:17)
lht=str2num(local_high_temp)
DUE TO CERTAIN CONDITIONS ,AGAIN THE LINE NUMBER IS MENTIONED HERE.
else
findG=findstr(element,'G')
temps=[element(findG(1)+4: findG(1)+30)]
local_low_temp=temps(1:7)
llt=str2num(local_low_temp) %the local low temp is made from string to number
local_high_temp=temps(10:17)
lht=str2num(local_high_temp)%the local high temp is made from string to number
end
EITHER OF THE ABOVE TWO LINES, OTHER LINES FOLLOW THE ABOVE SYNTAX. HERE ALSO THE STRING IS TAKEN AND STORED AS AN INTEGER IN A VARIABLE.
else
z=rem(k,4)
if z~=1
j=z
NOW AGAIN THE REMAINDER IS CHECKED. BECAUSE ONLY THE FIRST LINE CONSISTS STRING. THE OTHER 3 LINES CONTAINS THE COEFFECIENTS, WHICH SHOULD BE TAKEN AND ACCOUNTED FOR CALCULATION.
values1=fgetl(f1)
findE=findstr(values1,'E')
ac1=[values1(2:findE(1)+3)]
a1=str2num(ac1)
ac2=[values1(findE(1)+4:findE(2)+3)]
a2=str2num(ac2)
ac3=[values1(findE(2)+4:findE(3)+3)]
a3=str2num(ac3)
ac4=[values1(findE(3)+4:findE(4)+3)]
a4=str2num(ac4)
g=rem(k,4)
if g~=0
ac5=[values1(findE(4)+4:findE(5)+3)] %in third line there is no ac5 for every element
a5=str2num(ac5)
UPTO HERE THE VALUES ARE TAKEN INTO DIFFERENT COEFFECIENTS FOR CALCULATION.BUT FOR EVERY ELEMENT 3RD LINE CONTAIMS ONLY FOUR COEFFECIENTS, HENCE WE AGAIN CREATED A REMAINDER LOOP FOR IT.SO THAT FOR 3RD LINE ONLY 4 COEFFECIENTS ARE ACCOUNTED.
[cpl(k)]=a1+(a2*llt)+(a3*llt^2)+(a4*llt^3)+(a5*llt^4) %cp for low temp
[cph(k)]=a1+(a2*lht)+(a3*lht^2)+(a4*lht^3)+(a5*lht^4) %cp for high temp
[hl(k)]=a1+((a2*llt)/2)+((a3*llt^2)/3)+((a4*llt^3)/4)+((a5*llt^4)/5) %enthalphy for low temp
[hh(k)]=a1+((a2*lht)/2)+((a3*lht^2)/3)+((a4*lht^3)/4)+((a5*lht^4)/5) %enthalphy for high temp
[sl(k)]=(a1*log(llt))+(a2*llt)+((a3*llt^2)/2)+((a4*llt^3)/3)+((a5*llt^4)/4) %entropy of low temp
[sh(k)]=(a1*log(lht))+(a2*lht)+((a3*lht^2)/2)+((a4*lht^3)/3)+((a5*lht^4)/4) %entropy of high temp
NOW ALL THESE COEFFECIENTS ARE CALCULATED IN CP,ENTHALPY, ENTROPY FOR EACH LINE OF EVERY ELEMENT FOR BOTH LOW AND HIGH LOCAL TEMPRATURES IN ITS 1ST LINE.
end
if g==0
[cpl(k)]=a1+(a2*llt)+(a3*llt^2)+(a4*llt^3) %cp for low temp
[cph(k)]=a1+(a2*lht)+(a3*lht^2)+(a4*lht^3) %cp for high temp
[hl(k)]=a1+((a2*llt)/2)+((a3*llt^2)/3)+((a4*llt^3)/4) %enthalphy for low temp
[hh(k)]=a1+((a2*lht)/2)+((a3*lht^2)/3)+((a4*lht^3)/4) %enthalphy for high temp
[sl(k)]=(a1*log(llt))+(a2*llt)+((a3*llt^2)/2)+((a4*llt^3)/3) %entropy of low temp
[sh(k)]=(a1*log(lht))+(a2*lht)+((a3*lht^2)/2)+((a4*lht^3)/3)
THIS IS FOR THE 3RD LINE THAT HAS 4 COEFFICIENTS.
end
end
end
end
ALWAYS MAKE SURE WE GIVE THE REQUIRED NUMBER OF end STATEMENTS TO END EACH LOOP.
figure(1)
plot(cpl,'color','r')
title('cp for low temprature')
figure(2)
plot(cph,'color','b')
title('cp for high temprature')
figure(3)
plot(hl,'color','k')
title('enthalpy for low temprature')
figure(4)
plot(hh,'color','c')
title('enthalpy for high temprature')
figure(5)
plot(sl,'color','g')
title('entropy for low temprature')
figure(6)
plot(sh,'color','m')
title('entropy for high temprature')
figure(7)
plot(cpl,cph,'linewidth',2,'color','r')
title('cpl vs cph')
xlabel('cp for low temprature')
ylabel('cp for high temprature')
figure(8)
plot(hl,hh,'linewidth',2,'color','c')
title('hl vs hh')
xlabel('enthalpy for low temprature')
ylabel('enthalpy for high temprature')
figure(9)
plot(sl,sh,'linewidth',2,'color','g')
title('sl vs sh')
xlabel('entropy for low temprature')
ylabel('entropyfor high temprature')
%the above graphs are determined with the help of the NASA thermodynamic
%experiment values
FOR EACH CALCULATED HEAT PROPERTIES GRAPH IS PLOTTED. AND WE ALSO COMPARED THE SAME PROPERTY WITH LOW AND HIGH LOCAL TEMPRATURES.
ERRORS FACED:
- WHEN CODING IS DONE AND EXECUTED, I FACED A PROBLEM IN A PARTICULAR ELEMENT. SINCE IT HAD TWO G’s IN THE FIRST LINE. THE findG WAS NOT ESSENTIAL.
- SINCE TWO G’s WERE PRESENT, I TRIED TO CHECK THE NEXT POSITION TO THE ALPHABET G, WHICH WAS ALSO ALPHABET.
- BY USING THE LOOP TO CHECK FOR A STRING, AND EXECUTE PARTICULAR STATEMENTS. IT WORKED.
- BUT UNFORTUNATELY, THE CODE DID NOT WORKED FOR THE NEXT ELEMENT. BECAUSE I WAS UNABLE TO CHECK THE LOOP FOR A ‘SPACE‘.
- HENCE I MENTIONED THOSE LINE TO PERFORM ITS TASKS.
(the graphs are in ‘MATLAB DOCS’ in PC)
-----THE END----
THE GRAPHS ARE ATTACHED HERE.
FOR CP IN LOW TEMPRATURE,
FOR CP IN HIGH TEMPRATURE,
FOR CP IN LOW TEMPRATURE VS CP IN HIGH TEMPRATURE,
FOR ENTHALPY IN LOW TEMPRATURE,
FOR ENTHALPY IN HIGH TEMPRATURE,
FOR ENTHALPY FOR LOW TEMPRATURE VS ENTHALPY FOR HIGH TEMPRATURE,
FOR ENTROPY IN LOW TEMPRATURE,
FOR ENTROPY IN HIGH TEMPRATURE,
FOR ENTROPY FOR LOW TEMPRATURE VS ENTROPY FOR HIGH TEMPRATURE,
HENCE WE EXTRACTED AND PLOTTED GRAPHS FOR THE NASA THRERMODYNAMIC .DAT FILE.
TRY THIS CODE AND ENJOY.