Challenge

Project 1 - Parsing NASA thermodynamic data

PROJECT-1 PARSING NASA THERMODYNAMIC DATA.

We want to make function that extracts the 14 co-efficients and calculates the enthalpy, entropy and specific heats for all the species in the data file.

so we start programming by ,clear all,close all,clc

first we should take the file which is given,for that this code is used

f1=fopen('THERMO.dat','r');
fgetl(f1);

then read the first line of the file.

header_global_temp=fget1(f1);
A=strsplit(header_global_temp,' ');

next step is to obtaining global maximum,medium,and minimum temp

for that this code will be applied,

global_min=strsplit(A{2});
global_mid=strsplit(A{3});
global_max=strsplit(A{4});

ignoring the comments in the file by,

for i=1:3
fgetl(f1);
end

reading te line datas given,

for i=1:53
header=fget(f1);
species_header=strsplit(header,' ');
species_name=species_header{1};
end

finding the string

loc_temp=strsplit(header,' ');
speciess_name=(loc_temp(1));
loc_min_temp=str2double(loc_temp(end-3));
loc_min_temp=str2double(loc_temp(end-2));
loc_min_temp=str2double(loc_temp(end-1));

next is to find the all coefficients in this, ie 14 number of coefficients.

this three codes are using for this,

strfind
tline1
str2double

%finding the coefficients a1 to a14
tline1=fgetl(f1);
tline2=fgetl(f1);
tline3=fgetl(f1);

a=strfind(tline1,'E');
a1=tline1(1:a(1)+3);
a1=str2double(a1);

a2=tline1(a(1)+4:a(2)+3);
a2=str2double(a2);

a3=tline1(a(2)+4:a(3)+3);
a3=str2double(a3);

a4=tline1(a(3)+4:a(4)+3);
a4=str2double(a4);

a5=tline(a(4)+4:a(5)+3);
a5=str2double(a5);

%finding strings and convert to numbers in line3

a=strfind(tline2,'E');

a6=tline2(1:a(1)+3);
a6=str2double(a6);

a7=tline2(a(1)+4:a(2)+3);
a7=str2double(a7);

a8=tline2(a(2)+4:a(3)+3);
a8=str2double(a8);

a9=tline2(a(3)+4:a(4)+3);
a9=str2double(a9);

a10=tline2(a(4)+4:a(5)+3);
a10=str2double(a10);

%finding strings and convert to numbers in line4

a=strfind(tline3,'E');
a11=tline3(1:a(1)+3);
a11=str2double(a11);

a12=tline3(a(1)+4:a(2)+3);
a12=str2double(a12);

a13=tline3(a(2)+4:a(3)+3);
a13=str2double(a13);

a14=tline3(a(3)+4:a(4)+3);
a14=str2double(a14);

create a folder.

mkdir(['C:\users\vaish\Onerive\Desktop\NASA\images\',species_n])

for getting the array of cp,h and s, for loop is used.

for k=1:length(T)
    %to compare the temperature to assign the coefficients
    %a1-a7 is high temperature coefficients
    %a8-a14 is low temperature coefficients
    if T(k)>loc_med_temp
        %high temperature coefficients
        cp=(a1+(a2.*T)+(a3.*T.^2)+(a4.*T.^3)+(a5.*T.^4))*R;
        H=(a1+(a2.*T)/2+(a3.*T.^2)/3+(a4.*T.^3)/4+(a5.*T.^4)/5+(a6/T))*RT
        S=((a1.*log(T))+(a2.*T)+(a3.*T.^2)/2+(a4.*T.^3)/3+(a5.*T.^4)/4+a7)*R
    else
        %low temperature coefficients
        cp=(a8+(a9.*T)+(a10.*T.^2)+(a11.*T.^3)+(a12.*T.^4))*R;
        H=(a8+(a9.*T)/2+(a10.*T.^2)/3+(a11.*T.^3)/4+(a12.*T.^4)/5+(a13/T))*RT
        S=((a8.*log(T))+(a9.*T)+(a10.*T.^2)/2+(a11.*T.^3)/3+(a12.*T.^4)/4+(a13))*R
    end
end

in this high temperature coefficients and low temperature coefficients are noticed.

next step is to plot the graph,

plotting the curve cp vs T

figure(1)
plot(cp,T,'linewidth',3,'volor','r');

grid on
title(species_name);
xlabel('specific heat [J/K]');
ylabel('temperature [K]');
saveas(1,'cp_vs_temp.jpeg');

plot of H vs T


figure(2)
plot(H,T.'linewidth',3,'color','g');
title(species_name);
xlabel('enthalpy [J]');
ylabel('temperature [k]');

plot of entropy vs temperature
figure(3)
plot(S,T,'linewidth',3,'color','b');
title(species_name);
xlabel('entropy [J/K]');
ylabel('temperature [K]');

plotting the curve

%cp vs T
figure(1)
plot(cp,T,'linewidth',3,'volor','r');
grid on
title(species_name);
xlabel('specific heat [J/K]');
ylabel('temperature [K]');
saveas(1,'cp_vs_temp.jpeg');

%H vs T
figure(2)
plot(H,T.'linewidth',3,'color','g');
title(species_name);
xlabel('enthalpy [J]');
ylabel('temperature [k]');

%entropy vs temperature
figure(3)
plot(S,T,'linewidth',3,'color','b');
title(species_name);
xlabel('entropy [J/K]');
ylabel('temperature [K]');

so the program is done.

the full code is attching below.

clear all
close all
clc

%for getting the data file
f1=fopen('THERMO.dat','r');
fgetl(f1);
%reading the first line of the file
header_global_temp=fget1(f1);
A=strsplit(header_global_temp,' ');

%splitting the string
%obtaining global maximum,medium,and minimum temp

global_min=strsplit(A{2});
global_mid=strsplit(A{3});
global_max=strsplit(A{4});

%ignoring the comments in the file

for i=1:3
    fgetl(f1);
end

%reading all line data

for i=1:53
    header=fget(f1);
    species_header=strsplit(header,' ');
    species_name=species_header{1};
end

%finding the string

loc_temp=strsplit(header,' ');
speciess_name=(loc_temp(1));
loc_min_temp=str2double(loc_temp(end-3));
loc_min_temp=str2double(loc_temp(end-2));
loc_min_temp=str2double(loc_temp(end-1));

%finding the coefficients a1 to a14
tline1=fgetl(f1);
tline2=fgetl(f1);
tline3=fgetl(f1);

a=strfind(tline1,'E');
a1=tline1(1:a(1)+3);
a1=str2double(a1);

a2=tline1(a(1)+4:a(2)+3);
a2=str2double(a2);

a3=tline1(a(2)+4:a(3)+3);
a3=str2double(a3);

a4=tline1(a(3)+4:a(4)+3);
a4=str2double(a4);

a5=tline(a(4)+4:a(5)+3);
a5=str2double(a5);

%finding strings and convert to numbers in line3

a=strfind(tline2,'E');

a6=tline2(1:a(1)+3);
a6=str2double(a6);

a7=tline2(a(1)+4:a(2)+3);
a7=str2double(a7);

a8=tline2(a(2)+4:a(3)+3);
a8=str2double(a8);

a9=tline2(a(3)+4:a(4)+3);
a9=str2double(a9);

a10=tline2(a(4)+4:a(5)+3);
a10=str2double(a10);

%finding strings and convert to numbers in line4

a=strfind(tline3,'E');
a11=tline3(1:a(1)+3);
a11=str2double(a11);

a12=tline3(a(1)+4:a(2)+3);
a12=str2double(a12);

a13=tline3(a(2)+4:a(3)+3);
a13=str2double(a13);

a14=tline3(a(3)+4:a(4)+3);
a14=str2double(a14);

%creating folder

mkdir(['C:\users\vaish\Onerive\Desktop\NASA\images\',species_n])




T=linspace(loc_min_temp,loc_max_temp,1000);
R=8.314

%for getting the array of cp,h and s

for k=1:length(T)
    %to compare the temperature to assign the coefficients
    %a1-a7 is high temperature coefficients
    %a8-a14 is low temperature coefficients
    if T(k)>loc_med_temp
        %high temperature coefficients
        cp=(a1+(a2.*T)+(a3.*T.^2)+(a4.*T.^3)+(a5.*T.^4))*R;
        H=(a1+(a2.*T)/2+(a3.*T.^2)/3+(a4.*T.^3)/4+(a5.*T.^4)/5+(a6/T))*RT
        S=((a1.*log(T))+(a2.*T)+(a3.*T.^2)/2+(a4.*T.^3)/3+(a5.*T.^4)/4+a7)*R
    else
        %low temperature coefficients
        cp=(a8+(a9.*T)+(a10.*T.^2)+(a11.*T.^3)+(a12.*T.^4))*R;
        H=(a8+(a9.*T)/2+(a10.*T.^2)/3+(a11.*T.^3)/4+(a12.*T.^4)/5+(a13/T))*RT
        S=((a8.*log(T))+(a9.*T)+(a10.*T.^2)/2+(a11.*T.^3)/3+(a12.*T.^4)/4+(a13))*R
    end
end

%for i=1:53
%loc_temp=strsplit(tline,' ');
%species_name=(loc_temp(1));

%plotting the curve

%cp vs T
figure(1)
plot(cp,T,'linewidth',3,'volor','r');
grid on
title(species_name);
xlabel('specific heat [J/K]');
ylabel('temperature [K]');
saveas(1,'cp_vs_temp.jpeg');

%H vs T
figure(2)
plot(H,T.'linewidth',3,'color','g');
title(species_name);
xlabel('enthalpy [J]');
ylabel('temperature [k]');

%entropy vs temperature
figure(3)
plot(S,T,'linewidth',3,'color','b');
title(species_name);
xlabel('entropy [J/K]');
ylabel('temperature [K]');
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.