Challenge

Project 1 - Parsing NASA thermodynamic data

clear all
close all
clc

% Reading the NASA Thermodynamic data file using 'fopen' function
f1= fopen('THERMO.dat','r');

%'fgetl' is used to read the data file line by line.
% First 5 lines are generally considered as comments. also global temperature data we are not using for calculation.
for m = 1:5 
    comment_line = fgetl(f1);
end

%Defining Universal Gas constant
R = 8.3145;         %in J/mol-K 

%Reading all species individually
for j = 1:53
    tline = fgetl(f1);
    A = strsplit(tline,' '); 
    species_name = (A{1});
    
    %Reading Local Temperature for each species
    local_low_temp   = str2num(A{end-3});
    local_high_temp  = str2num(A{end-2});
    local_mid_temp   = str2num(A{end-1});
    
    %Reading 1st line of Temperature values
    tline = fgetl(f1);
    a = findstr(tline,'E');
    
    %Converting the string of values to number
    a1 = tline(1:a(1)+3);
    a1 = str2num(a1);
    a2 = tline(a(1)+4:a(2)+3);
    a2 = str2num(a2);
    a3 = tline(a(2)+4:a(3)+3);
    a3 = str2num(a3);   
    a4 = tline(a(3)+4:a(4)+3);
    a4 = str2num(a4);    
    a5 = tline(a(4)+4:a(5)+3);
    a5 = str2num(a5);
    
    %Reading 2nd line of Temperature values
    tline = fgetl(f1);
    a = findstr(tline,'E');
    
    %Converting the string of values to number
    a6  = tline(1:a(1)+3);
    a6  = str2num(a6);
    a7  = tline(a(1)+4:a(2)+3);
    a7  = str2num(a7);
    a8  = tline(a(2)+4:a(3)+3);
    a8  = str2num(a8);    
    a9  = tline(a(3)+4:a(4)+3);
    a9  = str2num(a9);    
    a10 = tline(a(4)+4:a(5)+3);
    a10 = str2num(a10);
    
    %Reading 3rd line of Temperature values
    tline = fgetl(f1);
    a = findstr(tline,'E');
    
    %Converting the string of values to number
    a11 = tline(1:a(1)+3);
    a11 = str2num(a11);
    a12 = tline(a(1)+4:a(2)+3);
    a12 = str2num(a12);
    a13 = tline(a(2)+4:a(3)+3);
    a13 = str2num(a13);    
    a14 = tline(a(3)+4:a(4)+3);
    a14 = str2num(a14);    
    
    %Defining Temperature range for calculations
    T = linspace(local_low_temp,local_high_temp,1000);
    
    %Calculating Specific Heat, Enthalpy, Entropy and Molecular Weight
    Cp = specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,R,T,local_mid_temp);
    
    H = Enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,R,T,local_mid_temp);
    
    S = Entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,R,T,local_mid_temp);
    
    M = molecular_weight(species_name);
    
    %Creating separate Directory to store graphs and values of each species
    cd('D:/Anoop/Matlab/File parsing');
    mkdir(species_name);
    cd(species_name);

    %Writing Molecular Weight to a text file
    M_file = fopen('Molecular Weight.txt','w');
    fprintf(M_file,'Molecular Weight of %s is %d',species_name,M);
    fclose(M_file);
    
    %Plotting Temperature VS Specific Heat graph and Saving
    figure(1)
    plot(T,Cp,'linewidth',1.5,'color','r');
    xlabel('Temperature (K)');
    ylabel('Specific Heat (KJ)');
    title(sprintf('Temperature vs Specific Heat of %s',species_name))
    grid on
    saveas(figure(1),'Specific Heat.jpg');
    
    %Plotting Temperature VS Enthalpy graph and Saving
    figure(2)
    plot(T,H,'linewidth',1.5,'color','b');
    xlabel('Temperature (K)');
    ylabel('Enthalpy (KJ/mol)');
    title(sprintf('Temperature vs Enthalpy of %s',species_name))
    grid on
    saveas(figure(2),'Enthalpy.jpg');
    
    %Plotting Temperature VS Entropy graph and Saving
    figure(3)
    plot(T,S,'linewidth',1.5,'color','g');
    xlabel('Temperature (K)');
    ylabel('Entropy (KJ/mol-K)');
    title(sprintf('Temperature vs Entropy of %s',species_name))
    grid on
    saveas(figure(3),'Entropy.jpg');
    
    %Changing Directory to Original Directory
    cd('D:/Anoop/Matlab/File parsing');
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.