Challenge

Project 1 - Parsing NASA thermodynamic data

clear
clc
close
%% Open data file
f1=fopen("C:\Users\ADMIN\Documents\MATLAB\THERMO.dat",'r');
%% set title
title=fgetl(f1);
%% Extract global temperature range
temp_range=fgetl(f1);
temp_range=str2num(temp_range);
global_low_temp=temp_range(1);
global_mid_temp=temp_range(2);
global_high_temp=temp_range(3);

%% removing comments in the next 3 lines
for i=1:1:3
fgetl(f1);
end
%% Counting the number of species
i=0;
while strcmp(fgetl(f1),'END')==0
i=i+1;
end
no_species=i/4;
%% Total 53 species are present
frewind(f1);
for i=1:1:5
fgetl(f1);
end

for i=1:1:no_species
%% GET species names
line=fgetl(f1);
M= strsplit(line);
name=M{1};

%% Get temperature limits
M=strfind(line,'.');
local_low_limit=str2num(line(M(1)-4:M(1)+3));
local_high_limit=str2num(line(M(2)-4:M(2)+3));
local_mid_limit=str2num(line(M(3)-4:M(3)+3));
species_data(i).name=name;
species_data(i).llt=local_low_limit;
species_data(i).lmt=local_mid_limit;
species_data(i).lht=local_high_limit;

%% Get coefficients from next line
line=fgetl(f1);
M=strfind(line,'E');
a1=str2double(line(1:M(1)+3));
a2=str2double(line(M(1)+4:M(2)+3));
a3=str2double(line(M(2)+4:M(3)+3));
a4=str2double(line(M(3)+4:M(4)+3));
a5=str2double(line(M(4)+4:M(5)+3));
%% Jump to next line and similarly get the remaining coefficients
line=fgetl(f1);
M=strfind(line,'E');
a6=str2double(line(1:M(1)+3));
a7=str2double(line(M(1)+4:M(2)+3));
b1=str2double(line(M(2)+4:M(3)+3));
b2=str2double(line(M(3)+4:M(4)+3));
b3=str2double(line(M(4)+4:M(5)+3));
%% Jump to next line
line=fgetl(f1);
M=strfind(line,'E');
b4=str2double(line(1:M(1)+3));
b5=str2double(line(M(1)+4:M(2)+3));
b6=str2double(line(M(2)+4:M(3)+3));
b7=str2double(line(M(3)+4:M(4)+3));
species_data_lowcoeff=[b1 b2 b3 b4 b5];

%% Calculating the specific heat for low temperatures & high temperatures
R= 8.314; %% universal gas constant;
T_low=linspace(local_low_limit,local_mid_limit,100);
T_high=linspace(local_mid_limit,local_high_limit,100);
Cp_low=[b1 b2 b3 b4 b5]*[ones(1,100);T_low;T_low.^2;T_low.^3;T_low.^4].*R;
Cp_high=[a1 a2 a3 a4 a5]*[ones(1,100);T_high;T_high.^2;T_high.^3;T_high.^4].*R;
%% Plotting specific heat vs temperature
figure(i);
s(1)=subplot(1,3,1);
plot(T_low,Cp_low,'b','Linewidth',3);
hold on;
plot(T_high,Cp_high,'r','Linewidth',3);
legend("low temp",'high temp');
xlabel('Temperature');
ylabel('Specific heat');


%% Calculating Enthalpy
H_high=[a1 a2/2 a3/3 a4/4 a5/5 a6]*[T_high;T_high.^2;T_high.^3;T_high.^4;T_high.^5;ones(1,100)].*R;
H_low=[b1 b2/2 b3/3 b4/4 b5/5 b6]*[T_low;T_low.^2;T_low.^3;T_low.^4;T_low.^5;ones(1,100)].*R;
%% Plotting Enthalpy vs temperature
s(2)=subplot(1,3,2);
%title('Enthalpy vs temperature')
plot(T_low,H_low,'b','Linewidth',3);
hold on;
plot(T_high,H_high,'r','Linewidth',3);
legend("low temp",'high temp');
xlabel('Temperature');
ylabel('Enthalpy');



%% Calculating Entropy
S_high=[a1 a2 a3/2 a4/3 a5/4 a7]*[log(T_high);T_high;T_high.^2;T_high.^3;T_high.^4;ones(1,100)].*R;
S_low=[b1 b2 b3/2 b4/3 b5/4 b7]*[log(T_low);T_low;T_low.^2;T_low.^3;T_low.^4;ones(1,100)].*R;
%% plotting entropy vs temperature
s3=subplot(1,3,3);
%title('Entropy vs temperature');
plot(T_low,S_low,'b','Linewidth',3);
hold on;
plot(T_high,S_high,'r','Linewidth',3);
legend("low temp",'high temp');
ylabel('Entropy');
sgtitle("plots for "+name);

%% Saving pics in individual folders
path='C:\Users\ADMIN\Documents\MATLAB\Skill-lync_plots'
plot_1=fullfile(path,name)
saveas(figure(i),plot_1, 'png');
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.