Challenge

Project 1 - Parsing NASA thermodynamic data

https://screenrec.com/share/iGASwjCMeQ

clear 
close
clc
f=fopen('THERMO.dat','r');  % file open
for i= 1:5   % skipping the header
    fgetl(f);
end
for j=1:53   % using the the command for loop to pick each substance data
% extraction of local temperatures
a=fgetl(f); % picking the Oxygen temperatures line
b=strsplit(a,' '); % Splitting the line using the delimiter space
z=length(b); % making a general formula for picking temperatures based on 9 strings available at each temperature line
species_name=b{1}; % indexing for the first string the substance name i.e. O2
local_low=str2num(b{z-3}); % picking temperature from the total strings index
local_high=str2num(b{z-2}); % picking temperature from the total strings index
local_mid=str2num(b{z-1});  % picking temperature from the total strings index

% extraction of coefficients
coeff_line1=fgetl(f) 
pos_e=strfind(coeff_line1,'E'); % define the character E as a common refrence for each line
a1 =str2double(coeff_line1(1:pos_e(1)+3)); % picking coefficient based on E location
a2=str2double(coeff_line1(pos_e(1)+4:pos_e(2)+3)); % picking coefficient based on E location
a3=str2double(coeff_line1(pos_e(2)+4:pos_e(3)+3)); % picking coefficient based on E location
a4=str2double(coeff_line1(pos_e(3)+4:pos_e(4)+3)); % picking coefficient based on E location
a5=str2double(coeff_line1(pos_e(4)+4:pos_e(5)+3)); % picking coefficient based on E location
coeff_line2=fgetl(f) % picking the second line
pos_2=strfind(coeff_line2,'E'); % picking coefficient based on E location
a6=str2double(coeff_line2(1:pos_2(1)+3)); % picking coefficient based on E location
a7=str2double(coeff_line2(pos_2(1)+4:pos_2(2)+3)); % picking coefficient based on E location
a8=str2double(coeff_line2(pos_2(2)+4:pos_2(3)+3)); % picking coefficient based on E location
a9=str2double(coeff_line2(pos_2(3)+4:pos_2(4)+3)); % picking coefficient based on E location
a10=str2double(coeff_line2(pos_2(4)+4:pos_2(5)+3));% picking coefficient based on E location
coeff_line3=fgetl(f) % picking the third line
pos_3=strfind(coeff_line3,'E'); % picking coefficient based on E location
a11=str2double(coeff_line3(1:pos_3(1)+3)); % picking coefficient based on E location
a12=str2double(coeff_line3(pos_3(1)+4:pos_3(2)+3)); % picking coefficient based on E location
a13=str2double(coeff_line3(pos_3(2)+4:pos_3(3)+3)); % picking coefficient based on E location
a14=str2double(coeff_line3(pos_3(3)+4:pos_3(4)+3)); % picking coefficient based on E location
% calculation of cp,h,s
T = linspace(local_low,local_high,200); 
for i=1:length(T)
   if (T(i)<=local_mid) % low temperature parameter
       ltr(i)=T(i);
   elseif (T(i)>local_mid) % high temperature parameter
       htr(i)=T(i);
   end
end 
LTR=ltr; % LTR array
m=length(ltr)
HTR=htr(m+1:length(T)); % HTR array 

% calculation of cp, h, s
R=8.314
cp1=(a8+(a9*LTR)+(a10*LTR).^2+(a11*LTR).^3+(a12*LTR).^4)*R
h1=(a8+a9*LTR/2+(a10*LTR.^2)/3+(a11*LTR.^3)/4+(a12*LTR.^4)/5+a13./LTR).*LTR*R
s1=(a8*log(LTR)+a9*LTR+(a10*LTR.^2/2)+(a11*LTR.^3/3)+(a12*LTR.^4/4)+a14)*R
cp2=(a1+(a2*HTR)+(a3*HTR).^2+(a4*HTR).^3+(a5*HTR).^4)*R
h2=(a1+(a2*HTR/2)+(a3*HTR.^2/3)+(a4*HTR.^3/4)+(a5*HTR.^4/5)+a6./HTR).*HTR*R
s2=(a1*log(HTR)+a2*HTR+(a3*HTR.^2/2)+(a4*HTR.^3/3)+(a5*HTR.^4/4)+a7)*R
CP=[cp1 cp2] % CP for both LTR and HTR 
H=[h1 h2] % H for both LTR and HTR
S=[s1 s2] % S for both LTR and HTR
mkdir(['D:\Data\Readings',species_name]) % folder creation
figure(1)
plot(T,CP,'LineWidth',2,'Color','r')
xlabel('Temperature (K)')
ylabel('Specific heat (j/kg)')
title('Temperature vs Specific heat')
figure(2)
plot(T,H,'LineWidth',2,'Color','b')
xlabel('Temperature (K)')
ylabel('Enthalpy (j)')
title('Temperature vs Enthalpy')
figure(3)
plot(T,S,"LineWidth",2,"Color",'y')
xlabel('Temperature (K)')
ylabel('Entropy (j/kg.k)')
title('Temperature vs Entropy')
cd(['D:\Data\Readings',species_name]) % mandatory to change directory before saving figures
saveas(1,'Temp Vs Specific heat','jpg');
saveas(2,'Temp Vs Enthalpy','jpg');
saveas(3,'Temp Vs 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.