Project

FILE PARSING OF NASA THERMODYNAMIC DATA USING MATLAB PROGRAM

Objective:

  • Writing a function that extracts the 14 coefficients and calculates the enthalpy, entropy and specific heats for all the species in the data file and it will be reading this file NASA thermodynamic data The formulae are shown below.

Here R is the universal gas constant, T is the temperature

  • Calculating the molecular weight.
  • plotting the enthalpy, entropy, and specific heats for local temperature.
  • Saving plot as an image.

Main program:

clear all
close all
clc

% load file
f=fopen(\'THERMO.dat\',\'r\');
fgetl(f)
% store value of temperature in variable.
tempL=str2num(fgetl(f));
global_low_temp=tempL(1);
global_mid_temp=tempL(2);
global_high_temp=tempL(3);

%skipping the lines of unwanted lines
for i=1:3
    fgetl(f);
end

% create loop for all spices that calculate data, plot molecular weight.
for k =1:4:212;
    % store value of first line in variable
    line1=fgetl(f);
    % split all line in variable.
    l=strsplit(line1,\' \');
    ml=length(l);
    species=l{1};
    % store the value of local temperature
    low_temp=str2double(l(ml-3));
    high_temp=str2double(l(ml-2));
    mid_temp=str2double(l(ml-1));
    
    % store value of second lines in variable.
    line2=fgetl(f);
    % Finding the position of E and create coefficient value.
    a=strfind(line2,\'E\');
    a1=str2double(line2(1:(a(1)+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)))
    
     
    % store value of third lines in variable.
    line3=fgetl(f);
    % Finding the position of E and create coefficient value.
    b=strfind(line3,\'E\');
    a6=str2double(line3(1:(b(1)+3)));
    a7=str2double(line3((b(1)+4):(b(2)+3)));
    a8=str2double(line3((b(2)+4):(b(3)+3)));
    a9=str2double(line3((b(3)+4):(b(4)+3)));
    a10=str2double(line3((b(4)+4):(b(5)+3)));
    
    
    % store value of fourth lines in variable.
    line4=fgetl(f);
    % Finding the position of E and create coefficient value.
    c=strfind(line4,\'E\');
    a11=str2double(line4(1:(c(1)+3)));
    a12=str2double(line4((c(1)+4):(c(2)+3)));
    a13=str2double(line4((c(2)+4):(c(3)+3)));
    a14=str2double(line4((c(2)+4):(c(4)+3)));
    
    % creating lower temperature
    temp_lower=linspace(low_temp,mid_temp,100);
    % creating higher temperature
    temp_higher=linspace(mid_temp,high_temp,100);
    
    % universal gas constant(j/mol.k)
    R=8.314;
    
    for j=1:100;
        
        % calculate cp,H,S according to lower temperature and higher temp.
        cp1(j)=(a8+a9*temp_lower(j)+a10*temp_lower(j)^2+a11*temp_lower(j)^3+a12*temp_lower(j)^4)*R;
        H1(j)=(a8+(a9*temp_lower(j))/2+(a10*temp_lower(j)^2)/3+(a11*temp_lower(j)^3)/4+(a12*temp_lower(j)^4/5)+a13/temp_lower(j))*temp_lower(j)*R;
        S1(j)=(a8*log(temp_lower(j))+a9*temp_lower(j)+(a10*temp_lower(j)^2/2+(a11*temp_lower(j)^3)/3+(a12*temp_lower(j)^4)/4+a14)*R);
        
        cp2(j)=(a1+a2*temp_higher(j)+a3*temp_higher(j)^2+a4*temp_higher(j)^3+a5*temp_higher(j)^4)*R;
        H2(j)=(a1+(a2*temp_higher(j))/2+(a3*temp_higher(j)^2)/3+(a4*temp_higher(j)^3)/4+(a5*temp_higher(j)^4/5)+a6/temp_higher(j))*temp_higher(j)*R;
        S2(j)=(a1*log(temp_higher(j))+(a2*temp_higher(j))+(a3*temp_higher(j)^2/2+(a4*temp_higher(j)^3)/3+(a5*temp_higher(j)^4)/4+a7)*R);
        
        
    end
    
    % making folder
    nasa_folder=species;
    mkdir(nasa_folder);
    current_dir=pwd;
    cd(nasa_folder)
    
    % plotting graph
    figure(1);
    plot(temp_lower,cp1,\'linewidth\',2);
    hold on
    plot(temp_higher,cp2,\'linewidth\',2);
    hold off
    title([\'Temperature Vs specific heat\',species]);
    xlabel(\'Temperature\');
    ylabel(\'specific heat\');
    legend(\'low temperature\',\'high temperature\');
    fig=sprintf(\'cp_of_%s.png\',species);
    saveas(gca,fig);
    
     % plotting graph
    figure(2)
    plot(temp_lower,H1,\'linewidth\',2);
    hold on
    plot (temp_higher,H2,\'linewidth\',2);
    hold off
    title([\'Temperature vs Enthalpy \',species]);
    xlabel(\'Temperature\');
    ylabel(\'Enthalpy\');
    legend(\'low Temperature\', \'High temperature\');
     fig=sprintf(\'H_of_%s.png\',species);
    saveas(gca,fig);
    
     % plotting graph
    figure(3)
    plot(temp_lower,S1,\'linewidth\',2);
    hold on
    plot(temp_higher,S2,\'linewidth\',2);
    hold off
    title([\'Temperature vs Entropy\',species]);
    xlabel(\'Temperature\');
    ylabel(\'Entropy\');
    legend(\'low Temperature\',\'high temperature\');
    fig=sprintf(\'H_of_%s.png\',species);
    saveas(gca,fig);
    cd(current_dir);

Procedure:

  1. Nasa Thermodynamic data taking data from \'THERMO.dat\' file by using fopen command.
  2. with the help of fgetl command used to skip the header line
  3. The temperature line \'300 1000 5000\' was stored as a string in a variable.
  4. Assign the lower temperature, higher temperature, mid-temperature.
  5. using the strplit command the split the string.
  6. And the string value into numerical value using str2num command.
  7. The coefficient is arranged in a fixed order, finding the order and extract them in E location
  8. using command strfind to find the position of E, with respect to line2, line3,line4 for 14 co efficient value from a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14 variable value.
  9. Using universal constant R=8.314(j/mol.k).
  10. Using for loop command to calculate the specific heat,Enthalpy ,Entropy with respect to lower temperature and higher temperature.
  11. Making folder using command mkdir (D:MatLab/Basic/Tutorials/subfolder)
  12. saving the graphs according to the file folder pwd and using cd command is used to change the current folder to created new folder.
  13. After calculating the all the data we need to make the plot using the [T VS specific Heat, Enthalpy,Entropy]
  14. plotting the graph between Temperature and specific heat, Enthalpy, Entropy.
  15. Assigning the x label , y label and legend for the graph respective.
  16. using the Saveas command used to save the plot with .jpeg format.

Program for calculating the molecular weight :

 % Calculating molecular weight
    atom=[\'H\',\'C\',\'N\',\'R\',\'S\'];
    atm_weight=[1.00784 12.0107 15.999 14.0067 39.065 32.065];
    M_weight=0;
    current_species=char(species);
    for i=1:length(current_species)
        for j=1:length(atom)
            if strcmp(current_species(i),atom(j))
                M_weigth=M_weight+atm_weight(j);
                position=j;
            end
        end
        n=str2double(current_species(i));
        if n>1
            M_weigth=M_weight+atm_weight(j)*(n-1);
        end
    end
    fprintf(\'Molecular weight of %s : %f u\\n\',current_species,M_weight)
end

procedure:

  • The above program for calculating the molecular weight for the gas species.
  • Assign the atom [H, C, N, R, S ]and atomic weight of each atom.
  • species of various of the characters according to the species.
  • Using the for loop command for calculating the molecular weight of the atom
  • strcmp command is used to comparing the string of variables, then it will add up the atomic weight of each atoms and finally, it will calculate the molecular weight of the species.
  • finally the molecular weight of the species is calculated according to the above program.

Molecular weight:

molecular weight of o : 15.99
molecular weight of o2: 31.99
molecular weight of H :1.00784
molecular weight of H2: 2.0156
molecular weight of OH: 17.0068
molecular weight of H2O:18.0146
molecular weight of HO2: 33.005
molecular weight of H202:34.013
molecular weight of C:12.0107
molecular weight of CH: 13.01854
molecular weight of CH2: 14.02638
molecular weight of CH2(s):46.091
molecular weight of CH3:15.03
molecular weight of CH4: 16.0420
molecular weight of CO:28.0097
molecular weight of HCO:29.0175
molecular weight of CH2O:30.02538
molecular weight of CH3OH:31.033
molecular weight of C2H:25.0292
molecular weight of C2H2:26.03708
molecular weight of C2H3:27.04492
molecular weight of C2H4:28.05276
molecular weight of C2H5:29.060
molecular weight of C2H6:30.06844
molecular weight of CH2CO:42.0360
molecular weight of HCCO:41.02824
molecular weight of HCCOH:42.036
molecular weight of H2CN:28.033
molecular weight of HCN: 27.025
molecular weight of HNO: 31.0135
molecular weight of N:14.0067
molecular weight of NNH:29.022
molecular weight of N2O:44.0124
molecular weight of NH:15.015
molecular weight of NH2:16.022
molecular weight of NH3:17.0302
molecular weight of No:30.005
molecular weight of NO2:46.0047
molecular weight of HCNO:43.02424
molecular weight of HOCN:43.02424
molecular weight of HNCO:43.0242
molecular weight of NCO: 42.016
molecular weight of CN:26.017
molecular weight of HCNN:41.0319
molecular weight of N2:28.0134
molecular weight of AR:39.065
molecular weight of C3H8:44.094
molecular weight of C3H7:43.086
molecular weight of CH3CH0:44.051
molecular weight of CH2CHO:43.043

Screen Shot for Folder graph saved.

OUTPUT:PLOTS

O2

N2

CO2:

Conclusion:

Finally, the File parsing of the Nasa Thermodynamic state will be achieved and 14 coefficient of data will be extracted and calculated the Specific heat, Enthalpy, Entropy & molecular weight of various species of the showed in the above program.

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.