Challenge

Project 1 - Parsing NASA thermodynamic data

Main Coding -Thermodynamic file parsing of NASA:

I have read the thermo.dat file.In that first 5 lines contain globle temp. details so I have skipped those lines and also i have skipped last line which contains the word end. Then i got actual data of 212 lines, in which each species contains the four lines data,So I get the total number of species is 53.

I have assumed following variables for below coding

Cp= Specific heat

H=Enthalpy

S=Entropy

Temp = Temperature

R= Universal gas constant.

clear all
close all
clc

%opening and reading the Thermo.dat file
file = fopen ('THERMO.dat','r');
%removing first 5 line i.e. headings
for i = 1:5
    f=fgetl(file);
end

%extracting the species and 14 coefficient values

for j=1:53
% heading of file 
    species=fgetl(file);
    A=strsplit(species,' ');
    species_name=A{1};

    local_low_temp=str2double(A(end-3));
    local_high_temp=str2double(A(end-2));
    local_mid_temp=str2double(A(end-1));

    %extract coefficent 
    %Line1
    line1=fgetl(file);
    %Find Position of E in the first line using variable e1
    e1=strfind(line1,'E');
    %Find 14 coefficients of each specifies
    a1=str2double(line1(1:e1(1)+3));
    a2=str2double(line1(e1(1)+4:e1(2)+3));
    a3=str2double(line1(e1(2)+4:e1(3)+3));
    a4=str2double(line1(e1(3)+4:e1(4)+3));
    a5=str2double(line1(e1(4)+4:e1(5)+3));
    %Line 2
    line2=fgetl(file);
    %Find Position of E in the second line using variable e2
    e2=strfind(line2,'E');
    a6=str2double(line2(1:e2(1)+3));
    a7=str2double(line2(e2(1)+4:e2(2)+3));
    a8=str2double(line2(e2(2)+4:e2(3)+3));
    a9=str2double(line2(e2(3)+4:e2(4)+3));
    a10=str2double(line2(e2(4)+4:e2(5)+3));
    %Line 2
    line3=fgetl(file);
    %Find Position of E in the second line using variable e2
    e3=strfind(line3,'E');
    a11=str2double(line3(1:e3(1)+3));
    a12=str2double(line3(e3(1)+4:e3(2)+3));
    a13=str2double(line3(e3(2)+4:e3(3)+3));
    a14=str2double(line3(e3(3)+4:e3(4)+3));
    %creating folder for each species 
    %mkdir('C:/Users/jagda/OneDrive/Desktop/fileParsing/species/',species_name); 

    %Universal gas constant R = (8.3144598(48) J.mol−1⋅K−1);
    R = (8.314);
    %LOCAL TEMPERATURE RANGES which is unique assumed for calculation purpose
    temp = linspace(local_low_temp,local_high_temp,100);

	%Plots for o2, N2 and Co2 species.
    req_species=["O2","N2","CO2"];
    if(species_name==req_species(1))||(species_name==req_species(2))||(species_name==req_species(3))
        %specific heat fuction coading
         C_p =R*specific_heat_calc(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,temp);
         %entholpy function coading 
         H= R*entholpy_calc(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,local_mid_temp,temp);
         %entropy fuction coading
         S= R*entropy_calc(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,temp);
         mkdir(species_name);
         cd(species_name);
            %Plot Specific heat vs Temperature 
                figure(1)
                plot(temp,C_p)
                title('Specific heat vs Temperature')
                xlabel('Temperature')
                ylabel('Specific heat')
                %image=getframe(gcf);
                %imwrite(image.cdata,'C-p vs temp.png')
                saveas(1,'Specific_heat','jpg')
                %Plot Specific heat vs Temperature                 
                figure(2)
                plot(temp,H)
                title('Entholpy vs Temperature')
                xlabel('Temperature')
                ylabel('Entholpy')
                %image=getframe(gcf);
                %imwrite(image.cdata,'entholpy vs temp.png')
                saveas(2,'Entholpy','jpg')
                %Plot Specific heat vs Temperature 
                figure(3)
                plot(temp,S)
                title('entropy vs Temperature')
                xlabel('Temperature')
                ylabel('Entropy')
                %image=getframe(gcf);
                %imwrite(image.cdata,'entropy vs temp.png');
               saveas(3,'Entropy','jpg')
   
    cd ..
    end
    
    MW1=molecular_weight(species_name);        
    MWeight=sprintf('Molecular weight of %s is %f',species_name,MW1);
    disp(MWeight);
end
fclose(file);

Function coding of Specific heat:

function [C_p]=specific_heat_calc(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,temp)
     if (temp>local_mid_temp)   
    C_p = (a1+(a2*temp)+(a3*(temp.^2))+(a4*(temp.^3))+(a5*(temp.^4)));
     else   
    C_p = (a8+(a9*temp)+(a10*(temp.^2))+(a11*(temp.^3))+(a12*(temp.^4)));   
     end
end

Function coding of Entholpy:

 function [H]=entholpy_calc(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,local_mid_temp,temp)
     if (temp>local_mid_temp)
         H =(a1+(a2*temp)/2)+(a3*(temp.^2)/3)+(a4*(temp.^3)/4)+(a5*(temp.^4)/5+a7);
     else
         H =(a8+(a9*temp)/2)+(a10*(temp.^2)/3)+(a11*(temp.^3)/4)+(a12*(temp.^4)/5+a14);
     end
 end

Function coding of Entropy:

 %entropy function coading
function[S]=entropy_calc(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,local_low_temp,local_mid_temp,local_high_temp,temp)
 if (temp>local_mid_temp)
     S=(a1*log(temp))+(a2*temp)+(a3*(temp.^2)/2)+(a4*(temp.^3)/3)+(a5*(temp.^4)/4+a7);
 else
     S=(a8*log(temp))+(a9*temp)+(a10*(temp.^2)/2)+(a11*(temp.^3)/3)+(a12*(temp.^4)/4+a14);
 end
end

Function coding of molecular weight:

function [MW]=molecular_weight(species_names)
    atomic_names = ['H','C','O','N','Ar'];
    atomic_weights = [1.007784, 12.0107, 15.999, 14.0067, 39.948];
    W=0;
        for i=1:length(species_names)
            for j=i:length(atomic_names)
                if species_names(i)==atomic_names(j)
                    W=W+atomic_weights(j);
                    position=j;
                end
            end
            n=str2double(species_names(i));
            if n>=1
                W=W+atomic_weights(position)*(n-1);
            end
        end
        MW=W;
end

Screenshot of the window where all the folders are saved:

Plots for O2 species:

Plots for N2 species:

Plots for CO2 species :

The molecular weight of each species and displayed it in the command window:

Molecular weight of O is 15.999000

Molecular weight of O2 is 31.998000

Molecular weight of H is 1.007784

Molecular weight of H2 is 2.015568

Molecular weight of OH is 15.999000

Molecular weight of H2O is 18.014568

Molecular weight of HO2 is 33.005784

Molecular weight of H2O2 is 34.013568

Molecular weight of C is 12.010700

Molecular weight of CH is 12.010700

Molecular weight of CH2 is 24.021400

Molecular weight of CH2(S) is 24.021400

Molecular weight of CH3 is 36.032100

Molecular weight of CH4 is 48.042800

Molecular weight of CO is 28.009700

Molecular weight of CO2 is 44.008700

Molecular weight of HCO is 29.017484

Molecular weight of CH2O is 24.021400

Molecular weight of CH2OH is 24.021400

Molecular weight of CH3O is 36.032100

Molecular weight of CH3OH is 36.032100

Molecular weight of C2H is 24.021400

Molecular weight of C2H2 is 36.032100

Molecular weight of C2H3 is 48.042800

Molecular weight of C2H4 is 60.053500

Molecular weight of C2H5 is 72.064200

Molecular weight of C2H6 is 84.074900

Molecular weight of CH2CO is 24.021400

Molecular weight of HCCO is 13.018484

Molecular weight of HCCOH is 13.018484

Molecular weight of H2CN is 16.022268

Molecular weight of HCN is 27.025184

Molecular weight of HNO is 31.013484

Molecular weight of N is 14.006700

Molecular weight of NNH is 28.013400

Molecular weight of N2O is 44.012400

Molecular weight of NH is 14.006700

Molecular weight of NH2 is 28.013400

Molecular weight of NH3 is 42.020100

Molecular weight of NO is 30.005700

Molecular weight of NO2 is 46.004700

Molecular weight of HCNO is 27.025184

Molecular weight of HOCN is 31.013484

Molecular weight of HNCO is 15.014484

Molecular weight of NCO is 42.016400

Molecular weight of CN is 26.017400

Molecular weight of HCNN is 41.031884

Molecular weight of N2 is 28.013400

Molecular weight of AR is 39.948000

Molecular weight of C3H8 is 120.107000

Molecular weight of C3H7 is 108.096300

Molecular weight of CH3CHO is 36.032100

Molecular weight of CH2CHO is 24.021400

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.