Project

Project 1 - Parsing NASA thermodynamic data

clear all
close all
clc

f1=fopen(\'THERMO.dat\',\'r\');
Title=fgetl(f1);


gt=strsplit(fgetl(f1),\' \');
global_min_temp=str2double(gt{2});
global_mid_temp=str2double(gt{3});
global_max_temp=str2double(gt{4});
R=8.314;
temp=linspace(300,5000,100);
%to avoid the next 3 lines
for i=1:3
    fgetl(f1);
end

for j=1:53
   intro= fgetl(f1);
   species=intro(1:6);
   local_temp_range=strfind(intro,\'G\');
   local_min_temp=intro(local_temp_range(1)+4:local_temp_range(1)+10);
   local_min_temp=str2double(local_min_temp);
   local_max_temp=intro(local_temp_range(1)+13:local_temp_range(1)+20);
   local_max_temp=str2double(local_max_temp);
   local_mid_temp=intro(local_temp_range(1)+23:local_temp_range(1)+30);
   local_mid_temp=str2double(local_mid_temp);
   local_temp=linspace(local_min_temp,local_max_temp,100);
   tline1=fgetl(f1);
   a=strfind(tline1,\'E\');
   a1=tline1(1:a(1)+3);
   a1=str2double(a1);
   a2=tline1(a(1)+4:a(2)+3);
   a2=str2double(a2);
   a3=tline1(a(2)+4:a(3)+3);
   a3=str2double(a3);
   a4=tline1(a(3)+4:a(4)+3);
   a4=str2double(a4);
   a5=tline1(a(4)+4:a(5)+3);
   a5=str2double(a5);
   
   
   tline2=fgetl(f1);
   a=strfind(tline2,\'E\');
   a6=tline2(1:a(1)+3);
   a6=str2double(a6);
   a7=tline2(a(1)+4:a(2)+3);
   a7=str2double(a7);
   a8=tline2(a(2)+4:a(3)+3);
   a8=str2double(a8);
   a9=tline2(a(3)+4:a(4)+3);
   a9=str2double(a9);
   a10=tline2(a(4)+4:a(5)+3);
   a10=str2double(a10);
   
   tline3=fgetl(f1);
   a=strfind(tline3,\'E\');
   a11=tline3(1:a(1)+3);
   a11=str2double(a11);
   a12=tline3(a(1)+4:a(2)+3);
   a12=str2double(a12);
   a13=tline3(a(2)+4:a(3)+3);
   a13=str2double(a13);
   a14=tline3(a(3)+4:a(4)+3);
   a14=str2double(a14);
   species
   molecular_weight=molecular_wt(species)
   
   if temp>=global_mid_temp
    cp=R.*( a1+a2.*temp+a3.*temp.^2+a4.*temp^.3+a5.*temp.^4);
    h=(R.*temp).*(a1+(a2.*temp)/2+(a3.*temp.^2)/3+(a4.*temp.^3)/4+(a5.*temp.^4)/5+a6./temp);
    s=R.*(a1.*log(temp)+(a2.*temp)+(a3.*temp.^2)/2+(a4.*temp.^3)/3+(a5.*temp.^4)/4+a7);
else
    cp=R.*(a8+a9.*temp+a10.*temp.^2+a11.*temp.^3+a12.*temp.^4);
    h=(R.*temp).*(a8+(a9.*temp)/2+(a10.*temp.^2)/3+(a11.*temp.^3)/4+(a12.*temp.^4)/5+a13./temp);
    s=R.*(a8.*log(temp)+(a9.*temp)+(a10.*temp.^2)/2+(a11.*temp.^3)/3+(a12.*temp.^4)/4+a14);
   end
   figure(1)
   plot(local_temp,cp,\'linewidth\',3,\'color\',[1 0 1])
   xlabel(\'local temperature range\');
   ylabel(\'specific heat at contant pressure\');
   title([\'Temperaure vs Cp of  \',num2str(species)]);
   
   figure(2)
   plot(local_temp,h,\'linewidth\',3,\'color\',[1 0 1])
   xlabel(\'local temperature range\');
   ylabel(\'enthalpy\');
   title([\'Temperaure vs H of  \',num2str(species)]);
   
   figure(3)
   plot(local_temp,s,\'linewidth\',3,\'color\',[1 0 1])
   xlabel(\'local temperature range\');
   ylabel(\'entropy\');
   title([\'Temperaure vs S of  \',num2str(species)]);
   
   mkdir([\'C:\\Users\\Haseeb Ahmad\\Pictures\\File Parsing\\Species\\Data of Species \',species])
   cd([\'C:\\Users\\Haseeb Ahmad\\Pictures\\File Parsing\\Species\\Data of Species \',species])
   saveas(1,\'Teperature vs Cp.jpg\')
   saveas(2,\'Teperature vs H.jpg\')
   saveas(3,\'Temperature vs S.jpg\')
   cd([\'C:\\Program Files\\Polyspace\\R2019b\\bin\'])
end



function [MW]=molecular_wt(species)
species;
atom=[\'H\' ,\'C\' ,\'N\' , \'O\' ,\'S\' ,\'A\'];
Atomic_Weight=[1 12 14 16 32 40];
 
MW=0;
for i=1:length(species)
  for  j=1:length(Atomic_Weight)
    if (strcmpi(species(i),atom(j))==1)
        MW=MW+Atomic_Weight(j);
        atom_assigned=j;
    end
  end
 
    p=str2double(species(i));
    if p>1
    MW=MW+(Atomic_Weight(atom_assigned)*(p-1));
    end
end
end

        

\"q\"

\"w\"

\"e\"

\"r\"

\"t\"

\"y\"

\"p\"

\"o\"

\"i\"

\"1\"

As the pictures of the Command Wndow displaying molecular weights were too much therefore only 4 are being provided.

\"a\"

\"b\"

\"c\"

\"d\"

the program is case insentive.

\"47\"

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.