Challenge

Project 1 - Parsing NASA thermodynamic data

clear all
close all.
clc

%Make directory
mkdir'C:UsersAdminDesktopNASA File Parsing'

%Reading Data file-NASA Thermodynamic
%Openafile&'r'Open the file for reading

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

%Obtaing Temperatures by Reading Header Information
global_temp=fgetl(f1);

%Spliting
t=strsplit(global_temp);

%Converting string cells to numbers using str2num,
global_low_temp=str2num(t{2});
global_medium_temp=str2num(t{3});
global_high_temp=str2num(t{4});

%Temperature range&Gas Constant
%Temperature Range assumed
Temp=linspace(global_low_temp,global_high_temp,1000);

%Universal Gas ConstantJ/(mo1-K)
R=8.314;

%skipping three comment lines in the file
fori=1:3
    gt=fgetl(f1);

end.

fori=1:53
gt=fgetl(f1);
A=strsplit(gt,'');
Species_SP=(A[1})

line1-fgetl(f1);
a=strfind(line_1,'E');

%Extracting higher and lower temperature coefficients

%%Extracting FIRST7coefficients i.e HIGH-temperature coefficients
al-line_1(1:a(1)+3);
al-str2num(a1);%1
a2-line_1(a(1)+4:a(2)+3);
a2-str2num(82);%2
a3-line_1(a(2)+4:a(3)+3);
a3-str2num(a3);%3
a4-line_1(a(3)+4:a(4)+3);
a4-str2num(84);
as-line_1(a(4)+4:a(5)+3);
a5=str2num(as);%5
line_2=fgetl(f1);

b-strfind(line1,'E');;
a6-line_2(1:b(1)+3);
a6=str2num(86);%6
a7-line_2(a(1)+4:b(2)+3);
a7=str2num(87);%7

%Extracting SECOND7coefficients-LOW-temperature coefficients
as-line_2(b(2)+4:b(3)+3);
a8=str2num(as);%8
a9-line_2(b(3)+4:b(4)+3);
a9-str2num(89);%9
a10=line_2(b(4)+4:b(5)+3);
a10=str2num(a10);%10

line_3=fgetl(f1);
c=strfind(line_1,'E');
a11=line_3(1:c(1)+3);
a11-str2num(a11);
a12-line_3(c(1)+4:C(2)+3);
a12-str2num(a12);
a13=line_3(c(2)+4:C(3)+3);
a13=str2num(a13);
a14=line_3(c(3)+4:C(4)+3);
a14-str2num(a14);

%Specific heat calculation
    Cp=Specificheat(al,a2,a3,a4,a5,a8,a9,ale,a11,a12,Temp,R,global_medium_temp);

    %Enthalpy calculation
    H=Enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,Temp,R,global_medium_temp);

    %Entropy calculation.
    S=Entropy_calc(al,a2,a3,a4,a5,a7,a8,a9,ale,a11,a12,a14,Temp,R,global_nedium_temp);

   XCalculating molecular weight of species
   Molecularweight(1)Molecular weight(Species_SP);

    %Read&Write Molecular list
     Molecular_list=fopen('Molecular weight.txt','a+');
         fprintf(Molecular_list,'Molecular weight of%sis%dn',Species_SP,Molecularweight);
         fclose(Molecular_list);

     %plotting(CP,H,S,Temp,Species_SP)
        %Saving asafolder
           cur_dir=pwd;
           mkdir(Species_SP);
           cd(Species_SP);

        %Plot1,Specific heat(CP)vs Temperature Range(Temp)
        figure(1)
        plot(Temp,Cp,linewidth",2,"color","r');
        xlabel('Temperature[K]');
        ylabel('Specific Heat[k]]');
        title(sprintf('Varying Specific Heat with Temperature Range of%s,Species_SP));
        grid on
        saveas(figure(1),'Specific Heat.jpg");

        %Plot2,Enthalpy(H)vs Temperature Range(Temp).
        figure(2)
        plot(Temp,H,'linewidth",2,"color','g');
        xlabel('Temperature[K]');
        ylabel('Enthalpy in[k3/(mol)]');
        title(sprintf("Varying Enthalpy with Temperature Range of%s',Species_SP));
        grid on
        saveas(figure(2),'Ethalpy.jpg');

        %Plot3,Entropy(5)vs Temperature Range(Temp)
        figure(3)
        plot(Temp,5,'linewidth",2,"color','b');
        xlabel('Temperature[K]');
        ylabel('Entropy in[k]/(mol-K)]');
        title(sprintf('Varying Entropy with Temperature Range of%s',Species_SP));
        grid on
        saveas(figure(3),'Entropy.jpg');

        cd(cur_dir);
 
         %Molecular weight
         MMolecular weight(Species_SP)
         +2=fopen('molecular mass","w');
         fprintf('%sn%sn%fn','species","Molecular mass,M)
         fclose(+2)

         end
         
                                

Code Explanation:


1. 'clear all'-clear all the variables in the workspace,
'close all'-closes all the plots and figures and
'clc'-clears the command window.

2. Makingadirectory using 'mkdir' with location address.

3. After that,reading the text file 'Thermo.dat'file and open it by using 'fopen'and'r'as reading command.

4. For reading the line in a text file using 'fgetl'.

5. To obtain the temperature range from the Thermo.dat file,using 'strsplit'to split the temperature into a
particular string cell.

6. Used'str2num'for converting string cells to numbers.

7. Divided the temperature into a string and then converted it to a number so that temperature values can be used
separately to solve the NASA thermodynamics.

8. Using'for&end'loops to skip the next three comment lines in the text file.

9. Reading all the 53 species to plot specific heat(cp), enthalpy(H), and entropy(S), with temperature values, and
to find the molecular weights.

10. Used'for'loop to read 53 species.

11. Used'strfind'to find string.

12. Using'linspace'specified the temperature range from low to high.

13. Adding universal gas constant value'R'.

14. Extracted higher and lower temperature coefficients by reading line by line from the species.

15. Calling specific heat, enthalpy, and entropy function codes.

16. Calculating Molecular weight.

Output:

>> Molecular weight AR
The molecular weight of AR: molecular weight AR:3.994800E+01
ans=
39.9480

>> Molecular weightC
Molecular weight ofC:molecular weightC:1.201100e+01
ans=
12.0110

>> Molecular weight C2H
The molecular weight of C2H: molecular weight C2H:2.503000E+01
ans=
25.0300

>> Molecular_weight C2H2
Molecular weight of C2H2:molecular weight C2H2:2.603800e+01
ans=
26.0380

>> Molecular weight C2H3
Molecular weight of C2H3:molecular weight C2H3:2.704600E+01
ans=
27.0460

>> Molecular_weight C2H4
Molecular weight of C2H4:molecular weight C2H4:2.805400E+01
ans=
28.0540

>> Molecular_weight C2H5
Molecular Weight of C2H5:molecular weight C2H5:2.906200e+01
ans=
29.0620

>> Molecular_weight C2H6
Molecular weight of C2H6:molecular weight C2H6:3.007000E+01
ans=
30.0700

>> Molecular_weight C3H7
Molecular weight of C3H7 molecular weight C3H7:4.308900e+01
ans=
43.0890

>> Molecular weight C3H8
Molecular weight of C3H8:molecular weight C3H8:4.409700E+01
ans=
44.0970

>> Molecular weight CH
Molecular Weight of CH: molecular weight CH:1.301900e+01
ans=
13.0190

>> Molecular weight CH2
Molecular weight of CH2 molecular weight CH2:1.402700E+01
ans=
14.0270

>> Molecular_weight CH2(S)
Molecular weight of CH2(S):molecular weight CH2(S):1.402700e+01
ans=
14.0270

>> Molecular weight CH2CHO
Molecular weight of CH2CHO:molecular weight CH2CHO:4.304500e+01
ans=
43.0450

>> Molecular weight CH2CO
Molecular Weight of CH2CO:molecular weight CH2CO:4.203700+01
ans=
42.0370

>> Molecular weight CH20
Molecular weight of CH20:molecular weight CH20:3.002600e+01
ans=
30.0260

>> Molecular weight CH2OH
Molecular weight of CH2OH:molecular weight CH2OH:3.103400E+01
ans=
31.0340

>> Molecular weight CH3
Molecular weight of CH3 molecular weight CH3:1.503500+01
ans=
15.0350

>> Molecular weight CH3CHO
Molecular Weight of CH3CHO molecular weight CH3CHO:4.405300E+01
ans=
44.0530

>> Molecular weight CH30
Molecular Weight of CH30:molecular weight CH30:3.103400+01
ans=
31.0340

>> Molecular weight CH3OH
Molecular Weight of CH3OH molecular weight CH3OH:3.204200+01
ans=
32.0420

>> Molecular weight CH4
Molecular weight of CH4 molecular weight CH4:1.604300e+01
ans=
16.0430

>> Molecular weight CN
Molecular Weight of CN molecular weight CN:2.601800e+01
ans=
26.0180

>> Molecular weight Co
Molecular weight of CO molecular weight CO:2.801000E+01
ans=
28.0100

>> Molecular weight CO2
Molecular weight of CO2:molecular weight CO2:4.400900e+01
ans=
44.0090

>> Molecular weightH
Molecular weight ofH:molecular weightH:1.008000e+00
ans=
1.0080

>> Molecular weight H2
Molecular weight of H2 molecular weight H2:2.016000E+00
ans=
2.0160

>> Molecular weight H2CN
Molecular weight of H2CN molecular weight H2CN:2.803400+01
ans=
28.0340

>> Molecular weight H20
Molecular Weight of H20 molecular weight H20:1.801500e+01
ans=
18.0150

>> Molecular weight H202
Molecular Weight of H202 molecular weight H202:3.401400e+01
ans=
34.0140

>> Molecular weight HCCO
Molecular Weight of HCCO molecular weight HCCO:4.102900e+01
ans=
41.0290

>> Molecular weight HCCOH
Molecular Weight of HCCOH molecular weight HCCOH:4.203700E+01
ans=
42.0370

>> Molecular weight HCN
Molecular Weight of HCN molecular weight HCN:2.702600e+01
ans= 27.0260


>> Molecular weight HCNN
Molecular Weight of HCNN molecular weight HCNN:4.103300e+01
ans=
41.0330

>> Molecular weight HCNO
Molecular Weight of HCNO molecular weight HCNO:4.302500E+01
ans=
43.0250

>> Molecular_weight HCO
Molecular Weight of HCO molecular weight HCO:2.901800+01
ans=
29.0180

>> Molecular weight HNCO
Molecular weight of HNCO:molecular weight HNCO:4.302500E+01
ans=
43.0250

>> Molecular_weight HNO
Molecular weight of HNO:molecular weight HNO:3.101400E+01
ans=
31.0140

>> Molecular weight H02
Molecular Weight of H02:molecular weight H02:3.300600e+01
ans=
33.0060

>> Molecular weight HOCN
Molecular weight of HOCN:molecular weight HOCN:4.302500E+01
ans=
43.0250

>> Molecular_weightN
Molecular Weight ofN:molecular weightN:1.400700E+01
ans=
14.0070

>> Molecular weight N2
Molecular weight of N2:molecular weight N2:2.801400E+01
ans=
28.0140

>> Molecular weight N20
Molecular Weight of N20:molecular weight N20:4.401300e+01
ans=
44.0130

>> Molecular_weight NCO
Molecular Weight of NCO molecular weight NCO:4.201700+01
ans=
42.0170

>> Molecular_weight NH
Molecular weight of NH:molecular weight NH:1.501500E+01
ans=
15.0150

>> Molecular weight NH2
Molecular weight of NH2 molecular weight NH2:1.602300E+01
ans=
16.0230

>> Molecular weight NH3
Molecular Weight of NH3:molecular weight NH3:1.703100+01
ans=
17.0310

>> Molecular_weight NNH
Molecular Weight of NNH:molecular weight NNH:2.902200e+01
ans=
29.0220

>> Molecular weight NO
Molecular weight of NO molecular weight NO:3.000600E+01
ans=
30.0060

>> Molecular weight NO2
Molecular weight of NO2:molecular weight NO2:4.600500e+01
ans=
46.0050

>> Molecular weight0
Molecular weight of0:molecular weight0:1.599900E+01
ans=
15.9990

>> Molecular_weight 02
Molecular Weight of 02:molecular weight 02:3.199800E+01
ans=
31.9980

>> Molecular_weight OH
Molecular Weight of OH:molecular weight OH:1.700700E+01
ans=
17.0070

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.