Challenge

Project 1 - Parsing NASA thermodynamic data

Aim :- Write a code in matlab for Nasa thermodynamic data file and then get the plots and values for the molecular weight of gas species.

Objective :-

  • Write a function that extracts the 14 coefficients and calculates the enthalpy,entropy and specific heat for all the species in data file.
  • Calculate the molecular weight of each species and display it in the command window.
  • Plot the Cp,Enthapy,Emtropy for the local temperature range(low temperature :: high temperature) specific for each species.
  • Save the plots as images with appropriate names and dump them in separate folders for each species with a suitable name.All these should be generated automatically.
  • The main program that you will submit will just take the "THERMO (3).dat " file as an input and generate Cp,,h and s plots.
  • Screenshot of the window where all the folders are saved.
  • Plots for O2,N2 and CO2 species.

Theory :-

Here R is the Universal gas constant (8.314),T is the temperature.

Specific Heat:-

Cp/R = a1 + a2 T + a3 T^2 + a4 T^3 + a5 T^4

It is the amount of energy that must be added in the form of heat to one unit of mass of the substance in order to cause an increase of one unit in its temperature.

Enthalpy :-

H/RT = a1 + a2 T/2 + a3 T^2 /3 + a4 T^3/4 + a5 T^4/5 + a6/T

A property of a thermodynamic system is equal to the system internal energy plus the product of its pressure and volume.it reflects the capacity to do non mechanical work and the capacity to release heat.

Entropy:-

S/R = a1 lnt + a2 T + a3 T^2 /2 + a4 T^3 /3 + a5 T^4 /4 + a7

The measure of a system thermal energy per unit temperature that is unavilable for doing useful work .Because work is obtained from ordered molecular motion .In a system contained so as to prevent the mass transfer for processes at constant pressure the heat absorbed or released equals the change in Enthapy.

Main Program:-

clear all 
close all
clc

%Getting data file 
f = fopen('THERMO (3).dat','r');
fgetl(f);

%Reading header 
tline = fgetl(f);
A = str2num(tline);
global_low_temp = A(:,1);
global_med_temp = A(:,2);
global_high_temp = A(:,3);

%skip comment lines
for i=1:3
    fgetl(f)
end

%Reading species data 
for i = 1:53
    line1 = fgetl(f);
    l = strsplit(line1);
    m = length (l);
    sp = l(1);
    species = char(sp);
    

    low_temp = str2double(l(m-3));
    mid_temp = str2double(l(m-2));
    high_temp = str2double(l(m-1));

    % storing the valve of 2nd line 
    line2 = fgetl(f);
    a = strfind(line2,'E');
    a1 = str2double(line2(1:(a+3)));
    a2 = str2double(line2((a(1)+4):(a(2)+3)));
    a3 = str2double(line2((a(2)+4):(a(3)+3)));
    a4 = str2double(line2((a(3)+4):(a(4)+3)));
    a5 = str2double(line2((a(4)+4):(a(5)+3)));

    % storing the value of 3rd line 
    line3 = fgetl(f);
    b = strfind(line3,'E');
    a6 = str2double(line3(1:(b(1)+3)));
    a7 = str2double(line3((b(1)+4):(a(2)+3)));
    a8 = str2double(line3((b(2)+4):(a(3)+3)));
    a9 = str2double(line3((b(3)+4):(a(4)+3)));
    a10 = str2double(line3((b(4)+4):(a(5)+3)));

     % storing the value of 4th line 
    line4 = fgetl(f);
    c = strfind(line3,'E');
    a11 = str2double(line4(1:(c(1)+3)));
    a12= str2double(line4((c(1)+4):(a(2)+3)));
    a13 = str2double(line4((c(2)+4):(a(3)+3)));
    a14 = str2double(line4((c(3)+4):(a(4)+3)));

    T = linspace(low_temp,high_temp,500);

    

    %universal gas constant
    R = 8.314;

    % Function for Specific heat,Enthalpy and Entropy for lower and higher temperature
 if T<=mid_temp
    
        %for lower temperature 
        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;
        s=(a8*log(T)+a9*T+a10*(T.^2)/2+a11*(T.^3)/3+a12*(T.^4)/4+a13)*R;
 else 
        %for higher temperature 
        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).*T*R;
        s=(a8*log(T)+a9*T+a10*(T.^2)/2+a11*(T.^3)/3+a12*(T.^4)/4+a13*T.^5/5)*R;
 end
    

    % Creating folder 
    nasa_file = species;
    mkdir(nasa_file);
    current = pwd;
    cd(nasa_file);
   

    % Creating figure of specific heat :
  
    figure(1)
    plot(T,cp,'linewidth',2,'Color','r');
    title(['Temperature Vs specific heat,species']);
    xlabel('temperature');
    ylabel('specific heat');
    legend ('Temperature','Specific heat');

    % saving .png file of figure
    fig = sprintf('specific heat of %s.png',species);
    saveas (gca,fig);


    % creating figure of enthalphy
  
    figure(2)
    plot(T,h,'linewidth',2,'Color','r');
    
    title(['Temperature Vs Enthalphy,species']);
    xlabel('temperature');
    ylabel('Enthalphy');
    legend ('Temperature','Enthalphy');

    % saving .png file of figure
    fig = sprintf('Enthalphy of %s.png',species);
    saveas (gca,fig);

    % creating figure of Entrophy
  
    figure(3)
    plot(T,s,'linewidth',2,'Color','r');
   
    title(['Temperature Vs Entrophy,species']);
    xlabel('temperature');
    ylabel('Entrophy');
    legend ('Temperture','Entrophy');

    %saving .png file of figure
    fig = sprintf('Entrophy of %s.png',species);
    saveas (gca,fig);

    cd ..

    % creating figure of molecular weight 
    atom = ['H','C','O','N','A','S'];
    atomic_weight = [1.008 12.011 15.999 14.007 39.948 32.065];
    mw = 0;
    
    for p = 1:length(species)
    for q = 1:length(atomic_weight)
        if strcmp(species(p),atom(q))
mw = mw + atomic_weight(q);
position = q;
        end 
    end

    % Used for multiplication into the number of atom
    n = str2double(species(p));
    if n > 1
        mw = mw + atomic_weight(position)*(n-2);
    end 
    end

    % display molecular weight 

    fprintf('molecular weight of %s : %f\n ',species,mw);
   
end

~ 53 Elements :-

Temperature vs Specific heat , O2

Temperature Vs Entropy , O2

Temperature Vs Enthalpy ,O2

Temperature Vs Specific Heat , N2

Temperature Vs Entropy , N2

Temperature Vs Enthalpy , N2

Temperature Vs Specific heat , CO2

Temperature Vs Entropy , CO2

Temperature Vs Enthalpy , CO2

Molecular Weight of some elements :-

molecular weight of O : 15.999000

molecular weight of H : 1.008000

molecular weight of OH : 17.007000

molecular weight of C : 12.011000

molecular weight of CH : 13.019000

molecular weight of CH2(S) : 45.084000

molecular weight of CH3 : 14.027000

molecular weight of CH4 : 15.035000

molecular weight of CO : 28.010000

molecular weight of HCO : 29.018000

molecular weight of CH2OH : 30.026000

molecular weight of CH3OH : 31.034000

molecular weight of C2H : 13.019000

molecular weight of C2H3 : 14.027000

molecular weight of C2H4 : 15.035000

molecular weight of C2H5 : 16.043000

molecular weight of C2H6 : 17.051000

molecular weight of CH2CO : 41.029000

molecular weight of HCCOH : 42.037000

molecular weight of H2CN : 27.026000

molecular weight of HNO : 31.014000

molecular weight of N : 14.007000

molecular weight of NNH : 29.022000

molecular weight of N2O : 30.006000

molecular weight of NH : 15.015000

molecular weight of NH3 : 16.023000

molecular weight of NO : 30.006000

molecular weight of HCNO : 43.025000

molecular weight of NCO : 42.017000

molecular weight of CN : 26.018000

molecular weight of HCNN : 41.033000

molecular weight of N2 : 14.007000

molecular weight of AR : 39.948000

molecular weight of C3H8 : 31.078000

molecular weight of C3H7 : 30.070000

molecular weight of CH3CHO : 43.045000

molecular weight of CH2CHO : 42.037000

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.