Project

file parsing project

clc

clear all

close all

%input and temp variables

R=8.14; %gas constant

k=0; %Main loop governer

low_temp=200; %percent partition between high temperture and low temperature

%opening file

FID=fopen(\\\'therm.dat\\\');

for i=1:5

line=fgets(FID); %liminating initial lines

end

t=linespace(0,1000,100); %creating a temperature array

while k==0 %main loop to go for all substances

line=fgets(FID);

a=sscanf(line,\\\'%c\\\');

%checking for end

c=a(1:3);

d=\\\'END\\\';

if c==d

break

end

%finding molecular mass

p=25;

mol_mass=0;

for i=0:2

p=p+5*i;

g=str2num(a(p+4));

switch a(p)

case\\\'0\\\'

mol_mass =mol_mass + 16*g ;

case \\\'H\\\'

mol_mass=mol_mass+2*g;

case \\\'N\\\'ol

mol_mass=mol_mass+14*g;

case\\\'A\\\'

mol_mass=mol_mass+40*g;

otherwise

break

end

end

s=0;

s=num2str(mol_mass);

%naming the substance with molecular mass

for i=1:9

if a(i)==\\\'\\

b(i)==\\\'_\\\'

end

b(i)=a(i);

end

if length(s)==2

b(10:11)=s;

else

b(10)=\\\'_\\\';

b(11)=s;

end

%inputing next 3 lines

line=fgets(FID);

a1=sscanf(line,\\\'%f\\\');

line=fgets(FID);

a2=sscanf(line,\\\'%f\\\');

line=fgets(FID);

a3=sscanf(line,\\\'%f\\\');

%obtaining constant in two array h for high temp and m for low temp

%here low temp is assumed to be any temperature below 200k

h=[a1(1) a1(2) a1(3) a1(4) a1(5) a2(1) a2(2)];

m=[a2(3) a2(4) a2(5) a3(1) a3(2) a3(4)];

%thermal properties calculation

for i=1:length(t)

if t(i)<low_temp

te=t(i);

cp(i)=R*(m(1)+m(2)*te+m(3)*te^2+m(4)*te^3+m(5)*te^4);

H(i)=R*te*(m(1)+m(2)*te/2+m(3)*(te^2)/3+m(4)*(te^3)/4+m(5)*(te^4)/5+m(6)/te);

s(i)=R*(m(1)*log(te)+m(2)*te+m(3)*(te^2)/2+m(4)*(te^3)/3+m(5)*(te^4)/4+m(7));

else

te=t(i);

cp(i)=R*(h(1)+h(2)*te+h(3)*te^2+h(4)*te^3+h(5)*te^4);

H(i)=R*te*(h(1)+h(2)*te/2+h(3)*(te^2)/3+h(4)*(te^3)/4+h(5)*(te^4)/5+h(6)/te;

S(i)=R*(h(1)*log(te)+h(2)*te+h(3)*(te^2)/2+h(4)*(te^3)/3+h(5)*(te^4)/4+h(7));

end

end

%plotting

figure(1)

plot(t,cp)

figure(2)

plot(t,H)

figure(3)

plot(t,s)

%unique name for every figure

filename1=sprintf(\\\'cp vs T of %s\\\' ,b);

filename2=sprintf(\\\'enthalpy vs T of %s\\\',b);

filename3=sprintf(\\\"entropy vs T of %s\\\',b);

filename1=sprintf(\\\'cp vs T of %s\\\',b);

filename2=sprintf(\\\'enthalpy vs T of %s\\\',b);

filename3=sprintf(\\\'entropy vs T of %s\\\',b);

%new folder and saving figure

mkdir(b)

old_folder=pwd;

c(b)

savefig(1,filename1)

cd(old_folder)

end

close all

fclose(FID)

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.