Challenge

Project 1 - Parsing NASA thermodynamic data

AIM: Parsing the NASA s thermodynamic data using the matlab.NASA  came up with polynomials that can be used to evaluate thermodynamic properties such as Cp, H and S. They have also documented the co-efficients that are required to evaluate these polynomials for 1000+ species.

PROCEDURE:

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.

5. The main program that you will submit will just take the "THERMO.dat" file as an input and generate Cp, H and S plots.

6. Please write a detailed report to describe your logic.

ERRORS ENCOUNTERED:

PLOTS:

CODE:

clear all %#ok
close all
clc

 
R = 8.314;

 
% OPEN AND LOADING THE THERMO.dat file.

 
f = fopen('THERMO.dat','r');

 
% skipping the 4 lines of starting and reach out to the header file.

 
for i =1:5
fgetl(f);

 

 

 
end

 
% use the for loop as we have to rum the same code fot the diffrenr 53
% species those are present inside the THERMO.dat file.

 
for i = 1:53 %#ok

 
% get the line which contains all the local temperatures.
A = fgetl(f);

 
% split all the individual characters using the strsplit command.

 
b = strsplit(A,' ');

 
species_name = b{1};

 
% Extracting the local,mid and high temperature by the assuming the referce
% from the back side.

 
low_local_temp =str2num(b{length(b)-3}); %#ok
mid_local_temp = str2num(b{length(b)-1}); %#ok
high_local_temp = str2num(b{length(b)-2}); %#ok

 
% Extracting the coefficients for the calculation of the cp,h,s.

 
coefficient_line1 = fgetl(f);

 
pos_e = strfind(coefficient_line1,'E');

 
a1 = str2num(coefficient_line1(1:pos_e(1)+3)); %#ok
a2 = str2num(coefficient_line1((pos_e(1)+4):(pos_e(2)+3))); %#ok
a3 = str2num(coefficient_line1((pos_e(2)+4):(pos_e(3)+3))); %#ok
a4 = str2num(coefficient_line1((pos_e(3)+4):(pos_e(4)+3))); %#ok
a5 = str2num(coefficient_line1((pos_e(4)+4):(pos_e(5)+3))); %#ok

 

 
coefficient_line2 = fgetl(f);
pos_e1 = strfind(coefficient_line2,'E');

 
a6 = str2num(coefficient_line2(1:pos_e1(1)+3)); %#ok
a7 = str2num(coefficient_line2((pos_e1(1)+4):(pos_e1(2)+3))); %#ok
a8 = str2num(coefficient_line2((pos_e1(2)+4):(pos_e1(3)+3))); %#ok
a9 = str2num(coefficient_line2((pos_e1(3)+4):(pos_e1(4)+3))); %#ok
a10 = str2num(coefficient_line2((pos_e1(4)+4):(pos_e1(5)+3))); %#ok

 

 

 
coefficient_line3 = fgetl(f);
pos_e2 = strfind(coefficient_line3,'E');

 
a11 = str2num(coefficient_line3(1:pos_e2(1)+3)); %#ok
a12 = str2num(coefficient_line3((pos_e2(1)+4):(pos_e2(2)+3))); %#ok
a13 = str2num(coefficient_line3((pos_e2(2)+4):(pos_e2(3)+3))); %#ok
a14 = str2num(coefficient_line3((pos_e2(3)+4):(pos_e2(4)+3))); %#ok

 
% form the two arrays for temperature based on the midddle value where the
% 1st array contains the temperature ranges between low to mid and the
% second arrays contains the temp from mid to high.

 
LTR = linspace(low_local_temp,mid_local_temp,100);
HTR = linspace(mid_local_temp,high_local_temp,100);

 
for i = 1:length(LTR) %#ok

 
�lculation of cp,H,S

 
cp1(i) = (a8 + a9.*LTR(i) + a10.*LTR(i).*LTR(i) + a11.*LTR(i).^3 + a12.*LTR(i).*4)*R; %#ok

 
H1(i) = (a8 + (a9.*LTR(i))/2 + (a10.*LTR(i).*LTR(i))/3 + (a11.*LTR(i).^3)/4 + (a12.*LTR(i).*4)/5 + a13*LTR(i))*LTR(i); %#ok

 
S1(i) = ((a8*log(LTR(i)) + a9.*LTR(i) + (a10.*LTR(i).*LTR(i))/2 + (a11.*LTR(i).^3)/3) + ((a12.*LTR(i).*4)/4) + a13)*R; %#ok

 
end

 
for i = 1:length(HTR) %#ok

 
cp2(i) = (a8 + a9.*HTR(i) + a10.*HTR(i).*HTR(i) + a11.*HTR(i).^3 + a12.*HTR(i).*4)*R; %#ok

 
H2(i) = (a8 + (a9.*HTR(i))/2 + (a10.*HTR(i).*HTR(i))/3 + (a11.*HTR(i).^3)/4 + (a12.*HTR(i).*4)/5 + a13*HTR(i))*HTR(i); %#ok

 
S2(i) = ((a8*log(HTR(i)) + a9.*HTR(i) + (a10.*HTR(i).*HTR(i))/2 + (a11.*HTR(i).^3)/3) + ((a12.*HTR(i).*4)/4) + a13)*R; %#ok

 
end
% make the directory where we will store all the plots of diffrent species
% inside the folder name "species name".

 
mkdir(['C:\Users\Amit\Desktop\skill lync\',species_name]);

 
T = [LTR HTR];
cp = [cp1 cp2];
H = [H1,H2];
S = [S1,S2];

 
% �lculation of molecular weight,
[molecular_wt] = mw(species_name)

 
figure(1);
plot(T,cp);
xlabel('Temperature')
ylabel('specific heat')
title('specific heat v/s temperature')

 
figure(2)
plot(T,H)
xlabel('temperature')
ylabel('enthalpy')
title('temperature v/s enthalpy')

 
figure(3)

 
plot(T,S)
xlabel('temperature')
ylabel('entropy')
title('temperature v/s entropy')

 
cd(['C:\Users\Amit\Desktop\skill lync\',species_name])
saveas(1,'cp','jpg')
saveas(2,'h','jpg')
saveas(3,'s','jpg')

 
end
function [molecular_wt] = mw(species_name)

 
elements = ['H','C','N','O','A'];
atomic_wt = [1,12,14,16,40];
molecular_wt = 0;

 
for i = 1:length(species_name)
for j = 1:length(elements)
if strcmpi(species_name(i),elements(j))
molecular_wt = molecular_wt + atomic_wt(j);
position = j;
end
end
f = str2double(species_name(i)) %#ok
if f>=1
molecular_wt = molecular_wt + atomic_wt(position)*(f-1);
end
end
sprintf('Molecular weight of %s:%f', species_name,molecular_wt)
end
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.