Project

FILE PARSING OF NASA THERMODYNAMIC DATA USING MATLAB

OBJECTIVE

To extract the coefficients of different compounds and calculate the specific heat capacity, enthalpy, entropy of all the compounds and plot their values against the temperature range.

CODE

close all
clc

% opening the data file
f = fopen(\'THERMO.dat\',\'r\');
header = fgetl(f);

% extracting the global temperatures
x = fscanf(f,\'%f \\n\',[1 3]);
 T1 = x(1,1);
 T2 = x(1,2);
 T3 = x(1,3);

% leaving out the comment lines
c1 = fgetl(f);
c2 = fgetl(f);
c3 = fgetl(f);

for i = 1:53
    
 % name of the species
 species_line = fgetl(f);
 species = strtok(species_line);
 
 % extracting the coefficients
 
 l1 = fgetl(f);
 q = strfind(l1,\'E\');
 a1 = str2double(l1(1:(q(1)+3)));
 a2 = str2double(l1((q(1)+4):(q(2)+3)));
 a3 = str2double(l1((q(2)+4):(q(3)+3)));
 a4 = str2double(l1((q(3)+4):(q(4)+3)));
 a5 = str2double(l1((q(4)+4):(q(5)+3)));
 
 l2 = fgetl(f);
 p = strfind(l2,\'E\');
 a6 = str2double(l2(1:(p(1)+3)));
 a7 = str2double(l2((p(1)+4):(p(2)+3)));
 a8 = str2double(l2((p(2)+4):(p(3)+3)));
 a9 = str2double(l2((p(3)+4):(p(4)+3)));
 a10 = str2double(l2((p(4)+4):(p(5)+3)));
 
 
 l3 = fgetl(f);
 r = strfind(l3,\'E\');
 a11 = str2double(l3(1:(r(1)+3)));
 a12 = str2double(l3((r(1)+4):(r(2)+3)));
 a13 = str2double(l3((r(2)+4):(r(3)+3)));
 a14 = str2double(l3((r(3)+4):(r(4)+3)));

 % creating new folders 
 mkdir(\'E:/matlab skill lync/parsing data/species_data\',species)
 t = linspace(T1,T3,400);
 R = 8.314;
 [cp,H,S] = thermo_data(R,T2,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,t);
 
 figure(1)
 plot(t,cp,\'linewidth\',3,\'color\',\'r\')
 grid on
 title(species)
 xlabel(\'TEMPERATURE\')
 ylabel(\'SPECIFIC HEAT\')
 
 figure(2)
 plot(t,H,\'linewidth\',3,\'color\',\'g\')
 grid on
 title(species)
 xlabel(\'TEMPERATURE\')
 ylabel(\'ENTHALPY\')
 
 figure(3)
 plot(t,S,\'linewidth\',3,\'color\',\'b\')
 grid on
 title(species)
 xlabel(\'TEMPERATURE\')
 ylabel(\'ENTROPY\')
 
  molecular_mass = molecular_weight(species);
 
 saving = ([\'E:/matlab skill lync/parsing data/species_data/\',species]);
 cd(saving)
 saveas(1,\'SPECIFIC HEAT\',\'jpg\')
 saveas(2,\'ENTHALPY\',\'jpg\')
 saveas(3,\'ENTROPY\',\'jpg\')

 f2 = fopen(\'molecular_mass.txt\',\'w\');
 fprintf(f2,\'%s \\n %s %f amu\\n\',species,\'molecular-mass\',molecular_mass);
 fclose(f2);
 
 cd(\'E:/matlab skill lync/parsing data/\')

end

First the data sheet is opened by fopen command.

fgetl command is used to read the line in the data sheet one by one

The temperature range values are extracted and the unwanted lines are avoided.

For all the 53 compounds the process is repeated by using a for loop.

By using strtok , strfind, str2double the species name and corresponding species coefficients are extracted and stored.

A seperate funciton thermo_data is called with specific inputs to calculate the cp, H, S values.

For the temperature range an array of values is created between the maximum and minimum temperature values and stored in the array named \'t\'.

CODE FOR THERMO_Data

 function[cp,H,S] = thermo_data(R,T2,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,t)
 
cp = zeros(size(t));
H = zeros(size(t)); 
S = zeros(size(t));

 for i = 1:length(t)
    if t(i)>T2
        cp(i) = R*((a1) + (a2*t(i)) + (a3*t(i)^2) + (a4*t(i)^3) + (a5*t(i)^4));
        H(i)  = R*t(i)*((a1) + (a2*t(i))/2 + (a3*t(i)^2)/3 + (a4*t(i)^3)/4 + (a5*t(i)^4)/5 + + (a6/t(i)));
        S(i)  = ((a1*log(t(i))) + (a2*t(i)) + (a3*t(i)^2)/2 + (a4*t(i)^3)/3 + (a5*t(i)^4)/4 + (a7))*R;
    else
        cp(i) = R*((a8) + (a9*t(i)) + (a10*t(i)^2) + (a11*t(i)^3) + (a12*t(i)^4));
        H(i)  = ((a8) + (a9*t(i))/2 + (a10*t(i)^2)/3 + (a11*t(i)^3)/4 + (a12*t(i)^4)/5 + + (a13/t(i)))*R*t(i);
        S(i)  = ((a8*log(t(i))) + (a9*t(i)) + (a10*t(i)^2)/2 + (a11*t(i)^3)/3 + (a12*t(i)^4)/4 + (a14))*R;
    end
 end
end

The temperature value from the \'t\' array is used one by one in a for loop and the cp, H, S value at each temperature is calculated based on the given conditions.

These data are then used to plot the graphs

cp vs temperature.

H vs temperature.

S vs temperature.

mkdir command is used to create the new folders based on species name and the \'cd\' and \'saveas\' commands are used to store the appropriate figures of the plot in those folders.

molecular mass is calculated by a seperate function and stored in a new file.

CODE FOR MOLECULAR MASS

function[m] = molecular_weight(species_name)
elements = [\'H\',\'C\',\'N\',\'O\',\'A\'];
atomic_masses = [1,12,14,16,40];

m = 0;
 for i = 1:length(species_name)
     for j = 1:length(elements)
         if strcmp(species_name(i),elements(j))
            m = m + atomic_masses(j);
            x = j;
         end
     end
     n = str2double(species_name(i));
     if n>1
     m = m + (atomic_masses(x)*(n-1));
     end
end
end

At the end 53 folders are created with respective species name and all the plots and molecular mass value is stored in it.

Plots for the O2 , N2 and CO2 species are shown below.

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.