Challenge

Project 1 - Parsing NASA thermodynamic data

clear all
close all
clc

R =  8.314%J / mol. K
%To ready the THERMO.dat file
f1 = fopen('thermo.txt','r');
fgetl(f1)
tempL = str2num(fgetl(f1));
% global_low_temperature = tempL(1)
% global_mid_temperature = tempL(2)
% global_high_temperature = tempL(3)
%for skipping the unwanted lines
for i = 1:3
    fgetl(f1);
end

for y=1:53

%for reading local temperatures   
tline0 = fgetl(f1);

a = findstr(tline0,'.');
tlin0=strtok(tline0)
lt1 = tline0(52-3:a(1)+3);
lt2 = tline0(a(1)+4:62+3);
lt3 = tline0(a(2)+4:72+3);
Local_Temp_low = str2num(lt1)
Local_Temp_high = str2num(lt2)
Local_Temp_mid = str2num(lt3)

%To read the lines for coefficient
%Reading the first line of Coefficient

tline1 = fgetl(f1);
b = findstr(tline1,'E');
a1 = str2num(tline1(1:b(1)+3))
a2 = str2num(tline1(b(1)+4:b(2)+3))
a3 = str2num(tline1(b(2)+4:b(3)+3))
a4 = str2num(tline1(b(3)+4:b(4)+3))
a5 = str2num(tline1(b(4)+4:b(5)+3))

%reading the second line of coefficient
tline2 = fgetl(f1);
c = findstr(tline2,'E');
a6 = str2num(tline2(1:c(1)+3))
a7 = str2num(tline2(c(1)+4:c(2)+3))
a8 = str2num(tline2(c(2)+4:c(3)+3))
a9 = str2num(tline2(c(3)+4:c(4)+3))
a10 = str2num(tline2(c(4)+4:c(5)+3))

%Reading the third line of coefficient
tline3 = fgetl(f1);
d = findstr(tline3,'E');
a11 = str2num(tline3(1:d(1)+3))
a12 = str2num(tline3(d(1)+4:d(2)+3))
a13 = str2num(tline3(d(2)+4:d(3)+3))
a14 = str2num(tline3(d(3)+4:d(4)+3))

Lower_Temp = linspace(Local_Temp_low,Local_Temp_mid,100);
Higher_Temp = linspace(Local_Temp_mid,Local_Temp_high,100);
%Cp of the given data
Cp_High = (a1 + a2*Higher_Temp + a3*Higher_Temp.^2 + a4*Higher_Temp.^3 + a5*Higher_Temp.^4 + a6*Higher_Temp.^5 + a7*Higher_Temp.^6 )*R
Cp_Low = (a8 + a9*Lower_Temp + a10*Lower_Temp.^2 + a11*Lower_Temp.^3 + a12*Lower_Temp.^4 + a13*Lower_Temp.^5 + a14*Lower_Temp.^6)*R
%Enthalphy of the given data
H_High = (a1 + a2 * (Higher_Temp/2) + a3 * ((Higher_Temp).^2)/3 + a4 * ((Higher_Temp).^3)/4 + a5 * ((Higher_Temp).^4)/5 + a6 * ((Higher_Temp).^5)/6 + a7 * ((Higher_Temp).^6)/7)*R.*Higher_Temp
H_Low = (a8 + a9 * (Lower_Temp/2) + a10 * ((Lower_Temp).^2)/3 + a11 * ((Lower_Temp).^3)/4 + a12 * ((Lower_Temp).^4)/5 + a13 * ((Lower_Temp).^5)/6 + a14 * ((Lower_Temp).^6)/7)*R.*Lower_Temp
%Entrophy Calculation for the given data
S_High = (a1*log(Higher_Temp) + a2*Higher_Temp + (a3*Higher_Temp)/2 + (a4*Higher_Temp)/3 + (a5*Higher_Temp)/4 + a7)*R
S_Low = (a8*log(Lower_Temp) + a9*Lower_Temp + (a10*Lower_Temp)/2 + (a11*Lower_Temp)/3 + (a12*Lower_Temp)/4 + a14)*R

Molecular_Weight(y) = molecular_weight(tlin0) ;
mkdir(['D:',tlin0])
cd(['D:',tlin0])
figure(1)
plot(Lower_Temp,Cp_Low,'linewidth',3)
hold on
plot(Higher_Temp,Cp_High,'linewidth',3)
hold off
saveas(gcf,'file1.png')

figure(2)
plot(Lower_Temp,H_Low,'linewidth',3)
hold on
plot(Higher_Temp,H_High,'linewidth',3)
hold off
saveas(gcf,'file2.png')

figure(3)
plot(Lower_Temp,S_Low,'linewidth',3)
hold on
plot(Higher_Temp,S_High,'linewidth',3)
hold off
saveas(gcf,'file3.png')
cd .. 
end


%coad for molecular weight

function MW = molecular_weight(tline0)

elements = ['H','C','N','A','S']
atomic_wt = [1.00 12.01 15.99 14.00 39.95 32.06];

MW = 0;
for i = 1:length(tline0);
    for j = 1:length(elements);
        if strcmp(tline0(i),elements(j))
            
            MW = MW + atomic_wt(j);
            a = j;
       
    
    n = str2num(tline0(i));
    
    if n>1
        MW = MW + atomic_wt(a)*(n-1);
    end
end 
end
end
end











explanation:-

1)assigning universal gas constant
2)taking or reading global temperatures
3)skipping commant lines
4)reading local temperatures
5)reading 1st,2nd,3rd,lines of data file
6)coding for cp,H,S values
7)creating a function for molecular weight
8)plotting temp vs cp,temp vs H,temp vs S for all elements

graph for o

screen shot of all plot folders:

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.