Challenge

Project 1 - Parsing NASA thermodynamic data

File Parsing-It is a string or a symbol either in natural language or in computer language or data structure conferming to the rule of formal english grammer.

OR

it si 'the spliting of a file or other input in to pieces of data that can be easily store or manipulated', so we are spliting a string in to the parts to convert it into something simpler than a string.

EQUATION REQUIRED

Cp/R=A1+A2T+A3T^2+A4T^3+A5T^4

H/RT=A1+A2T/2+A3T^2/3+A4T^3/4+A5T^4/5+A6/T

S/R=A1 lnt+a2T+A2T+A3T^2/2+A4T^3/3+A5T^4/4+A7

R-Universal gas constant,T is the temperature

A1,A2,A3,A4,A5,A6,A7-High temperature coefficient

A8,A9,A10,A11,A12,A13,A14-Low temperature coefficient

MAIN PROGRAMM

% MATLAB PROGRAM PARSE THE NASA THERMO FILE
clear all
close all
clc
% FILE OPEN TO READ
f1=fopen('THERMO.dat','r');
%HEADER OF THE FILE
header=fgetl(f1);
%GLOBAL TEMPERATURE VALUES
global_temp_line=fgetl(f1)
a1=strsplit(global_temp_line)
global_low_temp=(a1{2})
global_mid_temp=(a1{3})
global_high_temp=(a1{4})
%COMMENTS NEEDED TO BE ELIMINATE
comment_1=fgetl(f1)
comment_2=fgetl(f1)
comment_3=fgetl(f1)
%TOTAL NUMBER OF SPECIES IN FILE
coef_line=0
while ~feof(f1)
line=fgetl(f1)
a=sscanf(line,'%c');
c=a(1:3)
d='END'
if c==d
break
end
coef_line=coef_line+1
end
Total_number_of_species=(coef_line)/4
% extracting the coefficients
frewind(f1)
for i=1:5
[line]=fgetl(f1)
i=i+1
end
for i=1:Total_number_of_species
line1=fgetl(f1)
split1=strsplit(line1,' ')
species_na=split1(1)
species_name=char(species_na)
split2=strsplit(line1,'G')
local_temp=str2num(split2{2})
local_low_temperature=local_temp(2);
local_mid_temperature=local_temp(3);
local_high_temperature=local_temp(4);
line2=fgetl(f1)
coeff1to5=findstr(line2,'E');
A1=str2num(line2(1:coeff1to5(1)+3));
A2=str2num(line2(coeff1to5(1)+4:coeff1to5(2)+3));
A3=str2num(line2(coeff1to5(2)+4:coeff1to5(3)+3));
A4=str2num(line2(coeff1to5(3)+4:coeff1to5(4)+3));
A5=str2num(line2(coeff1to5(4)+4:coeff1to5(5)+3));
line3=fgetl(f1)
coeff6to10=findstr(line3,'E');
A6=str2num(line3(1:coeff6to10(1)+3));
A7=str2num(line3(coeff6to10(1)+4:coeff6to10(2)+3));
A8=str2num(line3(coeff6to10(2)+4:coeff6to10(3)+3));
A9=str2num(line3(coeff6to10(3)+4:coeff6to10(4)+3));
A10=str2num(line3(coeff6to10(4)+4:coeff6to10(5)+3));
line4=fgetl(f1)
coeff11to14=findstr(line4,'E')
A11=str2num(line4(1:coeff11to14(1)+3))
A12=str2num(line4(coeff11to14(1)+4:coeff11to14(2)+3));
A13=str2num(line4(coeff11to14(2)+4:coeff11to14(3)+3));
A14=str2num(line4(coeff11to14(3)+4:coeff11to14(4)+3));
% calling functions enthalpy,specific heat and entropy
T=linspace(200,6000,500);
cp=specific_heat(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,local_mid_temperature);
H=enthalpy(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,local_mid_temperature);
S=entropy(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,local_mid_temperature);
%CALCULATION OF MOLECULER MASS
MM=molecular_mass(species_name);
%CREATING A FOLDER TO SAVE THE PLOTS
mkdir(['C:\Users\cdgau\OneDrive\Desktop\GAURAVS NASA PARSINGSPECIES',species_name]);
%PLOTTING
figure(1)
plot(T,cp,'linewidth',3,'Color','m')
xlabel('TEMPERATURE (K)')
ylabel('SPECIFIC HEAT (KJ/kg k')
title({'Temperature VS specific haet',['species -',species_name]})
grid on
figure(2)
plot(T,H,'linewidth',3,'Color','m')
xlabel('TEMPERATURE (K)')
ylabel('ENTHALPY (KJ)')
title({'Temperature VS Enthalpy',['species -',species_name]})
grid on
figure(3)
plot(T,S,'linewidth',3,'Color','m')
xlabel('TEMPERATURE (K)')
ylabel('ENTROPY (KJ/K')
title({'Temperature VS Entropy',['species -',species_name]})
grid on
%CHANGING the DIRECTORY
cd (['C:\Users\cdgau\OneDrive\Desktop\GAURAVS NASA PARSINGSPECIES',species_name]);
%SAVING THE PLOTS
saveas(1,'Temperature vs specific heat','jpg');
saveas(2,'Temperature vs Enthalpy','jpg');
saveas(3,'Temperature vs Entropy','jpg');
cd
end
fclose(f1)
FUNCTION OF SPECIFIC HEAT
function cp=specific_heat(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,local_low)
T=linspace(200,6000,500);
if(T>local_low)
cp=(A1+(A2*T)+(A3*T.^2)+(A4*T.^3)+(A5*T.^4))*8.314;
else
cp=(A8+(A9*T)+(A10*T.^2)+(A11*T.^3)+(A12*T.^4))*8.314;
end
end
FUNCTION OF ENTHALPY
function H=enthalpy(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,local_low)
T=linspace(200,6000,500);
if(T>local_low)
H=(A1+(A2*T./2)+(A3*(T.^2)./3)+(A4*(T.^3)./4)+(A5*(T.^4)./5)+(A6.*T))*8.314.*T;
else
H=(A8+(A9*T./2)+(A10*(T.^2)./3)+(A11*(T.^3)./4)+(A12*(T.^4)./5)+A13./T)*8.314.*T;
end
end
FUNCTION OF ENTROPY
function S=entrop(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,local_low)
T=linspace(200,6000,500);
if(T>local_low)
S=((A1*log(T))+(A2.*T)+(A3*T.^2./2)+(A4*T.^3./T)+(A5*T.^4./4)+A7)*8.314;
else
S=((A8*log(T))+(A9.*T)+(A10*T.^2./2)+(A11*T.^3./T)+(A12*T.^4./4)+A13)*8.314;
end
end
FUNCTION OF MOLECULAR MASS
function[MM]=molecular_mass(species_name);
species=upper(species_name);
constituents=['H','C','N','O','A','S'];
atomic_weights=[1.00794 12.0107 14.0067 15.994 39.948 32.065];
MM=0;
u=0;
for i=1:length(species)
for j=1:length(constituents)
if(strcmp(species(i),constituents(j)))
MM=MM+atomic_weights(j);
u=j;
end
end
n=str2num(species(i));
if n>1
MM=MM+atomic_weights(u)*(n-1);
end
end
fprintf('The molecular mass of %s is %0.0fn',species,MM)
end
FUNCTION USED
fopen--opens the file,for binary read access,integer file identifier equal to or greater than 3, if file not open then fileid is -1
getl--next line command
string is split using strsplit command,
the numbers converts in to strings by command str2num.
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.