Challenge

Project 1 - Parsing NASA thermodynamic data

Title: Detailed report on file parsing.

Aim: Plot the Cp, Enthalpy, Entropy and calculate the molecular weight for 53 species.

Objective:

  1. Extract 14 coefficients and calculates the enthalpy, entropy and specific heat for all the species in data.
  2. Using local temperature range differentiate the high temperature coefficient and low temperature coefficient.
  3. Plot the Cp, Enthalpy and Entropy for the local temperature range for each species.
  4. Save the plots as images with appropriate names and collect them in separate folder for each species with suitable names

Procedure:

Step 1:    Generating all the 14 coefficients.

  1. Open the data file.
  2. Skipping the three lines of header information in data file.
  3. Using strsplit command splitting the line into coefficients.
  4. Using for loop define the 14 coefficients of 53 species one by one.

Step 2:    Calculating the cp, enthalpy and entropy and saving in folder.

  1. After defining coefficients calculate the values of cp, enthalpy and entropy by the given formula in challenge page.
  2. Variables which start with ‘a’ are high temperature and variables starts with ‘b’ are low temperature values.
  3. Using the command mkdir and cd make a separate file for each specie in folder.
  4. Plot the graph of temperature vs enthalpy, temperature vs entropy and temperature vs specific heat.
  5. Saving the file in folder using command saveas.

Step 3:    obtaining molecular mass of species.

  1. There is total 5 main elements in all 53 species.
  2. Which is H, C, Ar, O, and N.
  3. Make an array of the 5 species and their molecular weight.
  4. Using strcmp command compare element between these two arrays.
  5. Using sprintf command display molecular weight of all the 53 species in command window.

Conclusion:

  1. Using this challenge, I am able to read the file using code.
  2. I have learned different types of command to access data and perform different types of operations on data from file.

The code sample for given project:

% Project-1: NASA File Parsing

Clear
close all
clc
 
f1=fopen('THERMO.dat','r');
 
 
% Constant
R=8.314;
 
 
fgetl(f1);
 
tline=fgetl(f1);
tvector{1}=str2num(tline);
tvector{2}=str2num(tline);
tvector{3}=str2num(tline);
Ltemp=tvector(1);
Mtemp=tvector(2);
Htemp=tvector(3);
 
 
for i=1:3
    skip=fgetl(f1); % Skipping 3 comment lines
end
 
% Fetching Species+Calculating Cp\S\H and Molecular Weight
for i=1:53
    L0=fgetl(f1);
    y=strsplit(L0,' ');
    Specie=y{1};
    L1=fopen(f1);
    
    z=length(y);
    LT=str2num(y{z-3});
    MT=str2num(y{z-1});
    HT=str2num(y{z-2});
    T=linspace(LT,HT,100);
    L1 = fgetl(f1);
    M1=strfind(L1,'E');
    % High-temperature values
    a1=str2num(L1(1:M1(1)+3));
    a2=str2num(L1(M1(1)+4:M1(2)+3));
    a3=str2num(L1(M1(2)+4:M1(3)+3));
    a4=str2num(L1(M1(3)+4:M1(4)+3));
    a5=str2num(L1(M1(4)+4:M1(5)+3));
    L2=fgetl(f1);
    M2=strfind(L2,'E');
    a6=str2num(L2(1:M2(1)+3));
    a7=str2num(L2(M2(1)+4:M2(2)+3));
    
    % Low-temperature values
    b1=str2num(L2(M2(2)+4:M2(3)+3));
    b2=str2num(L2(M2(3)+4:M2(4)+3));
    b3=str2num(L2(M2(4)+4:M2(5)+3));
    L3=fgetl(f1);
    M3=strfind(L3,'E');
    b4=str2num(L3(1:M3(1)+3));
    b5=str2num(L3(M3(1)+4:M3(2)+3));
    b6=str2num(L3(M3(2)+4:M3(3)+3));
    b7=str2num(L3(M3(3)+4:M3(4)+3));
    
    % Calculating Cp\S\H and molecular wt. for every element/compound
   if(MT<=T)
    Cp=R*(b1+b2.*T+b3.*T.^2+b4.*T.^3+b5.*T.^4);
    H=R.*T.*(b1+b2.*T./2+b3.*T.^2./3+b4.*T.^3./4+b5.*T.^4./5+b6./T);
    S= R*(b1.*log(T)+b2.*T+b3.*T.^2./2+b4.*T.^3./3+b5.*T.^4./4+b7);
   else 
    Cp=R*(a1+a2.*T+a3.*T.^2+a4.*T.^3+a5.*T.^4);
    H=R*T.*(a1+a2.*T/2+a3.*T.^2./3+a4.*T.^3./4+a5.*T.^4./5+a6./T);
    S= R*(a1.*log(T)+a2.*T+a3.*T.^2./2+a4.*T.^3./3+a5.*T.^4./4+a7);   
    
   end
    % Plotting Results
    % Temp vs Entropy
%     mkdir(['D:\Skill lync\',Specie])
%     cd(['D:\Skill lync\',Specie])
    figure(1)
    plot(T,S,'r','Linewidth',2)
    title(['Temperature vs Entropy for: ',Specie])
    xlabel('Temperature')
    ylabel('Entropy')
    % Temp vs Enthalpy
    figure(2)
    plot(T,H,'b','Linewidth',2)
    title(['Temperature vs Enthalpy for: ',Specie])
    xlabel('Temperature')
    ylabel('Enthalpy')
    % Temp vs Specific Heat
    figure(3)
    plot(T,S,'r','Linewidth',2)
    title(['Temperature vs Specific Heat for: ',Specie])
    xlabel('Temperature')
    ylabel('Specific Heat')
    % Saving files in folder
%      saveas(1,'cp vs temp.png')
%      saveas(2,'H vs temp.png')
%      saveas(3,'S vs temp.png')
    cd ..
    M = ['H' 'C' 'N' 'A' 'O'];
    mass = [1 12 14 40 16];
    mol = 0;
    for i = 1:length(Specie)
        for j = 1:length(M)
            if strcmp(Specie(i),M(j))
                mol = mol + mass(j);
                p = j;
            end
        end
        N = str2num(Specie(i));
        if N>1
            mol = mol + mass(p)*(N-1);
        end
    end
    
    x = sprintf('Molucular mass of %s = %d',Specie,mol)
        
                
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.

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.