Challenge

Project 1 - Parsing NASA thermodynamic data

clear all
close all
clc
% opening & reading the required file

file= fopen('THERMO.dat','r')

% heading
line1=fgetl(file)

% global temperature values
line2=fgetl(file)

% next three lines are comments
des_1=fgetl(file)
des_2=fgetl(file)
des_3=fgetl(file)
t=strsplit(line2);
global_low_temperature=str2num(t{2});
global_mid_temperature=str2num(t{3});
global_high_temperature=str2num(t{4});

% Species information
for i=1:53
    species=fgetl(file);
    species_name=species(1:6)

    line_1=fgetl(file);
l1=strfind(line_1,'E');
c1=str2num(line_1(1:(l1(1)+3)));
c2=str2num(line_1((l1(1)+4):(l1(2)+3)));
c3=str2num(line_1((l1(2)+4):(l1(3)+3)));
c4=str2num(line_1((l1(3)+4):(l1(4)+3)));
c5=str2num(line_1((l1(4)+4):(l1(5)+3)));

line_2=fgetl(file);
l2=strfind(line_2,'E');
c6=str2num(line_2(1:(l2(1)+3)));
c7=str2num(line_2((l2(1)+4):(l2(2)+3)));
c8=str2num(line_2((l2(2)+4):(l2(3)+3)));
c9=str2num(line_2((l2(3)+4):(l2(4)+3)));
c10=str2num(line_2((l2(4)+4):(l2(5)+3)));

line_3=fgetl(file);
l3=strfind(line_3,'E');
c11=str2num(line_3(1:(l3(1)+3)));
c12=str2num(line_3((l3(1)+4):(l3(2)+3)));
c13=str2num(line_3((l3(2)+4):(l3(3)+3)));
c14=str2num(line_3((l3(3)+4):(l3(4)+3)));

% Creating folder for each species
mkdir(['D:\File parsing NASA\Species\',species_name]);

%Temperature ranges assumed for calculation purpose
temperature=linspace(global_low_temperature,global_high_temperature,1000)
% universal gas constant
R=8.314
% Calculation of properties based uponlower & upper temperature

for j=1:length(temperature)
    if temperature(j)<3000
        cp=(c1+c2.*temperature+c3.*temperature.^2+c4.*temperature.^3+c5.*temperature.^4).*R;
       H= (c1+(c2.*temperature)/2+(c3.*temperature.^2)/3+(c4.*temperature.^3)/4+(c5.*temperature.^4/5)+c6./temperature).*temperature.*R;
       S= (c1*log(temperature)+c2.*temperature+(c3.*temperature.^2)/2+(c4.*temperature.^3)/3+(c5.*temperature.^4)/4+c7).*R;
    else
        cp=(c8+c9.*temperature+c10.*temperature.^2+c11.*temperature.^3+c12.*temperature.^4).*R;
       H= (c8+(c9.*temperature)/2+(c10.*temperature.^2)/3+(c11.*temperature.^3)/4+(c12.*temperature.^4/5)+c13./temperature).*temperature.*R;
       S= (c8.*log(temperature)+c9.*temperature+(c10.*temperature.^2)/2+(c11.*temperature.^3)/3+(c12.*temperature.^4)/4+c14).*R;
    end
end

% plotting
% temperature vs entropy
figure(1)
plot(temperature,S,'linewidth',4,'color','b')
title(species_name)
xlabel('Temperature')
ylabel('Entropy')

% plotting
% temperature vs enthalpy
figure(2)
plot(temperature,H,'linewidth',4,'color','k')
title(species_name)
xlabel('Temperature')
ylabel('Enthalpy')

% plotting
% temperature vs specific heat
figure(3)
plot(temperature,cp,'linewidth',4,'color','y')
title(species_name)
xlabel('Temperature')
ylabel('specific heat')

directory= (['D:\File parsing NASA\Species\',species_name]);
cd(directory)

% savings the plot
saveas(1,'Entropy.jpg');
saveas(2,'Enthalpy.jpg');
saveas(3,'specific heat.jpg');
cd('D:\File parsing NASA\')
MM=molecular_mass(species_name)
end
fclose(file)

function MM=molecular_mass(species_name)
species = upper(species_name);
Constituents = ['H','C','N','O','A'];
Atomic_weight = [1.00794 12.0107 14.0067 15.9994 39.948]
MM=0;
for i=1:length(species)
    j=1:length(Constituents)
    if strcmp(species(i),Constituents(j))
        MM=MM+Atomic_weight(j);
        u=j;

    end
end
n=str2num(species(i));
if n>1
    MM = MM+Atomic_weight(u)*(n-1);
end
end

1. Location of species folder in desktop

2- Plots for O2

3- Plots for N2

4- Plot for CO2

Explanation for code

1. Initially open the given thermodynamic data file & read the data in file & store the data to the variable D.

2. Then read the header file of thermodynamic data and calculate the global low, mid & high temperatures.

3. By using fgetl(),strsplit(), and str2num() command find out the global low, mid & high temperatures.

4. Then calculate the 14 coefficients for all the species in the given thermodynamic data file.

5. In data file each species has three lines in which 14 coefficients are there.

6. By using the for loop , calculate the 14 coefficients for all the species.

7. By using strfind() command , findout the no. of exponential in the first line, by which can findout the no. of coefficient in the first line.

8. Then convert the coefficient to sting by using str2num() command.

9.Then calculate entropy, enthalpy & specific heat

10. Assuming R=8.314 j/mol-k and assumin temp range from 100 to 5000 take 100 values by linspace command

11. plot the graph between temp vs entropy, temp vs enthalpy & temp vs specific heat.

12. store all the three plots for all the species in file

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.