Challenge

Project 1 - Parsing NASA thermodynamic data

close all
clear all
clc
% opening the files for NASA THERMO DATAS 

% Reading the header datas for the THERMO.DATA file 

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

% spliting the strings 

Global_temperatues = strsplit(Global_temps,' ');

% storing the cell strings into varibels in numbers form 
% we can use the strings to numbers command for this 

low_temp = str2num(Global_temperatues{2})
mid_temp = str2num(Global_temperatues{3})
high_temp = str2num(Global_temperatues{4})

% now after storing the global temps datas now we can skip the 3 commands
% lines for that fgetl command can be use 

fgetl(Nasa_themo_datas);
fgetl(Nasa_themo_datas);
fgetl(Nasa_themo_datas);

% running it for 3 time will get the all three files of commands 

% now we can read the species datas 

% reading the data for O2 species 
fgetl(Nasa_themo_datas);
fgetl(Nasa_themo_datas);
fgetl(Nasa_themo_datas);
fgetl(Nasa_themo_datas);

% O2 species 
% generating local temperature ranges for the O2 species 
initial_condition_O2 = fgetl(Nasa_themo_datas);
local_temp_O2 = strsplit(initial_condition_O2,'  ');
low_local_temp_O2 = str2num(local_temp_O2{5});
mid_local_temp_O2 = str2num(local_temp_O2{7})
high_local_temp_O2 = str2num(local_temp_O2{6})

% getting the co-efficients for the O2 species 

Fist_coeffs = fgetl(Nasa_themo_datas);
First_five = findstr(Fist_coeffs,'E');
% First Co-efficient 
C1 = Fist_coeffs(1:First_five(1)+3);
C1 = str2num(C1)

% Finding the second Coefficents 
C2 = Fist_coeffs(First_five(1)+4:First_five(2)+3);
C2 = str2num(C2)

% Finding the Third Coefficents 
C3 = Fist_coeffs(First_five(2)+4:First_five(3)+3);
C3 = str2num(C3)

% Finding the fourth Coefficents 
C4 = Fist_coeffs(First_five(3)+4:First_five(4)+3);
C4 = str2num(C4)

% Finding the Fifth Coefficents 
C5 = Fist_coeffs(First_five(4)+4:First_five(5)+3);
C5 = str2num(C5)

% Since the next co-effiecent are in the next line so, 

Next_five_coeffs = fgetl(Nasa_themo_datas);
Next_fives = findstr(Next_five_coeffs,'E');

% sixth Co-efficient 

C6 = Next_five_coeffs(1:Next_fives(1)+3);
C6 = str2num(C6)

% seventh Co-efficient 

C7 = Next_five_coeffs(Next_fives(1)+4:Next_fives(2)+3);
C7 = str2num(C7)

% Eighth Co-efficient 

C8 = Next_five_coeffs(Next_fives(2)+4:Next_fives(3)+3);
C8 = str2num(C8)

% Ninth Co-efficient 

C9 = Next_five_coeffs(Next_fives(3)+4:Next_fives(4)+3);
C9 = str2num(C9)

% Tenth Co-efficient 

C10 = Next_five_coeffs(Next_fives(4)+4:Next_fives(5)+3);
C10 = str2num(C10)

% we'll repeat the same process to get the rest 4 co-efficients 

Rest_Four_Coeff = fgetl(Nasa_themo_datas);
Rest_four = findstr(Rest_Four_Coeff,'E');

% 11th Co-efficient

C11 = Rest_Four_Coeff(1:Rest_four(1)+3);
C11 = str2num(C11)

% 12th Co-efficient

C12 = Rest_Four_Coeff(Rest_four(1)+4:Rest_four(2)+3);
C12 = str2num(C12)

% 13th Co-efficient

C13 = Rest_Four_Coeff(Rest_four(2)+4:Rest_four(3)+3);
C13 = str2num(C13)

% 14th Co-efficient

C14 = Rest_Four_Coeff(Rest_four(3)+4:Rest_four(4)+3);
C14 = str2num(C14)

% Since the first seven co-efficients are for low temperature and last
% seven coefficients are used for high temperature 


% entropy of the system is given by 
% S/R = C1*lnT + C2*T + C3*T^2/2 + C4*T^3/3 + C5*T^4/4

% Enthalpy of the system is given by 
% H/RT = C1 + C2*T/2 + C3*T^2/3 + C4*T^3/4 + C5*T^4/5 + C6*T^5/6

% Specific heat of the system is given by 
% Cp/R = C1 + C2*T + C3*T^2 + C4*T^3 + C5*T^4

% Universal gas constant R 
R = 8.314;
% Calculating entropy, enthalpy and specific heat and for low temperature 

% calculation the entropy 
 S_low= (C1*log(low_local_temp_O2) + C2*low_local_temp_O2 + (C3*(low_local_temp_O2)^2)/2 + (C4*(low_local_temp_O2)^3/3) + (C5*(low_local_temp_O2)^4/4) + C7)*R

% calculation the Enthalpy 
H_low = (C1 + (C2*(low_local_temp_O2))/2 + (C3*(low_local_temp_O2)^2)/3 + (C4*(low_local_temp_O2)^3)/4 + (C5*(low_local_temp_O2)^4)/5 + (C6*(low_local_temp_O2)^5)/6)*(R*low_local_temp_O2)

% Calculation the Specific heat 

Cp_low = (C1 + C2*low_local_temp_O2 + C3*((low_local_temp_O2)^2) + C4*((low_local_temp_O2)^3) + C5*((low_local_temp_O2)^4))*R

% Calculating entropy, enthalpy and specific heat and for High temperature

% calculation the entropy 
 S_high= (C8*log(high_local_temp_O2) + C9*high_local_temp_O2 + (C10*(high_local_temp_O2)^2)/2 + (C11*(high_local_temp_O2)^3/3) + (C12*(high_local_temp_O2)^4/4) + C14)*R

% calculation the Enthalpy 
H_high = (C8 + (C9*(high_local_temp_O2))/2 + (C10*(high_local_temp_O2)^2)/3 + (C11*(high_local_temp_O2)^3)/4 + (C12*(high_local_temp_O2)^4)/5 + (C13*(high_local_temp_O2)^5)/6)*(R*high_local_temp_O2)

% Calculation the Specific heat 

Cp_high = (C8 + C9*high_local_temp_O2 + C10*((high_local_temp_O2)^2) + C11*((high_local_temp_O2)^3) + C12*((high_local_temp_O2)^4))*R

% Calculating entropy, enthalpy and specific heat and for range from low and High temperature
temp_range = linspace(low_local_temp_O2,high_local_temp_O2,100);
for i = 1:length(temp_range)
    tem_range1 = temp_range(i);
    if tem_range1 <=  1000;
        S(i) = (C1*log(tem_range1) + C2*tem_range1 + (C3*(tem_range1)^2)/2 + (C4*(tem_range1)^3/3) + (C5*(tem_range1)^4/4) + C7)*R;
    else 
        S(i) = (C8*log(tem_range1) + C9*tem_range1 + (C10*(tem_range1)^2)/2 + (C11*(tem_range1)^3/3) + (C12*(tem_range1)^4/4) + C14)*R;
    end
end

for i = 1:length(temp_range)
    tem_range1 = temp_range(i);
    if tem_range1 <= 1000;
        H(i) = (C1 + (C2*(tem_range1))/2 + (C3*(tem_range1)^2)/3 + (C4*(tem_range1)^3)/4 + (C5*(tem_range1)^4)/5 + (C6*(tem_range1)^5)/6)*(R*tem_range1);
    else 
        H(i) = (C8 + (C9*(tem_range1))/2 + (C10*(tem_range1)^2)/3 + (C11*(tem_range1)^3)/4 + (C12*(tem_range1)^4)/5 + (C13*(tem_range1)^5)/6)*(R*tem_range1);
    end
end

     for i = 1:length(temp_range)
    tem_range1 = temp_range(i);
    if tem_range1 <= 1000;
         Cp(i) = (C1 + C2*tem_range1 + C3*((tem_range1)^2) + C4*((tem_range1)^3) + C5*((tem_range1)^4))*R;
    else 
         Cp(i) = (C8 + C9*tem_range1 + C10*((tem_range1)^2) + C11*((tem_range1)^3) + C12*((tem_range1)^4))*R;
    end
     end

figure(1)
plot(temp_range,S,'LineWidth',2,'Color','r')
legend('Entropy change VS temperature')
figure(2)
plot(temp_range,H,'LineWidth',2,'Color','g')
legend('Enthalpy change VS temperature')
figure(3)
plot(temp_range,Cp,'LineWidth',2,'Color','b')
legend('Specific heat VS temperature')
xlabel('temperature')
ylabel('values')

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.