Challenge

Project 1 - Parsing NASA thermodynamic data

OBJECTICE:

To parse the themodynamic data file and to calculate the themodynamic properties of gas species present in the file.

AIM:

14 co-efficients and calculates the enthalpy, entropy and specific heats for all the species and Calculating the molecular weight of each species in the data file by use of NASA thermodynamic data file and below formulae.

PROCEDURE:

  • To open 'THERMO.dat' we are using 'fopen' and 'fgetl'.
  • For reading the header information in 'THERMO.dat' we are using strsplit it is used to find the all position of global local temperatur, global medium temperatur, global high temperatur.
  • And then reading the species by using for loop and getting first, second, third line of coeffecients by use of fgetl.
  • And then creating folder for species to save by use of mkdir saving same as species name.
  • comparing the species temperature to assign the coeffeceints as high temperatur and low temperature.
  • Then next calling of functions to calculate the thermal properties and molecular weight.
  • Plotting the results specific heat, enthalpy, and entropy temperature and it is stored in a specific folder created before.

CODE:

clear all
close all
clc

%getting the data file
f1=fopen('THERMO.dat','r');
fgetl(f1)
%reading the header information
A=fgetl(f1);
B=strsplit(A,' ');
global_low_temp=str2double(B{2});
global_mid_temp=str2double(B{3});
global_high_temp=str2double(B{4});

%skipping next three lines
for i=1:3
    fgetl(f1);
end

%reading the species
for i=1:53
    
    header=fgetl(f1);
    x=strsplit(header,' ');
    
    species_name=(x{1});
    z=length(x);
    
    local_low_temp=str2double(x{z-3});
        local_high_temp=str2double(x{z-2});
            local_mid_temp=str2double(x{z-1});
            
            t1=local_low_temp;
            t2=local_mid_temp;
            t3=local_high_temp;
            
            %getting first line coeffecients (a1-a5)
            line_1=fgetl(f1);
            
            a=strfind(line_1,'E');
            a1=str2double(line_1(1:a(1)+3));
            a2=str2double(line_1(a(1)+4:a(2)+3));
            a3=str2double(line_1(a(2)+4:a(3)+3));
            a4=str2double(line_1(a(3)+4:a(4)+3));
            a5=str2double(line_1(a(4)+4:a(5)+3));
            
            %getting second line coeffeceints (a6-a10)
             line_2=fgetl(f1);
            
            a_1=strfind(line_2,'E');
            a6=str2double(line_2(1:a_1(1)+3));
            a7=str2double(line_2(a_1(1)+4:a_1(2)+3));
            a8=str2double(line_2(a_1(2)+4:a_1(3)+3));
            a9=str2double(line_2(a_1(3)+4:a_1(4)+3));
            a10=str2double(line_2(a_1(4)+4:a_1(5)+3));
            
            %getting third line coeffeceints (a10-a14)
             line_3=fgetl(f1);
            
            a_2=strfind(line_1,'E');
            a11=str2double(line_3(1:a_2(1)+3));
            a12=str2double(line_3(a_2(1)+4:a_1(2)+3));
            a13=str2double(line_3(a_2(2)+4:a_1(3)+3));
            a14=str2double(line_3(a_2(3)+4:a_1(4)+3));
            
            
            %creating folder
            mkdir(['C:\Users\sateeshsingh\Desktop\FILE PARSING\output',species_name]);
         
            T=linspace(t1,t3,1000);
            R=8.314;
            % to get array of specific heat, enthalpy and entropy 
    for k=1:length(T)
    % to compare the species  temperature to assign the coeffeceints
    %a1-a7 (high temperature coeffeceints), a8-a14(low temperature coeffecients)    
    if T(k)>t2
        
        %high temperature coeffeceints.
        
        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
        %low temperature coeffecients
        
        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

            
            %plotting the graphs
            
            figure(1);
            plot(T,cp);
            grid on ;
            title(species_name);
            xlabel('Temperature');
            ylabel('Specific 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 the directory and saving the file
            cd=(['C:\Users\sateeshsingh\Desktop\FILE PARSING\output',species_name]);
            
            saveas(1,'specific heat','jpg');
            saveas(2,'enthalpy','jpg');
            saveas(3,'entropy','jpg');
            
            
             %molecular_masscalculation
             
             

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(l),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);
    
end
end
sprintf('Molecular Weight of %s:%f u',species_name,mol_mass)

             

end             
             fclose(f1)
            

Comparing the species with the element and calucated the molecular weight of the species

Folder with plotting are displayed:

Molecular weight for each species:

ans =

    'THERMO'


ans =

    'Molecular Weight of O:15.999000 u'


ans =

    'Molecular Weight of O2:31.998000 u'


ans =

    'Molecular Weight of H:1.007900 u'


ans =

    'Molecular Weight of H2:2.015800 u'


ans =

    'Molecular Weight of OH:17.006900 u'


ans =

    'Molecular Weight of H2O:18.014800 u'


ans =

    'Molecular Weight of HO2:33.005900 u'


ans =

    'Molecular Weight of H2O2:34.013800 u'


ans =

    'Molecular Weight of C:12.010700 u'


ans =

    'Molecular Weight of CH:13.018600 u'


ans =

    'Molecular Weight of CH2:14.026500 u'


ans =

    'Molecular Weight of CH2(S):14.026500 u'


ans =

    'Molecular Weight of CH3:15.034400 u'


ans =

    'Molecular Weight of CH4:16.042300 u'


ans =

    'Molecular Weight of CO:28.009700 u'


ans =

    'Molecular Weight of CO2:44.008700 u'


ans =

    'Molecular Weight of HCO:29.017600 u'


ans =

    'Molecular Weight of CH2O:30.025500 u'


ans =

    'Molecular Weight of CH2OH:31.033400 u'


ans =

    'Molecular Weight of CH3O:31.033400 u'


ans =

    'Molecular Weight of CH3OH:32.041300 u'


ans =

    'Molecular Weight of C2H:25.029300 u'


ans =

    'Molecular Weight of C2H2:26.037200 u'


ans =

    'Molecular Weight of C2H3:27.045100 u'


ans =

    'Molecular Weight of C2H4:28.053000 u'


ans =

    'Molecular Weight of C2H5:29.060900 u'


ans =

    'Molecular Weight of C2H6:30.068800 u'


ans =

    'Molecular Weight of CH2CO:42.036200 u'


ans =

    'Molecular Weight of HCCO:41.028300 u'


ans =

    'Molecular Weight of HCCOH:42.036200 u'


ans =

    'Molecular Weight of H2CN:28.033200 u'


ans =

    'Molecular Weight of HCN:27.025300 u'


ans =

    'Molecular Weight of HNO:31.013600 u'


ans =

    'Molecular Weight of N:14.006700 u'


ans =

    'Molecular Weight of NNH:29.021300 u'


ans =

    'Molecular Weight of N2O:44.012400 u'


ans =

    'Molecular Weight of NH:15.014600 u'


ans =

    'Molecular Weight of NH2:16.022500 u'


ans =

    'Molecular Weight of NH3:17.030400 u'


ans =

    'Molecular Weight of NO:30.005700 u'


ans =

    'Molecular Weight of NO2:46.004700 u'


ans =

    'Molecular Weight of HCNO:43.024300 u'


ans =

    'Molecular Weight of HOCN:43.024300 u'


ans =

    'Molecular Weight of HNCO:43.024300 u'


ans =

    'Molecular Weight of NCO:42.016400 u'


ans =

    'Molecular Weight of CN:26.017400 u'


ans =

    'Molecular Weight of HCNN:41.032000 u'


ans =

    'Molecular Weight of N2:28.013400 u'


ans =

    'Molecular Weight of AR:39.948000 u'


ans =

    'Molecular Weight of C3H8:44.095300 u'


ans =

    'Molecular Weight of C3H7:43.087400 u'


ans =

    'Molecular Weight of CH3CHO:44.052000 u'


ans =

    'Molecular Weight of CH2CHO:43.044100 u'


ans =

     0

>> 

Comparsion Entropy vs Temperture of CH2CHO:

Comparsion Specific Heat vs Temperture of CH2CHO:

Comparsion Enthalpy vs Temperture of CH2CHO:

RESULT:

Thus the above coding shows the Value of cp, H, and S for the each species and the plot between temperature vs specific heat, enthalpy, entropy is shown. Then the is folder generated by the coding and molecular weight also shown for the each species in the nasa thermo. dat 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.