Challenge

Project 1 - Parsing NASA thermodynamic data

specific heat- specific heat is amount of per unit mass raise to temperature per unit degree celsius.

entropy-system's thermal pe unit temp available for doing useful work.

entahlpy-it is energywhich is equal to internal energy+pressure*volume.

given formula is used for cp,s,H.

GRAPHS cp,s,H WRT to temperature is plotted.

molecular weight is calculated by formula.

clear all
close all
clc
% opening the nasa file 'THERMO.DAT)IN MAT LAB USING FOPEN COMMAND.
f1=fopen('THERMO.dat','r');

%heading(read line from file using fgetl command)
line1=fgetl(f1);
% reading line2.

line2=fgetl(f1);
%splittin character of line with delimiter.
A=strsplit(line2,' ');
% convert character array to numeric array temp 300,1000,5000
lowtemp=str2num(A{2});
medtemp=str2num(A{3});
hightemp=str2num(A{4});
% ommitting line 3,4,5
line3=fgetl(f1);
line4=fgetl(f1);
line5=fgetl(f1);

%reading the species for loop is used for reading all 53 species.finding
%all 14 coefficient.each species contain 3 lines for these coefficient.to
%distinguish each coefficient strfind command is used. numerical value is
%given by str2num command
for i=1:53
    species=fgetl(f1);
    species_name=species(1:6);
    %CONVERTING STRING TO NUMBER
    
    tline1=fgetl(f1);
    a=strfind(tline1,'E');
    a1=tline1(1:a(1)+3);
    a1=str2num(a1);
    a2=tline1(a(1)+4:a(2)+3);
   a2=str2num(a2); 
   a3=tline1(a(2)+4:a(3)+3);
 a3=str2num(a3); 
 a4=tline1(a(3)+4:a(4)+3);
 a4=str2num(a4); 
 a5=tline1(a(4)+4:a(5)+3);
 a5=str2num(a5);
 tline2=fgetl(f1);
 b=strfind(tline2,'E');
 a6=tline2(1:b(1)+3);
a6=str2num(a6);
a7=tline2(b(1)+4:b(2)+3);
a7=str2num(a7);

a8=tline2(b(2)+4:b(3)+3);
a8=str2num(a8);

a9=tline2(b(3)+4:b(4)+3);
a9=str2num(a9);

a10=tline2(b(4)+4:b(5)+3);
a10=str2num(a10);

tline3=fgetl(f1);
 c=strfind(tline3,'E');
 
 a11=tline3(1:c(1)+3);
a11=str2num(a11);

a12=tline3(c(1)+4:c(2)+3);
a12=str2num(a12);

a13=tline3(c(2)+4:c(3)+3);
a13=str2num(a13);

a14=tline3(c(3)+4:c(4)+3);
a14=str2num(a14);
% temp between 300 and 5000 is divided into 100  parts to plot graph.
Temp=linspace(300,5000,100);
%universal gas coefficient j/kmol-k
R=8.314;

% for & ELSE loop j is used for distinguish low tempr coefficient and high temp
% coefficient for each species and calculating Cp,S,H
for j=1:length(Temp)
    if Temp(j)<3000
        
     Cp=(a1+a2*Temp+a3*Temp.^2+a4*Temp.^3+a5*Temp.^4).*R;  
    H=(a1+(a2*Temp)./2+(a3*Temp.^2)./3+(a4*Temp.^3)./4+(a5*Temp.^4)./5+a6./Temp).*Temp.*R; 
   S=(a1*log(Temp)+(a2*Temp)+(a3*Temp.^2)./2+(a4*Temp.^3)./3+(a5*Temp.^4)./4+a7).*R;  
    else
        Cp=(a8+a9*Temp+a10*Temp.^2+a11*Temp.^3+a12*Temp.^4).*R; 
        H=(a8+(a9*Temp)./2+(a10*Temp.^2)./3+(a11*Temp.^3)./4+(a12*Temp.^4)./5+a13./Temp).*Temp.*R; 
        S=(a8*log(Temp)+(a9*Temp)+(a10*Temp.^2)./2+(a11*Temp.^3)./3+(a12*Temp.^4)./4+a14).*R;
    

    end
end




% plotting the graph betwee cp& T,S&T,H&T for each species.using x and y
% label& title for each specy name.we get 3 figure



%plot cp vs t

figure(1)
plot(Temp,Cp,'linewidth',2,'color','b');
xlabel('TemperatureK');
title(species_name);
ylabel('specific heat(kj)')

figure(2)
plot(Temp,H,'linewidth',2,'color','r');
title(species_name);
xlabel('TemperatureK');
ylabel('Enthalpy');

figure(3)
plot(Temp,S,'linewidth',2,'color','k');
title(species_name);
xlabel('TemperatureK');
ylabel('Entropy');
% mkdir is used to make a folder where each species graph is saved. we use
% change directory command for each species.
cd(['D:\a_matlab_programme\plots']);
mkdir([species]);
cd(species);

%saving the plots using save as command.
saveas(1,'specific heat.jpg');
saveas(2,'Enthalpy.jpg');
saveas(3,'Entropy.jpg');
cd ..

%we find molecular mass of each species using constituents(by which each
%species is made up.using molecur ass formula

%  MM=Molecular_mass(species_name)
 
species=upper(species_name);
constituents=['H','C','N','O','A'];
Atomic_weight=[1,12,14,16,40];
MM=0;
%for & if formula is to choose between to formula.
for k=1:length(species);
    for j=1:length(constituents);
        % strcmp is used to compare to vectors.
        if strcmp(species(k),constituents(j))==1;
            MM=MM+Atomic_weight(j);
            u=j;
        end
    end
    n=str2num(species_name(k));
    if n>1
        MM=MM+Atomic_weight(u)*(n-1);
      
    end
end
%sprintf is used toformat data in readable arrays.
MOL_MASS=sprintf('The molecular mass = %d',MM);
disp(MOL_MASS);


end

%closing file
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.