Challenge

Project 1 - Parsing NASA thermodynamic data

Challenge Title:- To collect the species of NASA THERMODYNAMIC mono atomic variable using the file name 'Thermo.dat'

Explaination:-The objective is collect the 53 species in to one folder and to plot the graph temperature vs enthalpy , temperature vs entropy , temperature vs specific heat

in this code 1st we are collecting the gobal temperture

next 5lines we can skip

from the next line we have mono atomic values with local temperatures and the specimen values

clear all
close all
clc
f1 = fopen('THERMO.dat','r')  % speciemens input fie
for i=1:5
    fgetl(f1) % fgetl is to read the lines from input file
end

R= 8.314 %universal gas constant


for j=1:53  %for loop to excuite the 53 species

    tline1=fgetl(f1); %species for the 
    mono_autonomy_mono_oxide= tline1(1) %taking the 1st mono atomic line
    line_split = strsplit(tline1,' ')%line split to identify the space btwn two values
    species_name = line_split{1}; %1st letter in line 
    find_dot=findstr(tline1,'.') %DOT to find the min,maz,mean temp values
    local_low_temp=str2num(tline1(find_dot(1)-3:find_dot(1))); %converting string to number
    local_high_temp=str2num(tline1(find_dot(2)-4:find_dot(2)));
    local_mid_temp=str2num(tline1(find_dot(3)-4:find_dot(3)));

    tline2=fgetl(f1) %line 2nd after the  line 
    mono_autonomy_mono_oxide= tline2(1)%taking the 2nd mono atomic line
    find_e=findstr(tline2,'E')%line split to identify the E letter btwn two values
    a1=str2num(tline2(1:find_e(1)+3)); %E to find the values 
    a2=str2num(tline2(find_e(1)+4:find_e(2)+3));%converting string to number
    a3=str2num(tline2(find_e(2)+4:find_e(3)+3));
    a4=str2num(tline2(find_e(3)+4:find_e(4)+3));
    a5=str2num(tline2(find_e(4)+4:find_e(5)+3));

    tline3=fgetl(f1)%line 3rd after the line 
    mono_autonomy_mono_oxide= tline3(1)%taking the 2nd mono atomic line
    find_e=findstr(tline3,'E')%line split to identify the E letter btwn two values
    a6=str2num(tline3(1:find_e(1)+3));%E to find the values 
    a7=str2num(tline3(find_e(1)+4:find_e(2)+3));%converting string to number
    a8=str2num(tline3(find_e(2)+4:find_e(3)+3));
    a9=str2num(tline3(find_e(3)+4:find_e(4)+3));
    a10=str2num(tline3(find_e(4)+4:find_e(5)+3));

    tline4=fgetl(f1)%line 3rd after the line 
    mono_autonomy_mono_oxide= tline4(1)%taking the 2nd mono atomic line
    find_e=findstr(tline4,'E')%line split to identify the E letter btwn two values
    a11=str2num(tline2(1:find_e(1)+3));%E to find the values 
    a12=str2num(tline4(find_e(1)+4:find_e(2)+3));%converting string to number
    a13=str2num(tline4(find_e(2)+4:find_e(3)+3));
    a14=str2num(tline4(find_e(3)+4:find_e(4)+3));
    %a15=str2num(tline4(find_e(4)+4:find_e(5)+3));

    T= linspace(local_low_temp,local_high_temp,50) % tempeatures in linespace
    if T < local_mid_temp % temperature is less than the mid temp
        cp=(a8 + a9*T+ a10*(T.^2)+ a11*(T.^3)+ a12*(T.^4)+ a13*(T.^5)+ a14*(T.^6))*R;
        H=(a8 + a9*(T./2)+ a10*((T.^2)./3)+ a11*((T.^3)./4)+ a12*((T.^4)./5)+ a13*((T.^5)./6)+ (a14./T) ) *R*T;
        s=(a8*log(T) + a9*T + a10*((T.^2)./2) + a11*((T.^3)./3) + a12*((T.^4)./4) + a13*((T.^5)./5) + a14*((T.^6)./6) )*R;

    else % temperature greater than the mid temp
        cp=(a1 +a2*T+ a3*(T.^2)+a4*(T.^3)+a5*(T.^4)+a6*(T.^5)+a7*(T.^6))*R
        H=(a1 + a2*(T./2) + a3*((T.^2)./3) + a4*((T.^3)./4) + a5*((T.^4)./5) + a6*((T.^5)./6)+ (a7./T))*R.*T
        s=(a1*log(T) + a2*T + a3*((T.^2)./2) + a4*((T.^3)./3) + a5*((T.^4)./4) + a6*((T.^5)./5) + a7*((T.^6)./6))*R;

  end
  
   molecular_weight = tes(species_name); %calling the funtion from tes
   sprintf('MOLECULAR WEIGHT  of  %s = %d',species_name,molecular_weight)
   %printing the species,molecular_weight values

    mkdir('E:\bhavek\MATLAB\matlab_practice\file_parising\file_parsing_test', species_name) % to create folders 
    cd( species_name ) %change directory

    figure(1)

    plot(T,cp,'Linewidth',1,'color','y') % ploting the graph for temperature and specific heat
    xlabel('temperature')
    ylabel('specific heat')
    

    figure(2)
    plot(T,H, 'Linewidth' ,3,'color','b')
    xlabel('temperature')
    ylabel('Ethalpy ')
    
   
    figure(3)
    plot(T,s,'Linewidth',3,'color','r')
    xlabel('temperature')
    ylabel('Entropy')

    saveas(figure(1),'specific_heat.png')
    saveas(figure(2),'Enthalpy.png')
    saveas(figure(3),'Entropy.png')
    
    cd ..  %%cd('change dirctory")
     
end


Function to call the specimen

function M_w=tes(species_name)

elements=['H','O','N','R','C'];
A_W=[1,16,14,40,12];
M_w=0;
for i=1:length(species_name)
  for j=1:length(elements)
    if strcmp(species_name(i),elements(j))
    M_w=M_w+A_W(j);
    p=j;
  end
end
n=str2num(species_name(i));
if n>1
  M_w=M_w+A_W(p)*(n-1);
end
end
end

caluculating molecular weight for each 53 specimen in thermo.dat file

atomic value for H=1, O=16,N=14,R=40,C=12

we are comparing the speciment and elements by strcmp funtion

we will change specimen name string in to number

molecular weight = molecular weight + atomic weigh (element)*(n-1)

we have ploted the temperature ,specific heat , enthalpy , entropy

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.