Challenge

Project 1 - Parsing NASA thermodynamic data

clear all
close all
clc

f1= fopen('THERMO.dat','r')
% used to skip the thermo line
skipline= fgetl(f1);
% get the first line values
tline=fgetl(f1);
A =strsplit(tline,' '); % to get individual values

R=8.314; % r is a universal gas constant
global_low_temp = str2num(A{2}); % convert string 300.00 to number 300, in cell array we use both strings and numbers
global_mid_temp = str2num(A{3});
global_high_temp = str2num(A{4});

% skip the 3 lines , those are considered to be the command line
for i=1:3
    skipline=fgetl(f1);
end
% This below loop is for 53 species same calculation
for g=1:53;
tline2=fgetl(f1) % here we got the oxygen line, from this line we can get the 3 types of temperature, species name and also the required values
B=strsplit(tline2,' ')
C=findstr(tline2,'G')
D=tline2(1:C(1)+30)

species_name=B{1} % we can exactly get the oxygen variable

low_temp=str2num(B{6})
medium_temp=str2num(B{8})
high_temp=str2num(B{7})    
line1=fgetl(f1);

a=findstr(line1,'E') % in line1 we looking for E

a1=line1(1:a(1)+3); % we can get 1st co-efficient

% In the same way all the coeffiencients of all the 4 lines are calculated

a1=str2num(a1); % we have changed string into number
a2=line1(a(1)+5:a(2)+3);
a2=str2num(a2);
a3=line1(a(2)+5:a(3)+3);
a3=str2num(a3);
a4=line1(a(3)+5:a(4)+3);
a4=str2num(a4);
a5=line1(a(4)+5:a(5)+3);
a5=str2num(a5);


line2=fgetl(f1);
a6=line2(1:a(1)+3);
a6=str2num(a6);
a7=line2(a(1)+5:a(2)+3);
a7=str2num(a7);
a8=line2(a(2)+5:a(3)+3);
a8=str2num(a8);
a9=line2(a(3)+5:a(4)+3);
a9=str2num(a9);
a10=line2(a(4)+5:a(5)+3);
a10=str2num(a10);

line3=fgetl(f1);
a11=line3(1:a(1)+3);
a11=str2num(a11);
a12=line3(a(1)+5:a(2)+3);
a12=str2num(a12);
a13=line3(a(2)+5:a(3)+3);
a13=str2num(a13);
a14=line3(a(3)+5:a(4)+3);
a14=str2num(a14);


% low temperature range is <1000(medium_temp)
% Medium temperature is 1000
% High temperature is >1000, we consider 1000 because every species contain
% temperature of 1000

T=linspace(200,3500,150);

for k=1:length(T); % we assume k, we can take any other variable also
    
    if T(k)>medium_temp
        
  cp=R*(a1+(a2.*T)+a3.*(T.^2)+a4.*(T.^3)+a5.*(T.^4))
  H=R*T.*((a1+(a2.*T)/2)+(a3.*T.^2)/3+(a4.*T.^3)/4+(a5.*T.^4)/5+a6.*T);
  S=R*(a1*log(T)+a2.*T+(a3.*T.^2)/2+(a4.*T.^3)/3+(a5.*(T.^4)/4)+a7);
  
    else % means the below values are only for T less than 1000
        
   cp=R*(a8+(a9.*T)+a10.*(T.^2)+a11.*(T.^3)+a12.*(T.^4));
   H=R*T.*((a8+(a9.*T)/2)+(a10.*T.^2)/3+(a11.*T.^3)/4+(a12.*T.^4)/5+a13.*T);
   S=R*(a8*log(T)+a9.*T+(a10.*T.^2)/2+(a11.*T.^3)/3+(a12.*(T.^4)/4)+a14);
   
    end
end

figure(1)
h(1)=plot(T,cp,'linewidth',3,'color','r')
xlabel('temperature')
ylabel('specific_heat')
grid on

figure(2)
h(2)=plot(T,H,'linewidth',3,'color','b')
xlabel('temperature')
ylabel('enthalpy')
grid on

figure(3)
h(3)=plot(T,S,'linewidth',3,'color','g')
xlabel('temperature')
ylabel('entropy')
grid on

% mkdir command is used create new folder and cd is used to save the plots in that folder.
mkdir(['C:\Users\Nandha Kumar\Desktop\temp programs\',species_name]);
cd(['C:\Users\Nandha Kumar\Desktop\temp programs\',species_name]);
saveas(figure(1),'specific heat','jpg');
saveas(figure(2),'enthalpy','jpg');
saveas(figure(3),'entropy','jpg');

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.