Project 1 - Parsing NASA thermodynamic data
AIM : TO PARSE THE THERMODYNAMIC FROM NASA USING MATLAB.
THEORY:
The official record of thermodynsmic values at difrant temprature has been stored b nasa in the polynomial with soecific constant from one to fourteen for various species in order to quantity the values. the polynomial can be soled with defined temprature values in accordance with our requarment .The term parsing refer to matlab reading on m file (script)transisting in to an internal code that it stores in memory .
GROVING EQUATIONS :
SPECIFIC HEAT :
cp = R*(a1 + a2*T +a3*T^2 + a4*T^3 + a5*T^4)
ENTHALPY :
s = (a1log(T) + a2*T + (a3*T^2)/2 +(a4*T^2)/3 + (a5.*T^2)/4 + a7 )*R
where
Cp = specific heat
H = Enthalpy
S =Entropy
R = Univarsal gas constant
T = Temprature
The first 7 coefficant is high temprature and second 7 is low temprature coefficant
OBJECTIVE :
- To write a function that extracts the 14 co-efficients and calculates the enthalpy, entropy and specific heats for all the species
- To Calculate the molecular weight of each species and display it in the command window.
- Plot the specific heat Enthalpy and Entropy for the local temperature range global low temperature to global high temperature.
- Save the plots as images with appropriate names and dump them in separate folders for each species
FUNCTIONS of PROGRAM :Calculate thermodynamic properties(SPECIFIC HEAT,ENTHALPY ,ENTROPY)
SPECIFIC HEAT :
function [cp] = specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,T,R,global_mid_temp)
if T <= global_mid_tempcp = R*(a1 + a2*T +a3*T.^2 + a4*T.^3 + a5*T.^4) elsecp = (a8 + a9*T +a10*T.^2 + a11*T.^3 + a12 *T.^4).*R endendENTHALPY :
function [h] = enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,T,R,global_mid_temp)if T<=global_mid_temph = R*T.*(a8 + (a9*T)/2 + (a10*T.^2)/3 + (a11*T.^3)/4 + (a12*T.^4)/5 + (a13./T));elseh = R*T.*(a1 + (a2*T)/2 + (a3*T.^2)/3 + (a4*T.^3)/4 + (a5*T.^4)/5 + (a6./T));endendENTROPY:
function [s] = entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,T,R,global_mid_temp)if T<=global_mid_temps = (a8*log(T) + a9*T + (a10*T.^2)/2 +(a11*T.^3)/3 + (a12*T.^4)/4 + a14 )*R;elses = (a1*log(T) + a2*T + (a3*T.^2)/2 +(a4*T.^3)/3 + (a5*T.^4)/4 + a7 )*R;endendMOLECULAR WEIGTH :
%calculating molecular weight of species mentioned in data filefunction[molecular_weight] =mole_wt(species_name)SPECIES = (species_name)constituents = ['H','C','N','O','A'];atomic_weight =[1 12 14 16 40];molecular_weight = 0;for i = 1:length(SPECIES)for j = 1: length (constituents)if strcmp(SPECIES(i),constituents(j))molecular_weight = molecular_weight + atomic_weight(j);u = j;endendn = str2double(SPECIES(i));if (n >1)molecular_weight = molecular_weight + atomic_weight(u)*(n-1)endendfprintf('molecular_weightof %s:-, species_name')endMAIN PROGRAM :
close all
clear allclc%reading the thermodynamic data filef1 = fopen('THERMO.dat','r');file_name = fgetl(f1);t_line = fgetl(f1);A = strsplit(t_line);R = 8.314%Defiining the temprature extreacted from data file%for i = (1:3);comments = fgetl(f1);endfor i = 1:53;%exteract species namespecies = fgetl(f1);B=strsplit(species,' ')species_name = B{1};global_low_temp = str2double(B{end-3});global_mid_temp = str2double(B{end-1});global_high_temp = str2double(B{end-2});T = linspace(global_low_temp,global_high_temp,500)%Exteracting coefficent from first lineline_1 = fgetl(f1);l1 = strfind(line_1,'E');a1 = str2double(line_1(1:(l1(1)+3)));a2 = str2double(line_1((l1(1)+4):(l1(2)+3)));a3 = str2double(line_1((l1(2)+4):(l1(3)+3)));a4 = str2double(line_1((l1(3)+4):(l1(4)+3)));a5 = str2double(line_1((l1(4)+4):(l1(5)+3))); %Exteracting coefficent from second lineline_2 = fgetl(f1);l2 = strfind(line_2,'E');a6 = str2double(line_2((l2(1)+4):(l1(2)+3)));a7 = str2double(line_2((l2(1)+4):(l1(2)+3)));a8 = str2double(line_2((l2(2)+4):(l1(3)+3)))a9 = str2double(line_2((l2(3)+4):(l1(4)+3)))a10 = str2double(line_2((l2(4)+4):(l1(5)+3)))%Exteracting coefficent from third lineline_3 = fgetl(f1)l3 = strfind(line_3,'E')a11 = str2double(line_3(1:(l3(1)+3)))a12 = str2double(line_3((l3(1)+4):(l3(2)+3)))a13 = str2double(line_3((l3(2)+4):(l3(3)+3)))a14 = str2double(line_3((l3(3)+4):(l3(4)+3))) %calling the thermodaynamic equation functioncp = specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,T,R,global_mid_temp);h = enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,T,R,global_mid_temp);s = entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,T,R,global_mid_temp);%creating a folder "SPEACS' to save the thermodaynamic plot of speciesmkdir(species_name)cd(species_name)%plotting%plotting between temprature and specific heatfigure(1)plot(T,h,'linewidth',3,'color','b')title('species name')ylabel('TEMPRATURE')xlabel('ENTHALPY')%plotting between temprature and enthalpyfigure(2)plot(T,h,'linewidth',3,'color','g')title('species name')ylabel('TEMPRATURE')xlabel('ENTHALPY')%plotting between temprature and entropyfigure(2)plot(T,h,'linewidth',3,'color','g')title('species name')ylabel('TEMPRATURE')xlabel('ENTHALPY')%save plotssaveas(1,'specific_heat.png')saveas(1,'enthalpy.png')saveas(1,'entropy_heat.png')%change dirctory for calculating molecular weightcd ..molecular_weight = mole_wt(species_name)endfclose(f1)EXPLANATION
- initially a code write the desired data fie an value is assaned difrant value or variables.
- data is read with difrant comand
- difrant folder with the species name is desired location
- creating difrant plots in difrant folder
- creating a difrant function comands like specific heat ,enthalpy, entropy and mole weight
- plots are saveing in specifed folder.
CONCLUTION :
The parsing thermodaynamic data fle by NASA is done using certain comands on matlab the plot of themodayanmic property vs temprature by certain speart moving folder. fucntion has to be coded to calculate the molecular waight of the species mentioned in the given data form the above progaram.it can be extreact new foulder.