Challenge

Project 1 - Parsing NASA thermodynamic data

PROJECT 1:-

AIM: - To write a function that extracts the 14 co-efficient and calculates the enthalpy, entropy and specific heats for all the species in the NASA data file.

PROCEDURE: -

  1. Load the ‘THERMO’ file using the ‘fopen’ command that contains all the temperature coefficients.
  2. Use the ‘fgetl’ command to read the lines given in the DATA sheet.
  3. We take the Global Temperature ranges by converting the string into a set of substrings using the ‘strsplit’.
  4. In order to load these data we need to convert these strings into numbers by ‘str2num’.
  5. Load the universal gas constant value as it will play a major role ahead.
  6. We are going to evaluate the values of all the species in this program, so we will create a forloop and write our program in it.
  7. With the help of ‘strsplit’ and’str2num’ we convert and load the temperature ranges of oxygen and save the in terms as Local temperatures ranges.
  8. After going another level down we load all the 14 coefficients and save from A1 to A14.
  9. A vector is created for the Local Temperature range.
  10. The Values of specific heat, Enthalpy and Entropy are calculated using the above Formulae.
  11. Graphs are plotted for Temperature vs Specific heat, enthalpy and entropy along with labels.
  12. To calculate molecular mass a separate function program is written
  13. Create a Vector for atoms and all its atomic weight.
  14. Create a variable 'mm' which will store the mass and state its initial Value as zero.
  15. Two forloops are created for title and atoms
  16. 'if' loop is created to check if the atomic number matches the forloop condition it should store the atomic weight.
  17. sprintf is used to print the value of molecular mass
  18. The program is run successfully. The graphs are plotted and Molecular mass values are also noted.
    %Molecular weight calculation
    function mm=molecular_mass(Title)
    atoms = ['H','C','N','O','A','S'];%Array for Elements
    at_wt = [1,12,14,16,20,32];%Array for atomic weight
    mm=0;%Mass counter
    %Forloop creation for identifying and calculating Molar weights 
    for i=1:length(Title) 
        for x=1:length(atoms)
            if(strcmpi(Title(i),atoms(x)))%Statement for identifying the individual element
                mm=mm+at_wt(x);
                pos=x;
            end
        end
        n= str2num(Title(i));
        if n>1
            mm=mm+at_wt(pos)*(n-1);
        end
    end
    sprintf('Molecular Mass = %f',mm)
    end
    -----------------------------------------------------------------------------------------
    clear all 
    close all
    clc
    
    %Loading the Datasheet
    f1 = fopen('THERMO.dat','r');
    %Reading the first Line
    fgetl(f1);
    %Reading and saving the first line as string
    tline = fgetl(f1);
    %Split the elements of a character vector 'tline' into substrings
    A = strsplit(tline,' ');
    %Loading the data for Global temperature levels
    Global_low_temp = A(2);
    Global_low_temp = str2num(A{2});
    Global_mid_temp = str2num(A{3});
    Global_high_temp = str2num(A{4});
    R = 8.314;
    %Creating a Forloop to get upto O values
    for i = 1:3
    fgetl(f1);
    
    end
     for j = 1:53
    %Split the elements of a character vector 'tline' into substrings
    aline=fgetl(f1);
    J = strsplit(aline,' ');
    %Alloting local Co-efficients
    Title = sprintf(J{1});
    Local_low_temp = str2num(J{end-3});
    Local_high_temp = str2num(J{end-2});
    Local_mid_temp = str2num(J{end-1});
    %Loading the Co-efficients
    %Calculating parameters 1.Specific heat 2.Enthalpy 3.Entropy
    uline = fgetl(f1);
    
    %Loading Co-efficients values from A1 to A5
    B = findstr(uline,'E');
    a1 = uline(1:B(1)+3);
    a2 = uline(B(1)+4:B(2)+3);
    a3 = uline(B(2)+4:B(3)+3);
    a4 = uline(B(3)+4:B(4)+3);
    a5 = uline(B(4)+4:B(5)+3);
    
    %Loading Co-efficients values from A6 to A10
    vline = fgetl(f1);
    D = findstr(vline,'E'); 
    a6 = vline(1:B(1)+3);
    a7 = vline(B(1)+4:B(2)+3);
    a8 = vline(B(2)+4:B(3)+3);
    a9 = vline(B(3)+4:B(4)+3);
    a10 = vline(B(4)+4:B(5)+3);
    
    %Loading Co-efficients values from A11 to A14
    mline = fgetl(f1);
    D = findstr(mline,'E'); 
    a11 = mline(1:B(1)+3);
    a12 = mline(B(1)+4:B(2)+3);
    a13 = mline(B(2)+4:B(3)+3);
    a14 = mline(B(3)+4:B(4)+3);
    
    %Converting String Values to numbers
    A1 = str2num(a1);
    A2 = str2num(a2);
    A3 = str2num(a3);
    A4 = str2num(a4);
    A5 = str2num(a5);
    A6 = str2num(a6);
    A7 = str2num(a7);
    A8 = str2num(a8);
    A9 = str2num(a9);
    A10 = str2num(a10);
    A11 = str2num(a11);
    A12 = str2num(a12);
    A13 = str2num(a13);
    A14 = str2num(a14);
    
    %Creating An array for Temperature Range
    T = linspace(Local_low_temp,Local_high_temp,100);
    %Calculating Values of Specific heat,Enthalpy,Entropy
    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)).*(T*R);
    S = (A1.*log(T)+(A2.*T)+(A3.*T.^2/2)+(A4.*T.^3/3)+(A5.*T.^4/4)+A7)*R;
    
    %Plotting
    %Calculation of Temperature and Specific heat
    figure(1)
     plot(T,Cp)
     xlabel('Temperature')
     ylabel('Specific heat')
     title(Title)
    %Calculation of Temperature and Emthalpy
     figure(2)
     plot(T,H)
     xlabel('Temperature')
     ylabel('Enthalpy')
     title(Title)
    %Calculation of Temperature and Entropy
     figure(3)
     plot(T,S)
     xlabel('Temperature')
     ylabel('Entropy')
     title(Title)
     %Creation of folders to save the programs
     mkdir(Title)
     cd(Title)%Change of directory
     saveas(1,'Specific Heat.jpg')
     saveas(2,'Enthalpy.jpg')
     saveas(3,'Entropy.jpg')
     cd ..%Returning back to the original directory
     mol_mass=molecular_mass(Title);% Calculation of Molecular Mass
     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.

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.