Challenge

Project 1 - Parsing NASA thermodynamic data

Molecular Weight of the species O is 15.994000Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'O2'

Molecular Weight of the species O2 is 31.988000Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'H'

Molecular Weight of the species H is 1.007940Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'H2'

Molecular Weight of the species H2 is 2.015880Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'OH'

Molecular Weight of the species OH is 17.001940Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'H2O'

Molecular Weight of the species H2O is 18.009880Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'HO2'

Molecular Weight of the species HO2 is 32.995940Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'H2O2'

Molecular Weight of the species H2O2 is 34.003880Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'C'

Molecular Weight of the species C is 12.010700Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'CH'

Molecular Weight of the species CH is 13.018640Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'CH2'

Molecular Weight of the species CH2 is 14.026580Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'CH2(S)'

Molecular Weight of the species CH2(S) is 14.026580Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'CH3'

Molecular Weight of the species CH3 is 15.034520Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'CH4'

Molecular Weight of the species CH4 is 16.042460Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'CO'

Molecular Weight of the species CO is 28.004700Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'CO2'

Molecular Weight of the species CO2 is 43.998700Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'HCO'

Molecular Weight of the species HCO is 29.012640Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'CH2O'

Molecular Weight of the species CH2O is 30.020580Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'CH2OH'

Molecular Weight of the species CH2OH is 31.028520Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'CH3O'

Molecular Weight of the species CH3O is 31.028520Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'CH3OH'

Molecular Weight of the species CH3OH is 32.036460Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'C2H'

Molecular Weight of the species C2H is 25.029340Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'C2H2'

Molecular Weight of the species C2H2 is 26.037280Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'C2H3'

Molecular Weight of the species C2H3 is 27.045220Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'C2H4'

Molecular Weight of the species C2H4 is 28.053160Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'C2H5'

Molecular Weight of the species C2H5 is 29.061100Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'C2H6'

Molecular Weight of the species C2H6 is 30.069040Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'CH2CO'

Molecular Weight of the species CH2CO is 42.031280Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'HCCO'

Molecular Weight of the species HCCO is 41.023340Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'HCCOH'

Molecular Weight of the species HCCOH is 42.031280Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'H2CN'

Molecular Weight of the species H2CN is 28.033280Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'HCN'

Molecular Weight of the species HCN is 27.025340Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'HNO'

Molecular Weight of the species HNO is 31.008640Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'N'

Molecular Weight of the species N is 14.006700Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'NNH'

Molecular Weight of the species NNH is 29.021340Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'N2O'

Molecular Weight of the species N2O is 44.007400Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'NH'

Molecular Weight of the species NH is 15.014640Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'NH2'

Molecular Weight of the species NH2 is 16.022580Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'NH3'

Molecular Weight of the species NH3 is 17.030520Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'NO'

Molecular Weight of the species NO is 30.000700Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'NO2'

Molecular Weight of the species NO2 is 45.994700Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'HCNO'

Molecular Weight of the species HCNO is 43.019340Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'HOCN'

Molecular Weight of the species HOCN is 43.019340Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'HNCO'

Molecular Weight of the species HNCO is 43.019340Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'NCO'

Molecular Weight of the species NCO is 42.011400Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'CN'

Molecular Weight of the species CN is 26.017400Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'HCNN'

Molecular Weight of the species HCNN is 41.032040Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'N2'

Molecular Weight of the species N2 is 28.013400Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'AR'

Molecular Weight of the species AR is 39.948000Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'C3H8'

Molecular Weight of the species C3H8 is 44.095620Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'C3H7'

Molecular Weight of the species C3H7 is 43.087680Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'CH3CHO'

Molecular Weight of the species CH3CHO is 44.047160Warning: Directory already exists. 
> In THERMODAT (line 125) 

compound_name =

    'CH2CHO'

Molecular Weight of the species CH2CHO is 43.039220Warning: Directory already exists. 
> In THERMODAT (line 125) 
>> 
%File Parsing for a file
clc
clear all
close all

f1 = fopen('THERMO.DAT','r');
first_line = fgetl(f1);

%R is the universal gas constant J/(mol-K)

R = 8.314;
temp = fgetl(f1);

%Reading text from a header file
%Reading the global temperature from the next line

A = strsplit(temp,' ');

%Cell array is generated 1x4 cell array
glob_lowtemp = str2num(A{2});
glob_midtemp = str2num(A{3});
glob_hightemp =str2num(A{4});

%Temperature range
Temperature = linspace(glob_lowtemp,glob_hightemp,1000);
%skipping the three comment lines
for j =1:3;
    k =fgetl(f1);
end
%running for loop fopr 53 times as there are 53 species
for i = 1:53;

    %Parsing of the species block
        tline = fgetl(f1);
        S =strsplit(tline,' ');
        Species_name =S{1};

        %Extracting the coefficients from first line
        line2 =fgetl(f1);
        x =findstr(line2,'E');

        %Finding the 5 coefficient
        x1 = line2(1:x(1)+3);
        x1 = str2num(x1);

        x2 = line2(x(1)+4:x(2)+3);
        x2 = str2num(x2);

        x3 = line2(x(2)+4:x(3)+3);
        x3 = str2num(x3);

        x4 = line2(x(3)+4:x(4)+3);
        x4 = str2num(x4);

        x5 = line2(x(4)+4:x(5)+3);
        x5 = str2num(x5);

        %line3 5coefficients
        line3 = fgetl(f1);
        x = findstr(line3,'E');

        x6 = line3(1:x(1)+3);
        x6 = str2num(x6);

        x7 = line3(x(1)+4:x(2)+3);
        x7 = str2num(x7);

        x8 = line3(x(2)+4:x(3)+3);
        x8 = str2num(x8);

        x9 = line3(x(3)+4:x(4)+3);
        x9 = str2num(x9);

        x10 = line3(x(4)+4:x(5)+3);
        x10 = str2num(x10);

        %Line4  4coefficients

        line4=fgetl(f1);
        x = findstr(line4,'E');

        x11 = line4(1:x(1)+3);
        x11 = str2num(x11);

        x12 = line4(x(1)+4:x(2)+3);
        x12 = str2num(x12);

        x13 = line4(x(2)+4:x(3)+3);
        x13 = str2num(x13);

        x14 = line4(x(3)+4:x(4)+3);
        x14 = str2num(x14);


        % Entropy Calculation 

        S = entropy_S(x1,x2,x3,x4,x5,x7,x8,x9,x10,x11,x12,x14,Temperature,glob_midtemp,R);

        %Cp calculation means Specific Heat calculation

        
        Cp = Specific_heat(x1,x2,x3,x4,x5,x8,x9,x10,x11,x12,Temperature,glob_midtemp,R);

        %Enthlpy Calculation is H

        H = enthalpy_H(x1,x2,x3,x4,x5,x6,x8,x9,x10,x11,x12,x13,Temperature,glob_midtemp,R);

        %Molecular Weight calculation of different elements

        mw(i) = mol_wt(Species_name);

        %Reading and writinh of the molecular wieght in the list of molecular
        %wieght
        Moll_wt = fopen('Molecular Weight.txt','w');
        fprintf(Moll_wt,'Molecular Weight of the species %s is  %f ',Species_name,mw);
        fprintf(Moll_wt,'/n');
        fclose(Moll_wt);

        % Plotting on the graph for species fo the temperature and specific
        % heat

        %Creating a folder for saving the species with its properties

        directory_curr = pwd;
        mkdir(Species_name);
        cd(Species_name);

        %Plotting the graph in different plotting window 
        %plot 1 for the temperature and entropy
        %plot 2 for the temperature and enthalpy
        %plot 3 for the temperature and specific heat


        %plot 1 Enthalphy and Temperaure

        figure(1)
        plot(Temperature,H,'linewidth',3,'color','b');
        xlabel('Temperature in [K]');
        ylabel('Enthalphy [KJ/mol]');
        grid on
        title(sprintf('Variation in Enthalphy wrt Temperature %s',Species_name));

        saveas (figure(1),'Enthalhy.jpg');

         %plot 2 Entropy and Temperature

        figure(2)
        plot(Temperature,S,'linewidth',3,'color','r');
        xlabel('Temperature in [K]');
        ylabel('Entropy [KJ/mol-k]');
        grid on
        title(sprintf('Variation in Entropy wrt Temperature %s',Species_name));

        saveas (figure(2),'Entropy.jpg');

         %plot 3 Specific Heat and Temperature

        figure(3)
        plot(Temperature,Cp,'linewidth',3,'color','g');
        xlabel('Temperature in [K]');
        ylabel('Specific Heat [KJ]');
        grid on
        title(sprintf('Variation in Specific Heat wrt Temperature %s',Species_name));

        saveas (figure(3),'Specific Heat.jpg');

        cd(directory_curr);

end    


code description:
%File Parsing for a file - comments to make a program user friendly

clc - to clear the command window

clear all - to clear all the workspace variables

close all - to close all the output window

f1 = fopen('THERMO.dat','r'); - command to open a file in read mode

first_line = fgetl(f1); -  to read file line by line

%R is the universal gas constant J/(mol-K)

R = 8.314; - constant

temp = fgetl(f1); - to save the line in the temp variable

%Reading text from headerfile - comments to make a program user friendly
%Reading the global temperature from the next line

A = strsplit(temp,' '); - to split the line saved in temp variable when space(' ') is found

%Cell array is generated 1x4 cell array 

glob_lowtemp = str2num(A{2}); - assigning the global lower temperature

glob_midtemp = str2num(A{3});- assigning the global middle temperature

glob_hightemp =str2num(A{4});- assigning the global high temperature

%Temperature range

Temperature = linspace(glob_lowtemp,glob_hightemp,1000); - command to generate the 1000 values between the range of temperature
%skipping the three comment lines

for j =1:3; - for skipping the comments line by running loop

k =fgetl(f1); - to read the comments line 

end - end of the for loop
%running for loop fopr 53 times as there are 53 species

for i = 1:53;  - for loop to parse the file and create plot for 53 molecules in the file

%Parsing of the species block -comments to make a program user friendly

tline = fgetl(f1); - reading the first line for a molecule

S =strsplit(tline,' '); - splitting the string when the space is found by the command

Species_name =S{1}; - extracting the name of the molecule

%Extracting the coefficients from first line 

line2 =fgetl(f1); - reading the first line of the coefficients

x =findstr(line2,'E'); - finding the string using the command

%Finding the 5 coefficient 

x1 = line2(1:x(1)+3); - Extracting the 1st coefficients from the line

x1 = str2num(x1); - converting the string coefficients extracted above to number

x2 = line2(x(1)+4:x(2)+3); - Extracting the 2nd coefficients from the  line

x2 = str2num(x2); - converting the string coefficients extracted above to number

x3 = line2(x(2)+4:x(3)+3); - Extracting the 3rd coefficients from the  line

x3 = str2num(x3); - converting the string coefficients extracted above to number

x4 = line2(x(3)+4:x(4)+3); - Extracting the 4th coefficients from the line

x4 = str2num(x4); - converting the string coefficients extracted above to number

x5 = line2(x(4)+4:x(5)+3); - Extracting the 5th coefficients from the line

x5 = str2num(x5); - converting the string coefficients extracted above to number

%line3 5coefficients

line3 = fgetl(f1); - reading the line of the coefficients

x = findstr(line3,'E');- finding the string using the command

x6 = line3(1:x(1)+3); -Extracting the 6th coefficients from the line

x6 = str2num(x6); - converting the string coefficients extracted above to number

x7 = line3(x(1)+4:x(2)+3);-Extracting the 7th coefficients from the line

x7 = str2num(x7); - converting the string coefficients extracted above to number

x8 = line3(x(2)+4:x(3)+3);-Extracting the 8th coefficients from the line

x8 = str2num(x8); - converting the string coefficients extracted above to number

x9 = line3(x(3)+4:x(4)+3);-Extracting the 9th coefficients from the line

x9 = str2num(x9); - converting the string coefficients extracted above to number

x10 = line3(x(4)+4:x(5)+3);-Extracting the 10th coefficients from the line

x10 = str2num(x10); - converting the string coefficients extracted above to number

%Line4 4coefficients

line4=fgetl(f1); - reading the line of the coefficients

x = findstr(line4,'E');- finding the string using the command

x11 = line4(1:x(1)+3);-Extracting the 11th coefficients from the line

x11 = str2num(x11); - converting the string coefficients extracted above to number

x12 = line4(x(1)+4:x(2)+3);-Extracting the 12th coefficients from the line

x12 = str2num(x12); - converting the string coefficients extracted above to number

x13 = line4(x(2)+4:x(3)+3);-Extracting the 13th coefficients from the line

x13 = str2num(x13); - converting the string coefficients extracted above to number

x14 = line4(x(3)+4:x(4)+3);-Extracting the 14th coefficients from the line

x14 = str2num(x14); - converting the string coefficients extracted above to number


% Entropy Calculation

S = entropy_S(x1,x2,x3,x4,x5,x7,x8,x9,x10,x11,x12,x14,Temperature,glob_midtemp,R);

%Cp calculation means Specific Heat calculation

 

Cp = Specific_heat(x1,x2,x3,x4,x5,x8,x9,x10,x11,x12,Temperature,glob_midtemp,R);

%Enthlpy Calculaion is H

H = enthalpy_H(x1,x2,x3,x4,x5,x6,x8,x9,x10,x11,x12,x13,Temperature,glob_midtemp,R);

%Molecular Weight calculation of different elements

mw(i) = mol_wt(Species_name);

%Reading and writinh of the molecular wieght in the list of molecular
%wieght

 

% Plotting on the graph for species fo the temperature and specific
% heat

%Creating a folder for saving the species with its properties

directory_curr = pwd; - pwd identify the current directory

mkdir(Species_name); - command used for making a new directory

cd(Species_name); - cd is for changing the directory

%Plotting the graph in different plotting window
%plot 1 for the temperature and entrophy
%plot 2 for the temperature and enthalphy
%plot 3 for the temperature and specific heat


%plot 1 Enthalphy and Temperaure

figure(1) - to open the first figure window

plot(Temperature,H,'linewidth',3,'color','b');  -plot between temperature and enthalpy

xlabel('Temperature in [K]'); - for labelling the x axis

ylabel('Enthalphy [KJ/mol]'); - for labelling the y axis

grid on - to make the grid on 

title(sprintf('Variation in Enthalphy wrt Temperature %s',Species_name)); -  to give the title to the plot 

saveas (figure(1),'Enthalhy.jpg'); - to save the plot as jpg file in the folder made

%plot 2 Entropy and Temperaure

figure(2) - to open the second figure window

plot(Temperature,S,'linewidth',3,'color','r');  -plot between temperature and entropy

xlabel('Temperature in [K]'); - labeling of the xaxis

ylabel('Entropy [KJ/mol-k]'); - labelling the y axis

grid on - to make the grid on 

title(sprintf('Variation in Entropy wrt Temperature %s',Species_name));-  to give the title to the plot 

saveas (figure(2),'Entropy.jpg'); - to save the plot as jpg file in the folder made

%plot 3 Specific Heat and Temperaure

figure(3) - - to open the third figure window

plot(Temperature,Cp,'linewidth',3,'color','g');plot between temperature and specific heat

xlabel('Temperature in [K]'); - labeling of the xaxis

ylabel('Specific Heat [KJ]');- labelling the y axis

grid on- to make the grid on

title(sprintf('Variation in Specific Heat wrt Temperature %s',Species_name));-  to give the title to the plot 

saveas (figure(3),'Specific Heat.jpg'); - to save the plot as jpg file in the folder made

cd(directory_curr); - to change the directory 

end to end the for loop
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.