Challenge

Project 1 - Parsing NASA thermodynamic data

OBJECTIVE:-

  1. Reading "NASA thermodynamic data" file and write a function that extracts the 14 coefficients and calculates the enthalpy, entropy and specific heats for all the species.
  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.
  4. Save the plots as images with appropriate names and dump them in separate folders for each species.

THEORY:-

Where,

R is the universal gas constant(R = 8.314 J/mol. K)

T is the temeprature(Local Temperatures)

MATLAB_CODE:-

clear all
close all
clc

R =  8.314%J / mol. K
%To ready the THERMO.dat file
f1 = fopen('THERMO.dat','r');
fgetl(f1)
tempL = str2num(fgetl(f1));
% global_low_temperature = tempL(1)
% global_mid_temperature = tempL(2)
% global_high_temperature = tempL(3)
%for skipping the unwanted lines
for i = 1:3
    fgetl(f1);
end

for y=1:53

%for reading local temperatures   
tline0 = fgetl(f1);

a = findstr(tline0,'.');
tlin0=strtok(tline0)
lt1 = tline0(52-3:a(1)+3);
lt2 = tline0(a(1)+4:62+3);
lt3 = tline0(a(2)+4:72+3);
Local_Temp_low = str2num(lt1)
Local_Temp_high = str2num(lt2)
Local_Temp_mid = str2num(lt3)

%To read the lines for coefficient
%Reading the first line of Coefficient

tline1 = fgetl(f1);
b = findstr(tline1,'E');
a1 = str2num(tline1(1:b(1)+3))
a2 = str2num(tline1(b(1)+4:b(2)+3))
a3 = str2num(tline1(b(2)+4:b(3)+3))
a4 = str2num(tline1(b(3)+4:b(4)+3))
a5 = str2num(tline1(b(4)+4:b(5)+3))

%reading the second line of coefficient
tline2 = fgetl(f1);
c = findstr(tline2,'E');
a6 = str2num(tline2(1:c(1)+3))
a7 = str2num(tline2(c(1)+4:c(2)+3))
a8 = str2num(tline2(c(2)+4:c(3)+3))
a9 = str2num(tline2(c(3)+4:c(4)+3))
a10 = str2num(tline2(c(4)+4:c(5)+3))

%Reading the third line of coefficient
tline3 = fgetl(f1);
d = findstr(tline3,'E');
a11 = str2num(tline3(1:d(1)+3))
a12 = str2num(tline3(d(1)+4:d(2)+3))
a13 = str2num(tline3(d(2)+4:d(3)+3))
a14 = str2num(tline3(d(3)+4:d(4)+3))

Lower_Temp = linspace(Local_Temp_low,Local_Temp_mid,100);
Higher_Temp = linspace(Local_Temp_mid,Local_Temp_high,100);
%Cp of the given data
Cp_High = (a1 + a2*Higher_Temp + a3*Higher_Temp.^2 + a4*Higher_Temp.^3 + a5*Higher_Temp.^4 + a6*Higher_Temp.^5 + a7*Higher_Temp.^6 )*R
Cp_Low = (a8 + a9*Lower_Temp + a10*Lower_Temp.^2 + a11*Lower_Temp.^3 + a12*Lower_Temp.^4 + a13*Lower_Temp.^5 + a14*Lower_Temp.^6)*R
%Enthalphy of the given data
H_High = (a1 + a2 * (Higher_Temp/2) + a3 * ((Higher_Temp).^2)/3 + a4 * ((Higher_Temp).^3)/4 + a5 * ((Higher_Temp).^4)/5 + a6 * ((Higher_Temp).^5)/6 + a7 * ((Higher_Temp).^6)/7)*R.*Higher_Temp
H_Low = (a8 + a9 * (Lower_Temp/2) + a10 * ((Lower_Temp).^2)/3 + a11 * ((Lower_Temp).^3)/4 + a12 * ((Lower_Temp).^4)/5 + a13 * ((Lower_Temp).^5)/6 + a14 * ((Lower_Temp).^6)/7)*R.*Lower_Temp
%Entrophy Calculation for the given data
S_High = (a1*log(Higher_Temp) + a2*Higher_Temp + (a3*Higher_Temp)/2 + (a4*Higher_Temp)/3 + (a5*Higher_Temp)/4 + a7)*R
S_Low = (a8*log(Lower_Temp) + a9*Lower_Temp + (a10*Lower_Temp)/2 + (a11*Lower_Temp)/3 + (a12*Lower_Temp)/4 + a14)*R

Molecular_Weight(y) = molecular_weight(tlin0) ;
mkdir(['D:',tlin0])
cd(['D:',tlin0])
figure(1)
plot(Lower_Temp,Cp_Low,'linewidth',3)
hold on
plot(Higher_Temp,Cp_High,'linewidth',3)
hold off
saveas(gcf,'file1.png')

figure(2)
plot(Lower_Temp,H_Low,'linewidth',3)
hold on
plot(Higher_Temp,H_High,'linewidth',3)
hold off
saveas(gcf,'file2.png')

figure(3)
plot(Lower_Temp,S_Low,'linewidth',3)
hold on
plot(Higher_Temp,S_High,'linewidth',3)
hold off
saveas(gcf,'file3.png')
cd .. 
end
%CODE FOR MOLECULAR WEIGHT:-

function MW = molecular_weight(tline0)

elements = ['H','C','N','A','S']
atomic_wt = [1.00 12.01 15.99 14.00 39.95 32.06];

MW = 0;
for i = 1:length(tline0);
    for j = 1:length(elements);
        if strcmp(tline0(i),elements(j))
            
            MW = MW + atomic_wt(j);
            a = j;
        end
    end
    n = str2num(tline0(i));
    
    if n>1
        MW = MW + atomic_wt(a)*(n-1);
    end
end 
end

OUTPUT:-

GRAPHS:-

For CO2:-

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.

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.