Challenge

Project 1 - Parsing NASA thermodynamic data

in the code first the data file is loaded and all the values are assigned to a1,a2,a3.....a14 in for loop as there are n no of speices and before it global temperatures local mid ,high and low teperatures and identified and the values are passed on to function thermal_cal where calculations are performed to get specific heat entropy and enthalpy , later on molecular weight is calculated in function molecular and file directory is opened to save graphs in same file directory and graphs are plotted

clear all
close all
clc
%opening file
f2=fopen('THERMO.dat','r');
fgetl(f2);

% reading global temperatures
templ = str2num(fgetl(f2));
global_lowtemp = templ(1);
global_midtemp = templ(2);
global_hightemp = templ(3);



for i = 1:53
    line1 = fgetl(f2);

    l = strsplit(line1, ' ');
    m = length(l);
    species = l{1};

    %identifing low,mid,high temperature values
    Lowtemp = str2double(l(m-3))
    midtemp = str2double(l(m-1))
    hightemp = str2double(l(m-2))
    

    line2 = fgetl(f2);
     
    a = strfind(line2,'E');

%taking the values of file
    a1 = str2double(line2(1:(a(1)+3)));
    a2 = str2double(line2((a(1)+4):(a(2)+3)));
    a3 = str2double(line2((a(2)+4):(a(3)+3)));
    a4 = str2double(line2((a(3)+4):(a(4)+3)));
    a5 = str2double(line2((a(4)+4):(a(5)+3)));

    line3 = fgetl(f2);

    b=strfind(line3,'E');

    a6 = str2double(line2(1:(b(1)+3)));
    a7 = str2double(line2((b(1)+4):(b(2)+3)));
    a8 = str2double(line2((b(2)+4):(b(3)+3)));
    a9 = str2double(line2((b(3)+4):(b(4)+3)));
    a10 = str2double(line2((b(4)+4):(b(5)+3)));

    line4 = fgetl(f2);

    c = strfind(line4,'E');
  
    a11 = str2double(line2(1:(c(1)+3)));
    a12 = str2double(line2((c(1)+4):(c(2)+3)));
    a13 = str2double(line2((c(2)+4):(c(3)+3)));
    a14 = str2double(line2((c(3)+4):(c(4)+3)));
    
    Low_temp = linspace(Lowtemp,midtemp,100);
    high_temp = linspace(midtemp,hightemp,100);
    t = linspace(Lowtemp,hightemp,1000);


    % getiing values from function thermal_cal to get values of cp,h,s
    [Cp,H,S] = thermal_cal(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,t,midtemp,Lowtemp,hightemp);

    %getting molecular weight for species
    weight=molecular(species)
    display(weight,species);

    %creating folder and opening it in the curent folder
    nasa_graphs = species;
    mkdir(nasa_graphs);
    current = pwd;
    cd(nasa_graphs);

    %ploting graph 1
figure(1)
plot(t,Cp,LineWidth=2)
title('[temperature vs specific heat]')
xlabel('temperature');
ylabel('specific heat');
grid on
fig =sprintf('specific heat of %s.png',species);
saveas(gca,fig)

%ploting graph 2
figure(2)
plot(t,S,LineWidth=3)
 title('[temperature vs entropy]')
fig = sprintf('entropy of %s.png',species);
saveas(gca,fig)
grid on

%ploting graph 3
figure(3)
plot(t,H,LineWidth=3)
grid on
title('[temperature vs enthalpy]')
fig = sprintf('enthalpy of %s.png',species);
saveas(gca,fig)
cd ..
end

the function code thermal_cal is

function [Cp,H,S]=thermal_cal(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,t,midtemp,lowtemp,hightemp)
R=8.314;
if t<=midtemp
  Cp=(a8+(a9*t)+(a10*(t.^2)+(a11*t.^3)+(a12*t).^4))*R;
H=(a8+(a9.*t/2)+(a10.*(t.^2)/2)+((a11.*t.^3)/4)+(a12.*(t.^4)/5)+a13/t).*R.*t;
S=((a8*log(t))+(a9*t)+((a10*t.^2)/2)+((a11*t.^3)/3)+((a12*t.^4)/4)+a14)*R;
else
Cp=(a1+(a2*t)+(a3*(t.^2)+(a4*t.^3)+(a5*t).^4))*R;
H=(a1+(a2.*t./2)+(a3.*(t.^2)./2)+((a4.*t.^3)./4)+(a5.*(t.^4)./5)+a6./t).*R.*t;
S=((a1*log(t))+(a2*t)+((a3*t.^2)/2)+((a4*t.^3)/3)+((a5*t.^4)/4)+a7)*R;
end

the function to calculate the molecular weight is

function [wt]=molecular(A)
atom=['C','H','O','N'];
mass=[12 1 16 14];
wt=0;
for i=1:length(A)
    for j=1:length(atom)
        if A(i)==atom(j)
            wt=wt+mass(j);
            z=j;
        end
    end
    b=str2num(A(i));
    b;
    if isempty(b)==1
        ;
    else
        wt=wt+(b-1)*mass(z);
    end
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.