Project 1 - Parsing NASA thermodynamic data
AIM :
1. Write a function that extracts the 14 co-efficients and calculates the enthalpy, entropy and specific heats for all the species in the data file. You will be reading this file NASA thermodynamic data(Tip: use fopen and fgetl). The formulae are shown below.
Here R is the universal gas constant, T is the temeprature
The FIRST 7 coefficients are HIGH-temperature coefficients and the SECOND 7 coefficients are LOW-temperature coefficients.
Also use the LOCAL TEMPERATURE RANGES which is unique for each individual species, not the GLOBAL TEMPERATURE RANGE.
2. Calculate the molecular weight of each species and display it in the command window.
3. Plot the Cp, Enthalpy and Entropy for the local temperature range (low temperature : high temperature) specific for each species.
4. Save the plots as images with appropriate names and dump them in separate folders for each species with suitable name. All these should be generated automatically.
THEORY :
Parsing: Parsing a file means reading in a data stream and building a memory model of the content of that data. This aims at facilitating perfoming some kind of transformation on the data. Parsing splits a file or other input into pieces of data that can be easily stored or manipulated.
DATA SOURCE :
Link to thermodynamic data file,
FORMULAE USED :
MAIN code :
clear allclose allclcF1=fopen('THERMO.dat','r')first_line=fgetl(F1);R=8.314;temp=fgetl(F1);A=strsplit(temp,' ');globel_low_tempreture=str2num(A{2});globel_middle_tempreture=str2num(A{3});globel_high_tempreture=str2num(A{4});tempreture=linspace(globel_low_tempreture,globel_high_tempreture,globel_middle_tempreture);third_line=fgetl(F1);fourth_line=fgetl(F1);fifth_line=fgetl(F1);for i=1:53sixth_line=fgetl(F1);M=strsplit(sixth_line,' ');species_name=M{1};sixth_line_one=fgetl(F1);a=findstr(sixth_line_one,'E');a1=sixth_line_one(1:a(1)+3);a1=str2num(a1);a2=sixth_line_one(a(1)+4:a(2)+3);a2=str2num(a2);a3=sixth_line_one(a(2)+4:a(3)+3);a3=str2num(a3)a4=sixth_line_one(a(3)+4:a(4)+3);a4=str2num(a4);a5=sixth_line_one(a(4)+4:a(5)+3);a5=str2num(a5);sixth_line_sec=fgetl(F1)a=findstr(sixth_line_sec,'E')a6=sixth_line_sec(1:a(1)+3);a6=str2num(a6);a7=sixth_line_sec(a(1)+4:a(2)+3);a7=str2num(a7);a8=sixth_line_sec(a(2)+4:a(3)+3);a8=str2num(a8)a9=sixth_line_sec(a(3)+4:a(4)+3);a9=str2num(a9);a10=sixth_line_sec(a(4)+4:a(5)+3);a10=str2num(a10);sixth_line_third=fgetl(F1)a=findstr(sixth_line_sec,'E')a11=sixth_line_sec(1:a(1)+3);a11=str2num(a11);a12=sixth_line_sec(a(1)+4:a(2)+3);a12=str2num(a12);a13=sixth_line_sec(a(2)+4:a(3)+3);a13=str2num(a13)a14=sixth_line_sec(a(3)+4:a(4)+3);a14=str2num(a14);A=entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,tempreture,globel_middle_tempreture,R);B=enthalphy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,tempreture,globel_middle_tempreture,R)C=speciofic_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,tempreture,globel_middle_tempreture,R)molecular_w(i) = molecular_weight(species_name)molecular_weight_of_the_species=fopen('molecular_weight.txt','w');fprintf(molecular_weight_of_the_species,'molecular weight of the %s is %f \n',species_name,molecular_w);fclose( molecular_weight_of_the_species)derectory_curr=pwd;mkdir(species_name);cd(species_name);figure(1)plot(tempreture,A,'color','r',LineWidth=2)xlabel('tempreturess')ylabel('entropys')grid ontitle(sprintf('variation in entropy wrt tempreture in %s',species_name))saveas(figure(1),'entrogy.jpg')figure(2)plot(tempreture,B,'color','b',LineWidth=2)xlabel('tempreture')ylabel('enthalpy')grid ontitle(sprintf('variation in enthalpy wrt tempreture in %s',species_name))saveas(figure(2),'enthalpy.jpg')figure(3)plot(tempreture,C,'color','k',LineWidth=2)xlabel('tempreture')ylabel('specific_heat')grid ontitle(sprintf('variation in specific heat wrt tempreture in %s',species_name))saveas(figure(3),'specificheat.jpg')cd(derectory_curr)end



function molecular_w = molecular_weight(species_name)key_possion=['O','H','C','N','A']compounds_value= [15.999,1.008,12.011,14.007,39.948];molecular_w= 0;for i = 1:length(species_name)for j = 1:length(key_possion)if strcmp(species_name(i),key_possion(j))molecular_w= molecular_w+compounds_value(j);poss = j;endendK= str2num(species_name(i));if (K>1)molecular_w = molecular_w+compounds_value(j)*(K-1);endfprintf('molecular weight of the species %s',species_name)fprintf('%f',molecular_w)disp(' ')end
function [A]=entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,tempreture,globel_middel_temp,R)if (tempreture>=globel_middel_temp)A=R*(a1.*log(tempretur)+a2.*(tempreture)+(a3.*(tempreture).^2/2)+(a4.*(tempreture.^3)/3)+(a5.*(tempreture).^4/4)+a7);elseA=R.*(a8.*log(tempreture)+a9.*(tempreture)+(a10.*(tempreture).^2/2)+(a11.*(tempreture.^3)/3)+(a12.*(tempreture).^4/4)+a14);endend
function [B]=enthalphy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,tempreture,globel_middel_temp,R)if (tempreture>=globel_middel_temp)B=R.*tempreture.*(a1+(a2.*tempreture/2)+(a3.*(tempreture).^2/3)+(a4.*(tempreture).^3/4)+(a5.*(tempreture).^4/5)+(a6.*(tempreture).^5/6));elseB=R.*tempreture.*(a8+(a9.*tempreture/2)+(a10.*(tempreture).^2/3)+(a11.*(tempreture).^3/4)+(a12.*(tempreture).^4/5)+(a13.*(tempreture).^5/6));endend
function [C]=speciofic_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,tempreture,globel_middel_temp,R)if (tempreture>=globel_middel_temp)C=R.*(a1+(a2.*(tempreture))+(a3.*(tempreture).^2)+(a4.*(tempreture).^3)+(a5.*(tempreture).^4));elseC=R.*(a8+(a9.*(tempreture))+(a10.*(tempreture).^2)+(a11.*(tempreture).^3)+(a12.*(tempreture).^4));endend







