Parsing NASA thermodynamic data
Parsing NASA thermodynamic data
AIM: Right a program Parsing NASA thermodynamic data properties such as Cp, H and S.
PROGRAM EXPLANATION
1. write a program that extracts the 14 coefficients from given THERMO.DAT fil
2. Calculate the enthalpy, entropy and specific heat for all the species in the data fil
3. Calculate the molecular weight of each species and display it in the command window
4. Plot the Cp, Enthalpy and Entropy for the local temperature range (specific for each species)
5. To save the plots as images with appropriate names and dump them in separate folders for each species
6. To save the Cp, Enthalpy and Entropy data in a text fil
7. To make a program to interact with the user in order to automate the whole process where the user enter the species name and the program then retrieves the appropriate data (the plots) and display it in front of the user
8. Calculate the Value of cofficients, calculating the value of Cp,Enthalpy and Entropy
9. Plotting, Printing Molecular Weight Data inCommand Window
10. Saving as .fig for MATLAB, Getting inputFrom User To Disply Plots
11. FUNCTION FOR MOLECULAR WEIGHT
12. function [molecular_weight]=molecular_mass(pecies_name)
13. FUNCTION THERMODYNAMIC PROPERTY
14. function[cp,h,s]= thermodynamic_properties(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,R, temperature_range, medium_global_temperature)
PROGRAM:
clear all
close all
clc
R=8.314;
f1=fopen('THERMO.DAT','r');
%preprocessing
header=fgetl(f1);
overalglobaltemperatureranges=fgetl(f1);
a=strsplit(overalglobaltemperatureranges,' ');
low_global_temperature=str2num(a{2});
medium_global_temperature=str2num(a{3});
high_global_temperature=str2num(a{4});
for i=1:3;
erase=fgetl(f1);
end
%parsing the species
for j=1:53;
overall_local_temperature_range=fgetl(f1);
b=strsplit(overall_local_temperature_range,' ');
low_local_temperature=str2num(b{end-3});
medium_local_temperature=str2num(b{end-3});
high_local_temperature=str2num(b{end-2});
species_name=b{1};
temperature_range=linespace(low_local_temperature,high_local_temperature,200);
coef_line_1=fgetl(f1);
coef_line_2=fgetl(f1);
coef_line_3=fgetl(f1);
�lculate the Value of cofficients
x=findstr(coef_line_1,'E');
a1=str2num(coef_line_1(1:x(1)+3));
a2=str2num(coef_line_1(x(2)+4:x(2)+3));
a3=str2num(coef_line_1(x(3)+4:x(3)+3));
a4=str2num(coef_line_1(x(4)+4:x(4)+3));
a5=str2num(coef_line_1(x(5)+4:x(5)+3));
y=findstr(coef_line_2,'E');
a6=str2num(coef_line_2(1:y(1)+3));
a7=str2num(coef_line_2(y(1)+4:y(2)+3));
a8=str2num(coef_line_2(y(2)+4:y(3)+3));
a9=str2num(coef_line_2(y(3)+4:y(4)+3));
a10=str2num(coef_line_2(y(4)+4:y(5)+3));
z=findstr(coef_line_3,'E');
a11=str2num(coef_line_3(1:z(1)+3));
a12=str2num(coef_line_3(z(1)+4:z(2)+3));
a13=str2num(coef_line_3(z(2)+4:z(3)+3));
a14=str2num(coef_line_3(z(3)+4:z(4)+3));
�lculating the value of Cp,Enthalpy and Entropy
[cp h s]=thermodynamic_properties(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,R,temperature,medium_global_temperature);
�lculating the Molecular Weight of Species
[molecular_weight(j)]=molecular_mass(species_name);
%plotting
set(0,'DefaultFigureVisibale','off')
m(1)=figure;
plot(temperature_range,cp,'linewidth',3,'color','g');
xlabel('Temperature (k)');
ylabel('Specfic Heat (J/kg-K)');
title(['Specfic Heat vs Temperature',species_name]);
m(2)=figure;
plot(temperature_range,h,'linewidth',3,'color','r');
xlabel('Temperature (k)');
ylabel('Enthelpy (J/kg)');
title(['Enthelpy vs Temperature',species_name]);
m(3)=figure;
plot(temperature_range,s,'linewidth',3,'color','y');
xlabel('Temperature (k)');
ylabel('Entropy (J/kg-K)');
title(['Entropy vs Temperature',species_name]);
%Printing Molecular Weight Data inCommand Window
fprintf('Species Name : %6s ',species_name)
fprintf('Molecular Weight : s n',Molecular Weight(j))
cd('D:species');
mkdir(Species Name);
cd(Species Name);
%Saving as .jpg for windows explorer
saveas(m(1),'specfic_heat_vs_Temp.jpg')
saveas(m(2),'enthelpy_vs_Temp.jpg')
saveas(m(3),'entropy_heat_vs_Temp.jpg')
%Saving as .fig for MATLAB
saveas(m(1),'specfic_heat_vs_Temp.fig')
saveas(m(2),'enthelpy_vs_Temp.fig')
saveas(m(3),'entropy_heat_vs_Temp.fig')
%saving data to file
f2=fopen('data_parsing.txt','W');
fprintf(f2, 's : s n','Species Name',species_name);
fprintf(f2, 's : s.3s n','MolecularWeight',molecular_weight(j));
fprintf(f2, 'For the Local Temperature Range : %3.1fk to %3.1fk nn',low_local_temperature,high_local_temperature);
fprintf(f2, '%6s %6s s s n','Temperature(K)','Specific Heat(J/K)','Enthalpy(J/Kg)','Entropy(J/K)');
fprintf(f2, '.2f .2f .2f .2f n',temperature_range,cp,h,s);
cd('D:Matlabbin');
end
fprintf('n The Input File has been stored nn')
%Getting inputFrom User To Disply Plots
Input=input('Do you require Data for Specific Species? Y/N :n','s')
if strcmpi(Input,'Y')
Name=input('Provide Name of Species : ','s')
cd('D:species')
cd(Name)
openfig('specific_heat_vs_Temp','visible');
openfig('enthalpy_vs_Temp','visible');
openfig('entropy_vs_Temp','visible');
fprintf('The Plots Corresponding to the Species have been Opened n')
fprintf('n The Program has ended n')
elseif strcmpi(Input,'N')
fprintf('n The Program has ended n')
else
fprintf('Invalid Input n')
fprintf('n The Program has ended n')
end
atoms=['0','C','H','A','N'];
atomic_weight=[15.999,12.0107,1.00784,39.948,14.0067];
molecular_weight=0;
x=1;
for i=1: length (species_name);
for j=1: length(atoms);
if strcmp(species_name(i),atoms(j))==1;
molecular_weight=atomic_weight(j)+molecular_weight;
atomicweight=atomic_weight(j);
end
end
t=isstrprop(species_name(i),'digit');
c=str2double(regexp(species_name,'d*','Match'));
if t==1
molecular_weight=atomicweight*(c(x)-1)+molecular_weight;
x=x+1;
end
end
end
FUNCTION THERMODYNAMIC PROPERTY:if temperature_range(k)>medium_global_temperature
cp(k)=R.*(a1+(a2.*temperature_range(k))+(a3.*(temperature_range(k)).^2)+(a4.*(temperature_range(k)).^3)+(a5.*(temperature_range(k).^4)));
h(k)=R.*temperature_range(k).*(a1+(a2.*temperature_range(k))./(2)+(a3.*(temperature_range(k)).^2)/(3)+(a4.*(temperature_range(k)).^3)./(4)+(a5.*(temperature_range(k)).^4)./(5)+(a6)./(temperature_range(k)));
cp(k)=R.*(a8+(a9.*(temperature_range(k))+(a10.*(temperature_range(k)).^2)+(a11.*(temperature_range(k)).^3)+(a12.*(temperature_range(k)).^4)));
h(k)=R.*temperature_range(k).*(a8+(a9.*temperature_range(k))./(2)+(a10.*(temperature_range(k)).^2)./(3)+(a11.*(temperature_range(k)).^3)./(4)+(a12.*(temperature_range(k)).^4)./(5)+(a13)./(temperature_range(k)));
end
COMMAND WINDOW:
tline='2.56942078E+00-8.59741137E-05 4.19484589E-08-1.00177799E-11 1.22833691E-15 2'
tline =
'2.56942078E+00-8.59741137E-05 4.19484589E-08-1.00177799E-11 1.22833691E-15 2'
>> a=findstr(tline,'E')
a =
11 26 41 56 71
>> tline(12)
ans =
'+'
>> tline(1:12)
ans =
'2.56942078E+'
>> tline(1:12+3)
ans =
'2.56942078E+00-'
>> a1=tline(1:a(1)+3)
a1 =
'2.56942078E+00'
>> a1=str2numa(a1)
Unrecognized function or variable 'str2numa'.
Did you mean:
>> a1=str2num(a1)
a1 =
2.5694
>> tline(a(1)+4:a(2)+3)
ans =
'-8.59741137E-05'
>> tline(a(1)+4:a(2)+3)
ans =
'-8.59741137E-05'
ERROR DURING PROGRAM: I cheaked all error and edit sone text error