Challenge

Project 1 - Parsing NASA thermodynamic data

AIM :

the main objectives of the project is to extract 14 coeffcient of each species and calculate the enthalpy and specific heat from the file given and to show the variation of these parameters against the corresponding temperature

FILE PARSING:

file parsing is the process of extracting the required information from a given file and implement it in program . in this program we use the nasa polynomials that can be used to evaluate thermodynamic properties

such as cp h and s and the coefficients required to evaluate these polynomials for species using that data file this programming is done using matlab

function coding for formula calculating the cp,h,s:

  

here temperatures vary from each species where the first 7 will be local high temperature and the rest 7 species will be the

local low temperature so here we use if and else command to calculate both tempertures

CODE:

function [cp,h,S] = input(T,R,Tm1,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14)
for i  = length(T)
    if T(i)>Tm1
        
        cp = (c1+c2.*T +c3.*T.^2+c4.*T.^3+c5.*T.^4)*R;
        
        h = (c1+(c2.*T)./2+(c3.*T.^2)./2+(c4.*T.^3)./2+(c5.*T.^4)./2+(c6.*T.^5)/2).*T.*R;
        
         S   = (c1.*log(T)+(c2.*T)+(c3.*T.^2)./2+(c4.*T.^3)./3+(c5.*T.^4)./4+ c7)*R;
    else
        cp = (c8+c9.*T +c10.*T^.2+c11.*T^3+c12.*T^4)*R;
        
        h = (c8+(c9.*T)./2+(c10.*T.^2)./2+(c11.*T.^3)./2+(c12.*T.^4)./2+(c13.*T.^5)/2)*T.*R;
        
         S   = (c8.*log(T)+(c9.*T)+(c10.*T.^2)./2+(c11.*T.^3)./3+(c12.*T.^4)./4+ c14)*R;
    end
end
end

FUNCTION CODING FOR CALCULATING THE MOLECULAR WEIGHT:

function molecular_weight_calculation = molecular_weight(sp_name)
species = (sp_name);
elements = ['H','C','O','N','A','S'];
atomic_weight = [1.0079 12.010 15.999 14.0067 39.948,32];
molecular_weight_calculation  = 0;
for i = 1:length(species)
    for j = 1:length(elements)
        if strcmp(species(i),elements(j))
            molecular_weight_calculation = molecular_weight_calculation + atomic_weight(j);
            a = j;
        end
    end
n = str2double(species(i));
if n>1
    molecular_weight_calculation = molecular_weight_calculation + atomic_weight(a)*(n-1);
end
end
end

in this code the molecular weight is calculated  by using function command here atomic name and atomic weight are given as input  to the species 

MAIN CODE

clear all 
close all
clc
f1 = fopen ('THERMO.dat','r');
fgetl(f1);
tline = fgetl(f1);
a = strsplit(tline,' ');
global_low_temp = str2double(a{2});
gobal_mid_temp =  str2double(a{3});
gobal_high_temp = str2double(a{4});
for i = 3:5
    g = fgetl(f1);
end
 for j = 1:53
     species = fgetl(f1);
     T = strfind(species,'.');
     species(52-3:53+3)
     T1 = species(52-3:T(1)+3);
     Tl1 = str2double(T1);
    species(T(1)+6:62+3);
    Th = species(T(1)+6:T(2)+3);
    Th1 = str2double(Th);
    species (T(1)+6:72+3);
    Tm = species(T(2)+6:T(3)+3);
    Tm1 = str2double(Tm);
    sp_name = species(1:6);
   
     coeff_line_1 = fgetl(f1);
     A11 = strfind(coeff_line_1,'E');
     coeff_line_1(1:12+3);
    %co efficients 2 
     a1 = coeff_line_1(1:A11(1)+3);
     c1 = str2double(a1);
     a2 = coeff_line_1(1:A11(1)+4:A11(2)+3);
     c2 = str2double(a2);
     a3 = coeff_line_1(1:A11(2)+4:A11(3)+3);
     c3 = str2double(a3);
     a4 = coeff_line_1(1:A11(2)+4:A11(4)+3);
     c4 = str2double(a4);
     a5 = coeff_line_1(1:A11(1)+4:A11(5)+3);
     c5 = str2double(a5);
     
     % co efficient 2
     coeff_line_2 = fgetl(f1);
    A12 = strfind(coeff_line_2,'E'); 
    coeff_line_2(1:12+3);
    a6 = coeff_line_2(1:A12(1)+3);
    c6 = str2double(a6);
     a7 = coeff_line_1(1:A11(1)+4:A11(2)+3);
     c7 = str2double(a2);
     a8 = coeff_line_1(1:A11(2)+4:A11(3)+3);
     c8 = str2double(a3);
     a9 = coeff_line_1(1:A11(2)+4:A11(4)+3);
     c9 = str2double(a4);
     a10 = coeff_line_1(1:A11(1)+4:A11(5)+3);
     c10 = str2double(a5);
    %co effecient 3
    coeff_line_3 = fgetl(f1);
    A13 = strfind(coeff_line_3,'E');
    A11 = coeff_line_2(1:A13(1)+3);
    c11 = str2double(A11);
    A12 = coeff_line_1(1:A11(1)+4:A11(2)+3);
    c12 = str2double(A12);
     a13 = coeff_line_1(1:A11(2)+4:A11(3)+3);
     c13 = str2double(a13);
     a14 = coeff_line_1(1:A11(2)+4:A11(4)+3);
     c14= str2double(a14);
     T = linspace(Tl1,Th1,100);
     R = 8.314;
     
     [cp,H,S] = input(T,R,Tm1,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14);
     mkdir(['C:\Users\JAI RITESH KUMAR . R\Documents\MATLAB\ASSIGNMENT\NASA file parsing\species',sp_name])
     molecular_weight_calculation = molecular_weight(sp_name);
     %%plotting
     figure(1)
     plot([T,cp],'linewidth',3,'color','b');
     
     xlabel('temp')
     ylabel('specific heat')
     title(sp_name);
     
     figure(2)
     plot([T,H],'linewidth',3,'color','b');
     xlabel('temp')
     ylabel('entropy');
     title(sp_name);
    
    figure(3)
    plot([T,S],'linewidth',3,'color','b');
     xlabel('temp')
    ylabel('enthalpy')
    title(sp_name);
    
    
   program = (['C:\Users\JAI RITESH KUMAR . R\Documents\MATLAB\ASSIGNMENT\NASA file parsing\species',sp_name]);
   cd(program)
   saveas(1,'specific heat.jpg')
   saveas(2,'entropy.jpg')
   saveas(3,'enthalpy.jpg')
   cd('C:\Users\JAI RITESH KUMAR . R\OneDrive\Documents\MATLAB')
  
 end
 fclose(f1)

EXPLANATION OF CODE:

  1. clear all - remove data from the workspace and freeing up system memory
  2. close all -delete all the current figure or the specified memory
  3. clc -  clear all the input and output variables
  4. first to read the data file fopen command is used and to get the inforamtion fget is used 
  5. using strsplit we get the global temperatures and then using fgetl command we skip the line which are not required 
  6. loop command is created to get the values of all the temperature and coefficients present in the file 
  7. to get temperature and coefficients values we used strfind to specify them accurately
  8. so the data is in string format in order to convert it into a number str2double command used 
  9. to make a folder mkdir command is used by specifiying the directory 
  10. then plotting is taken place using the command plot 
  11. for changing directory we use the command cd in order to save the plot of specific heat entropy enthalpy in each individual file of species
  12. and then the molecular weight is calculated by calling the molecular weight calculation function 
  13. the file is closed using the command fclose.

RESULTS:

 SCREENSHOT OF THE SAVED FILE :

PLOTS FOR O2 N2 AND CO2 SPECIES:

PLOTS FOR O2:

PLOT FOR N2

PLOT FOR CO2:

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.