Project

Parsing NASA thermodynamic data

%Parsing thermodynamic data of NASA file named "therm.dat"
clear all
close all
clc
R=8.31;
f1=fopen('therm.dat','r')
Header=fgetl(f1);
global_low_temp=fscanf(f1,'%f',[1,1]);
global_mid_temp=fscanf(f1,'%f',[1,1]);
global_max_temp=fscanf(f1,'%f',[1,1]);
for j=1:4
skip=fgetl(f1);
end
% Temperatute array
temp=linspace(200,3500,50);

% Extracting data 

for i=1:300
    
skip=fgets(f1);
Species = sscanf(skip,'%c',[5,1])

exit=Species(1:3);
last='END';
if exit==last
    break
end

a2=fgets(f1);
data2=sscanf(a2,'%f');

a3=fgets(f1);
data3=sscanf(a3,'%f');

a4=fgets(f1);
data4=sscanf(a4,'%f');

ht=[data2(1) data2(2) data2(3) data2(4) data2(5) data3(1) data3(2)] %High temp data

lt=[data3(3) data3(4) data3(5) data4(1) data4(2) data4(3) data4(4)] %Low temp data

for j=1:length(temp)
    t=1000; %mid temp calculation
    if temp(j)<=t
        
        Cp(j) = R*(lt(1)+lt(2)*temp(j)+lt(3)*(temp(j))^2 +lt(4)*(temp(j))^3 +lt(5)*(temp(j))^4);
         H(j) = R*temp(j)*(lt(1)+lt(2)*temp(j)/2 +lt(3)*((temp(j))^2)/3 +lt(4)*((temp(j))^3)/4 + lt(5)*((temp(5))^4)/5 + lt(6)/temp(j));
         S(j) = R*(lt(1)*log(temp(j))+lt(2)*temp(j)+lt(3)*((temp(j))^2)/2 +lt(4)*((temp(j))^3)/3 + lt(5)*((temp(j))^4)/4 + lt(7));
         
    else
        Cp(j) = R*(ht(1)+ht(2)*temp(j)+ht(3)*(temp(j))^2 +ht(4)*(temp(j))^3 +ht(5)*(temp(j))^4);
         H(j) = R*temp(j)*(ht(1)+ht(2)*temp(j)/2 +ht(3)*((temp(j))^2)/3 +ht(4)*((temp(j))^3)/4 + ht(5)*((temp(5))^4)/5 + ht(6)/temp(j));
         S(j) = R*(ht(1)*log(temp(j))+ht(2)*temp(j)+ht(3)*((temp(j))^2)/2 +ht(4)*((temp(j))^3)/3 + ht(5)*((temp(j))^4)/4 + ht(7));
        
    end
  
end
%calculating molecular weight
Mw = 0;
atoms = ['H' 'C' 'N' 'O'];
atom_wt = [1 12 14 16];

for i = 1:length(Species)
    
    for j = 1:length(atoms)
        if(strcmp(Species(i),atoms(j)))
            k=j;
            Mw = Mw + atom_wt(k);
        
    f = str2num(Species(i));
    if(f>1)
        Mw = Mw + atom_wt(k)*(f-1);
    end
    end
    end
    end
    %plotting
    % Creating a name for the directory
fd = sprintf('%s',Species);
% Making a directory
mkdir(fd);
      
      %Plot 1, Specific heat vs temp
      figure(1);
      plot(temp,Cp);
      xlabel('Temperature in K');
      ylabel('Specific heat in kJ')
      title('Specific heat vs Temp');
      
      

      %Plot 2, Enthalpy vs temp  
      figure(2);
      plot(temp,H);
      xlabel('Temperature in K');
      ylabel('Enthalpy in kJ/(mol)')
      title('Enthalpy vs Temp');
      
     
      %Plot 3, Entropy vs temp
      figure(3);
      plot(temp,S);
      xlabel('Temperature in K');
      ylabel('Entropy in kJ/(mol K)')
      title('Entropy vs Temp');
      % saving the plots that got generated
pf = pwd;
cd(fd);
saveas(1, 'cp.png');
saveas(2, 'h.png');
saveas(3, 's.png');
cd(pf);
end

fclose(f1)      
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.