Challenge

Project 1 - Parsing NASA thermodynamic data

%Parsing NASA thermodynamic data
%clearing and close and clc in the start of program
clear all
close all
clc
% reading the first line of the thermo.dat file 
f1= fopen('THERMO.dat','r');
get=fgetl(f1);
% reading the global temperature  its the second line
temp=fgetl(f1);

A= strsplit(temp,' ');      % strspit command is used to seperate every word and temp after space
% str2num command is used to covert the string into number from the
% temperature
global_low_temp= str2num(A{2});
global_mid_temp= str2num(A{3});
global_high_temp= str2num(A{4});

% to avoid the three comments in the table

for i=1:3
    fgetl(f1)
end

% reading the species from the table there are 53 species name.
%for loop is used to read every species from species name, coefficient and
%local temperaure of the individual species
for j=1:53
    line1=fgetl(f1);
    line1_split=strsplit(line1,' ');
    species=(line1_split{1});
     % reading the local temperature which is in string and converting to
     % number
    local_min_temp=str2num(line1_split{end-3});
    local_mid_temp=str2num(line1_split{end-1});
    local_high_temp=str2num(line1_split{end-2});
    T=linspace(local_min_temp,local_high_temp,1000);
   
    % reading the co-efficient of every species
    line2=fgetl(f1);
    line3=fgetl(f1);
    line4=fgetl(f1);

    find_E_in_line2=findstr(line2,'E');
    l2E=find_E_in_line2;

    %reading the coefficient from line 2
    cf1 = str2double(line2(1:(l2E(1)+3)));
    cf2= str2double(line2((l2E(1)+4):(l2E(2)+3)));
    cf3= str2double(line2((l2E(2)+4):(l2E(3)+3)));
    cf4= str2double(line2((l2E(3)+4):(l2E(4)+3)));
    cf5= str2double(line2((l2E(4)+4):(l2E(5)+3)));

    find_E_in_line3=findstr(line3,'E');
    l3E=find_E_in_line3;

    %reading the coefficient from line 3
    cf6 = str2double(line3(1:(l3E(1)+3)));
    cf7= str2double(line3((l3E(1)+4):(l3E(2)+3)));
    cf8= str2double(line3((l3E(2)+4):(l3E(3)+3)));
    cf9= str2double(line3((l3E(3)+4):(l3E(4)+3)));
    cf10= str2double(line3((l3E(4)+4):(l3E(5)+3)));

     find_E_in_line4=findstr(line4,'E');
    l4E=find_E_in_line4;

    %reading the coefficient from line 4
    cf11= str2double(line4(1:(l4E(1)+3)));
    cf12= str2double(line4((l4E(1)+4):(l4E(2)+3)));
    cf13= str2double(line4((l4E(2)+4):(l4E(3)+3)));
    cf14= str2double(line4((l4E(3)+4):(l4E(4)+3)));

   
    %calculating specific heat (cp),enthalpy(H),entropy(S)

    %R Gas constant which is 8.3145(j/k.mol)

    R=8.3145;

for i=1:length(T)
   
    if T(i)<= local_mid_temp
        cp(i)=R*(cf1+cf2*T(i)+cf3*T(i)^2+cf4*T(i)^3+cf5*T(i)^4);
        H(i)=R*T(i)*(cf1+cf2*T(i)/2+cf3*T(i)^2/3+cf4*T(i)^3/4+cf5*T(i)^4/5+cf6/T(i));
        S(i)=R*(cf1*log(T(i)) +cf2*T(i)+cf3*T(i)^2/2+cf4*T(i)^3/3+cf5*T(i)^4/4+cf7);
    
    else
        cp(i)=R*(cf8+cf9*T(i)+cf10*T(i)^2+cf11*T(i)^3+cf12*T(i)^4);
        H(i)=R*T(i)*(cf8+cf9*T(i)/2+cf10*T(i)^2/3+cf11*T(i)^3/4+cf12*T(i)^4/5+cf13/T(i));
        S(i)=R*(cf8*log(T(i)) +cf9*T(i)+cf10*T(i)^2/2+cf11*T(i)^3/3+cf12*T(i)^4/4+cf14);
    
    end

end



% now plotting the temperature with the specific heat,enthalphy,entrophy.

%plot for temerature vs specific heat cp
mkdir(species)
cd(species)
figure (1)
plot(T,cp);
xlabel('temperature[K]');
ylabel('specific heat cp [J/kg.K]');
title(sprintf('Temperature vs Specific Heat range of %s',species));
saveas(figure(1),'specific heat.jpg');

figure (2)

plot(T,H);
xlabel('temperature[K]');
ylabel('Enthalphy[KJ]');
title(sprintf('Temperature vs Enthalphy range of %s',species));
saveas(figure(2),'Enthalphy.jpg');
figure (3)
plot(T,S);
xlabel('temperature[K]');
ylabel('Entrophy[J/K]');
title(sprintf('Temperature vs Entrophy range of %s',species));
saveas(figure(3),'Entrophy.jpg');
%saving the plots in different folder 
cd ..

%calculating molecular weight 
molecular_weight_calc= molecular_weight(species)
    

end

program for calculating the molecular weight of every species.

function molecular_weight_calc= molecular_weight(species)

elements =['H','C','O','N','A'];

fprintf('molecular weight of ');
fprintf('species');
fprintf(':');
Atomic_weight=[1,12,16,14,40];

molecular_weight_calc=0;

for i=1:length(species);
   for j=1:length(elements);
    if strcmp(species(i),elements(j));
     molecular_weight_calc=molecular_weight_calc+Atomic_weight(j);
        position=j;
    end
end
n=str2num(species(i));
if n>1;
    molecular_weight_calc=molecular_weight_calc+(Atomic_weight(position)*(n-1));

   
end
end
 fprintf('molecular weight of %s :-',species);
 fprintf('%f',molecular_weight_calc);
 disp(' ');
 end

Im attaching the results for your reference below.

FINAL RESULTS

PLOT OF SOME SPECIES IM ATTACHING BELOW FOR YOUR REFRENCE.

PLOT OF 02

PLOT FOR N2

PLOT FOR CO2

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.