Challenge

Project 1 - Parsing NASA thermodynamic data

close all
clear all
clc
 
f1=fopen('THERMO.dat','r');
header=fgetl(f1);
l2=fgetl(f1);
t=strsplit(l2);
global_min=str2double(t{2});
global_mid=str2double(t{3});
global_max=str2double(t{4});
 
R=8.314;
 
temp=linspace(global_min,global_max,400);
 
% skip the lines in the file using fget1 command
for i=1:3
    fgetl(f1);
end
% To find the species of the nasa thermobynamics data of different elemnts
 
for i=1:53
    tline_1=fgetl(f1);
    A= strsplit(tline_1,' ');
    species=(A{1});
    
    tline_2=fgetl(f1);
    tline_3=fgetl(f1);
    tline_4=fgetl(f1);   
    
    
    a=strfind(tline_2,'D');
    b=strfind(tline_3,'D');
    c=strfind(tline_4,'D');
 
% extraction of high temperature coefficient
a1=str2double(tline_2(1:a(1)+3));
a2=str2double(tline_2(a(1)+4:a(2)+3));
a3=str2double(tline_2(a(2)+4:a(3)+3));
a4=str2double(tline_2(a(3)+4:a(4)+3));
a5=str2double(tline_2(a(4)+4:a(5)+3));
a6=str2double(tline_3(1:b(1)+3));
a7=str2double(tline_3(b(1)+4:b(2)+3));
 
%extraction of low temperature coefficient
 
b1=str2double(tline_3(b(2)+4:b(3)+3));
b2=str2double(tline_3(b(3)+4:b(4)+3));
b3=str2double(tline_3(b(4)+4:b(5)+3));
b4=str2double(tline_4(1:c(1)+3));
b5=str2double(tline_4(c(1)+4:c(2)+3));
b6=str2double(tline_4(c(2)+4:c(3)+3));
b7=str2double(tline_4(c(3)+4:c(3)+3));
 
mkdir(['D:\matlab\file parsing\',species]);
 
c_p=specific_heat(a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,R,temp,global_mid);
h=specific_heat(a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,R,temp,global_mid);
s=specific_heat(a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,R,temp,global_mid);
 
 
%plotting the specific heat, enthalpy ,entropy vs temperature
figure(1)
 
subplot(3,1,1)
plot(temp,c_P,'linewidth',5,'color','r');
grid on
title(species)
xlabel('temperature(k)')
ylabel('specific heat(j/kg-k)')
subplot(3,1,2)
plot(temp,h,'linewidth',5,'color','b');
grid on
title(species)
xlabel('temperature(k)')
ylabel('enthalpy(j/k)')
 
% cheange the directory and save the files
cd(['E:matlabfile parsing',species]);
saveas(1,'output.jpg');
 
% A function which the molecular weight of the species
MW=molecular_weight(species);
end
 
 
fclose(f1);
 
 
 
 
 
 
function[c_p]=specific_heat(a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,R,temp,global_mid);
if temp <=global_mid
c_p=R*(b1+(b2*(temp))+(b3*(temp).^2)+(b4*(temp).^3)+(b5*(temp).^4));
else

c_p=R*(a1+(a2*temp)+(a3*(temp).^2)+(a4*(temp).^3)+(a5*(temp).^4));
end
 
 
 
 
 
function[h]=enthalpy(a1,a2,a3,a4,a5,a6,b1,b2,b3,b4,b5,b6,R,temp,global_mid)
if temp <=global_mid
h=R.*temp.*(b1+(b2.*(temp./2))+(b3.*(temp.^2)./3)+(b4.*(temp.^3)./4)+(b5.*(temp.^4)./5)+(b6./temp));
else

h=R*temp.*(a1+(a2.*(temp./2))+(a3.*(temp.^2)./3)+(a4.*(temp.^3)./4)+(a5.*(temp.^4)./5)+(a6./temp));
end
 
 
 
function[s]=entropy(a1,a2,a3,a4,a5,a7,b1,b2,b3,b4,b5,b7,R,temp,global_mid)
if temp <=global_mid
s=R.*((b1.*log(temp))+(b2.*temp)+(b3.*(((temp.^2)./2)))+(b4.*(((temp.^3)./3)))+(b5.*(((temp.^4)./4)))+b7);

s=R.*((a1.*log(temp))+(a2.*temp)+(a3.*(((temp.^2)./2)))+(a4.*(((temp.^3)./3)))+(a5.*(((temp.^4)./4)))+a7);
end
 
 
 
function [MW]=molecular_weight(species)
 
element={'h','C','N','O','Ar'};
atomic_weight=[1,12,14,16,40];
 
MW=0;
 
for i=1:length(species)
    for j=1:length(atomic_weight)
        if strcmpi(species(i),element(j))
            MW =MW+atomic_weight(j);
            
            q=j;
        end
    end
    
    
    m=stre2double(species(i));
    if m>1
        MW=MW+(atomic_weight(q)*(m-1));
        
    end
end
 
fprint('molecular weight 0f %s is %d',species,MW);
disp(' ')
end
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.