Challenge

Project 1 - Parsing NASA thermodynamic data

1.O2

2.Ar

Screen shot where 53 species are saved:

Step by step procedure for this program execution:

1.fopen():To open the file

2.fgetl():To read the line

3.splitstrt():To split the lines by delimiter

4.findstr():To find the string with another string example findstr(l1,'E') in program

5.mkdir : To create a new folder

6.Cd: To change the directory

7.str2num():convert string to number

8.strtok():It separates it into multiple strings divided by a delimiter

9.For loop:It is used if we know the no.of iterations

10.strcmp():To compre two strings

11.disp():Display the variable

function[cp S H]=specificheat(a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,R,T,local_mid);
if T<=local_mid
    cp=R*(a1+(a2.*T)+(a3.*(T.^2))+(a4.*(T.^3))+(a5.*(T.^4)));
    S=(a1+(a2*(T/2))+(a3*((T.^2)/.3))+(a4*((T.^3)/.4))+(a5*((T.^4)/.5))+(a6./T))*R.*T;
     H=R*((a1.*log(T))+(a2.*T)+(a3.*((T.^2)./2))+(a4.*((T.^3)./3))+(a5.*((T.^4)./4))+a7);
else
cp=R*(b1+(b2.*T)+(b3.*(T.^2))+(b4.*(T.^3))+(b5.*(T.^4)));
    S=(b1+(b2*(T/2))+(b3*((T.^2)/.3))+(b4*((T.^3)/.4))+(b5*((T.^4)/.5))+(b6./T))*R.*T;
     H=R*((b1.*log(T))+(b2.*T)+(b3.*((T.^2)./2))+(b4.*((T.^3)./3))+(b5.*((T.^4)./4))+b7);
end
end



% Parsing NASA Thermodynamic file data

clear all
close all
clc

% Universal gas constant
R=8.314;

% Opening Thermodynamic file data
f1=fopen('THERMO.dat','r');
%Heading
Heading=fgetl(f1);

%Global temperature values
c=fgetl(f1);
l1=strsplit(c,' ');
global_min_temp=str2num(l1{2});
global_mid_temp=str2num(l1{3});
global_max_temp=str2num(l1{4});

%skipping comment lines
for i=1:3
    l2=fgetl(f1);
end

%Reading next line
l3=fgetl(f1)

%Parsing
at=strfind(l3,'.')
t=strsplit(l3(at-3:end-1),' ');

mkdir parsing
for j=1:100
      specius=strtok(l3,'  '); %Written the first part of string before space ' '
      cd parsing
      mkdir(specius)
      cd(specius)
      
%Calculating temperature
local_min=str2num(t{1});
local_max=str2num(t{2});
local_mid=str2num(t{3});

T=linspace(local_min,local_max,200);


a=fgetl(f1);
b=fgetl(f1);
c=fgetl(f1);

% Finding position of E
d=strfind(a,'E');
e=strfind(b,'E');
f=strfind(c,'E');

%Extracting High temperature coefficients

a1=str2num(a(1:d(1)+3));
a2=str2num(a(d(1)+4:d(2)+3));
a3=str2num(a(d(2)+4:d(3)+3));
a4=str2num(a(d(3)+4:d(4)+3));
a5=str2num(a(d(4)+4:d(5)+3));
a6=str2num(b(1:e(1)+3));
a7=str2num(b(e(1)+4:e(2)+3));

%extracting low temperature coeff
b1=str2num(b(e(2)+4:e(3)+3));
b2=str2num(b(e(3)+4:e(4)+3));
b3=str2num(b(e(4)+4:e(5)+3));
b4=str2num(c(1:f(1)+3));
b5=str2num(c(f(1)+4:f(2)+3));
b6=str2num(c(f(2)+4:f(3)+3));
b7=str2num(c(f(3)+4:f(4)+3));

%universal gas constant
R = 8.3145;

%specific heat,entrpy,enthalpy
[cp,S,H]=specificheat(a1,a2,a3,a4,a5,a6,a7,b1,b2,b3,b4,b5,b6,b7,R,T,local_mid);

%plot
figure(1)
plot(T,cp,'color','r','linewidth',3);
xlabel('temperature(K)');
ylabel('specific heat(J/KG)');

figure(2)
plot(T,H,'color','r','linewidth',3);
xlabel('temperature(K)');
ylabel('entropy(J/KG)');

figure(3)
plot(T,S,'color','r','linewidth',3);
xlabel('temperature(K)');
ylabel('enthalpy(J/KG)');

saveas(figure(1),'specific heat vs temperature.jpg');
saveas(figure(2),'entropy vs temperature.jpg');
saveas(figure(3),'enthalpy vs temperature.jpg');

%saving other data
saveas(figure(1),'specific heat vs temperature.fig');
saveas(figure(2),'entropy vs temperature.fig');
saveas(figure(3),'enthalpy vs temperature.fig');

cd('F:\matlab practice\Mani kumar\Nasa')
mkdir(specius)
cd(specius)
l3=fgetl(f1);

%molecular weight
elements=['H','O','C','N','S','Ar'];
atomic_weight=[1.007,15.999,12.010,14.006,32.059,39.948];
mw=0;

for i=1:length(specius)
  for  j=1:length(elements)
    
 if strcmp(specius(i),elements(j))==1  
     mw=atomic_weight(j)+mw;
     Z=atomic_weight(j);
  end
  end

n = str2num(specius(i));
if n>1;
    mw=Z*(n-1)+mw;
    end
end
disp(['molecular_weight of:',specius])
disp(mw)
cd('F:\matlab practice\Mani kumar\Nasa')
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.