Challenge

Project 1 - Parsing NASA thermodynamic data

Aim:

To Write a Matlab Programme for the NASA Thermodynamic Data's extracting 14 Coefficients and these are can be evaluate the Specific heat ,enthalpy,Entropy.

Objective:

1. Extract the 14 coefficients ,calculate Specific heat,Enthalpy,Entropy for each species.

2. Calculate Molecular weight.

3.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.

Governing Equation:

R is the universal gas constant, T is the temeprature.

The 1st7 coefficients are high temperature coefficients and the 2nd 7 coefficients are low temperature coefficients.

Cp = Specific Heat

H = Enthalpy

S = Entropy

R = Gas constant

T = temeprature

The 1st7 coefficients are high temperature coefficients and the 2nd 7 coefficients are low temperature coefficients.

Description:

1. The Specific heat of a substance is the amount of energy required to raise the temperature of 1 gram of the substance by 1oC">1oC. The table below lists the specific heats of some common substances. The symbol for specific heat is cp">cp, with the p">pp subscript referring to the fact that specific heats are measured at constant pressure. The units for specific heat can either be joules per gram per degree (J/goC)">(J/goC)(J/goC) or calories per gram per degree (cal/goC)">(cal/goC)(cal/goC).

2.Entropy is Chemical and physical changes in a system may be accompanied by either an increase or a decrease in the disorder of the system, corresponding to an increase in entropy (ΔS > 0) or a decrease in entropy (ΔS < 0), respectively. As with any other state function, the change in entropy is defined as the difference between the entropies of the final and initial states: ΔS = Sf − Si.

3.Enthalpy, the sum of the internal energy and the product of the pressure and volume of a thermodynamic system. ... In symbols, the enthalpy, H, equals the sum of the internal energy, E, and the product of the pressure, P, and volume, V, of the system: H = E + PV.

Programme Explanation:

1. The Program code start with clear all ,close all,clc. That means clear all plots ,close all variabels in the workspace data,clc is close command line window.

2.Open the file with 'fopen' Read the existing file by using fgetl caommand with as a inputs of File name & Permission of read .

3. Fgetl is command used to read line next to line. so that again used and read 2nd line . By using 'strsplit' we split into individual numbers . These is an array and converted into 3 different numbers with 'str2num'. And defined as Global low,mid,high temperatures.

4.Skiped next 3 lines by using fgetl and forloop because those are commented lines.

5.Then we take the 1st specie ,again spilt into individual numbers by using 'str2double'.

6. This pattern we do for 4 lines of 1st specie. before this given input for loop to get all individual coeffients.

7.Created folder with mkdir command.

8. The temperatures and Universal gas constant taken to calculate Specific heat,Entropy ,Enthalpy.

9. The code written for Enthaply, Entropy,Specific heat. as given formula.

10. Plotted Enthaply, Entropy,Specific heat with respect to the temperature.

11. Changing the directory using 'cd' command. The figures saved .

12. The molecular weight calculation inputs are taken chemical elements , atomic weight taken accordingly. strcmp is used to compare 2 strings. And printed molecular weight by using 'sprintf' command. closed file with 'fclose'.

Programme Code:

clear all
close all
clc

f1 = fopen('THERMO.dat','r')
fgetl(f1);
A = fgetl(f1);
B = strsplit(A,' ');
global_low_temp = str2num(B{2});
global_mid_temp = str2num(B{3});
global_high_temp = str2num(B{4});

for i = 3:5
    skip_lines = fgetl(f1);
end

% Temperature & Coefficients for each Species
for i =1: 53
   
    header = fgetl(f1);
  H = strsplit(header,' ');
   
   species_name = (H{1});
          z = length(H);
          
         t1 = str2double(H{z-3});
         t2 = str2double(H{z-1});
         t3 = str2double (H{z-2});
         
        % We have 5 coeffients 
           % 2nd line     
tline_2 = fgetl(f1);
a = findstr(tline_2,'E');
a_1 = tline_2(1:a(1)+3);
a1 = str2num(a_1);
a_2 = tline_2(a(1)+4:a(2)+3);
a2 = str2num(a_2);
a_3 = tline_2(a(2)+4:a(3)+3);
a3 = str2num(a_3);
a_4 = tline_2(a(3)+4:a(4)+3);
a4 = str2num(a_4);
a_5 = tline_2(a(4)+4:a(5)+3);
a5  =str2num(a_5);


% 3rd line
tline_3 = fgetl(f1);
c = findstr(tline_3,'E');
a_6 = tline_3(1:c(1)+3);
a6= str2num(a_6);
a_7 = tline_3(c(1)+4:c(2)+3);
a7 = str2num(a_7);
a_8 = tline_3(c(2)+4:c(3)+3);
a8 = str2num(a_8);
a_9 = tline_3(c(3)+4:c(4)+3);
a9 = str2num(a_9);
a_10= tline_3(c(4)+4:c(5)+3);
a10 = str2num(a_10);

% 4th line
tline_4 = fgetl(f1);
e = findstr(tline_4,'E');
a_11 = tline_4(1:e(1)+3);
a11 = str2num(a_11);
a_12= tline_4(e(1)+4:e(2)+3);
a12 = str2num(a_12);
% Another way Direct command for remaining 2
a13 = str2double(tline_4(e(2)+4:e(3)+3));

a14 = str2double(tline_4(e(3)+4:e(4)+3));

   % creating folder
  mkdir(['C:\Users\Admin\Desktop\A2\MATLAB\File Parsing\images\',species_name])


   T = linspace(t1,t3,1000);
   R = 8.314;
  

% Specific heat ,enthalpy,entropy
     for j =1:length(T)
       
       if T(j)>t2
           
           cp = (a1+a2.*T+a3.*T.^2+a4.*T.^3+a5.*T.^4)*R;
           
          H = (a1+(a2.*T)/2+(a3.*T.^2)/3+(a4.*T.^3)/4+(a5.*T.^4)/5+(a6./T))*R.*T;
          S = a1.*log(T)+a2.*T+(a3.*T.^2)/2+(a4.*T.^3)/3+(a5.*T.^4)/4+a7;
       
       else
           % lower temp
           cp = (a8+a9.*T+a10.*T.^2+a11.*T.^3+a12.*T.^4)*R;
           H  = (a8+(a9.*T)/2+(a10.*T.^2)/3+(a11.*T.^3)/4+(a12.*T.^4)/5+(a13./T))*R.*T;

          S  = a8.*log(T)+a9.*T+(a10.*T.^2)/2+(a11.*T.^3)/3+(a12.*T.^4)/4+a14;
       end
       
     end 
     
  figure(1)
  plot(T,cp)
  grid on
  title(species_name)
  xlabel('Temperature')
  ylabel('Speicific Heat')
  
 figure(2)
 plot(T,H)
 grid on
 title(species_name)
 xlabel('Temperature')
 ylabel('Enthalpy')
 
 figure(3)
 plot(T,S)
grid on
title(species_name)
xlabel('Temperature')
ylabel('Entropy')

%changing directory & save the file
save_file = (['C:\Users\Admin\Desktop\A2\MATLAB\File Parsing\images\',species_name]);
cd(save_file)
saveas(1,'specific heat','jpg')
saveas(2,'enthalpy','jpg')
saveas(3,'entropy','jpg')


    % molecular mass calculation
        elements = ['H','C','O','N','A'];
        atomic_weight = [1.0079 12.0107 15.999 14.0067 39.948];
          mol_mass = 0;
for l = 1:length(species_name)
    for m = 1:length(atomic_weight)
        if strcmp(species_name(1),elements(m));
            mol_mass = mol_mass+atomic_weight(m);
            position = m;
        end
    end
    n = str2double(species_name(l));
    if n>1
     
       
     mol_mass = mol_mass+atomic_weight(position)*(n-1);
     
       m1 =  sprintf('Molecular Weight of %s:%fu',species_name,mol_mass)
             
    end
end

end


fclose(f1)

Screenshot: Saving plots.

Ouptput plots:

Conclusion:

Extractd the 14 Coeffients of the NASA data and found Specific heat, Enthalpy, Entropy. Files & their plots saved for each in individulal block. The molecular weight also calculated.

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.