Challenge

Project 1 - Parsing NASA thermodynamic data

                           NASA thermodynamic analysis project

explanation:-

parsing a file mean reading the data from the file and applying some transformation to it and easily stored and manipulated the data the file THERMO.dat contains coefficients required to solve specific heat, enthalpy, entropy.

1. initially to read the data we use fopen command and fgetl command to extract the data from one line to another line and strsplit command to split the data

%reading the data from file

temp = fopen(‘thermo.dat’,’r’)

fgetl(temp)

temp_data = fgetl(temp)

a = strsplit(temp_data,’ ‘)

2. extracting the global temperature ranges using str2num so that string characters arrey is converted into numbers array

low = str2num(a{2})

mid = str2num(a{3})

high = str2num(a{4})

3. for finding all the 53 element we create for loop to solve 53 element

for i = 1:53

data = fgetl(temp)

a = strsplit(data, ‘ ‘)

species = a{1}

extraction of coefficient for this we use findstr command to fine string character E position from this we can acess the local temperature esaily from this we have to fine coefficients of line1 using fgetl command and also change the string characters to numbers

line1 = fgetl(f1);

op1 = findstr(line1,'E');

a1 = str2num(line1(1:op1(1)+3));

a2 = str2num(line1(op1(1)+4:op1(2)+3));

a3 = str2num(line1(op1(2)+4:op1(3)+3));

a4 = str2num(line1(op1(3)+4:op1(4)+3));

a5 = str2num(line1(op1(4)+4:op1(5)+3));

in the same way for line2 and line 3 also we can extract the coefficients.

4. for extracting low mid and high temperature we use str2double command for string to double precession number.

c = strfind(data,'.') ;

tlow = str2num(data(c(1)-3:c(1)+3))

tmid = str2num(data(c(3)-4:c(3)+3))

thigh = str2num(data(c(2)-4:c(2)+3))

5. plot between specific heat and temperature using linspace we have to take lowtemp and high temp in intervals of 100. we have to take function of specific heat and plot between cp and temperature.

T = linspace(tlow,thigh,500);

[Cp]=Specific_heat(r,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,tmid,T);

figure(1)

plot(T,Cp,'LineWidth',3,'Color','b')

xlabel('temperature')

ylabel('specific_heat')

grid on

title(sprintf('variation of specific heat with temperature for %s', species))

saveas(figure(1),'Cp.png');

specific heat funtion :-

function [Cp]= Specific_heat(r,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,tmid,T)

%first 7 coefficent are the high temperature coefficents and the next 7 coefficient are the low temp coefficents

if (T<=tmid)

Cp=r*(x8+ (x9*T)+(x10*(T).^2)+(x11*(T).^3)+ (x12*(T).^4));

else

Cp=r*(x1+(x2*T)+(x3*(T).^2)+(x4*(T).^3)+(x5*(T).^4));

end

end

in the same way we ahve to plot for enthalpy and entropy using seperate function for each of this

6. after finding plots we have to find molecular weight we have to write function for the element N,H,C,O,A using strcmp command we compare the other element to get the molecular weight.

Molecular weight funtion:-

%to calculate the molecular_weight

function [molecular_weight]=m_wt(species)

elements = {'H','C','O','N','A','S'};

atomic_weight= [1,12,16,14,39,32];

molecular_weight = 0;

%creating loop

for k = 1:length(species)

for l=1:length (elements)

%comparing the string value

if strcmp(species(k),elements(l))

%if above comparison is true, value of molecular mass is

%calculated

molecular_weight = molecular_weight+atomic_weight(l);

%storing the position for further use

position=1;

end

end

%converting the string to number

n = str2double(species(k));

%comparing if the value of n is greater than executed, the further

%statement

if (n>1)

%molecular mass calculation

molecular_weight =molecular_weight+(atomic_weight(position)*(n-1));

end

end

%command to print the molecular mass of the molecule

%disp(molecular_weight)

fprintf('Molecular weight of the species %s is %f',species,’mol_mass’,molecular_weight);

end

fprintf to read the all 53 molecular weight in a row.

7. ‘mkdir ‘ command is used for creating folders for all the 53 element ‘cd’ is used for change in directory using ‘save as ‘ command to save the plots.

mkdir(species)

cd(species)

saveas(1,’specific heat’,’jpg’)

saveas(2,’enthalpy’,’jpg’)

saveas(3,’entropy’,’jpg’)

cd..

errors occured:-

* not printing the molecular weight values

*in spacific heat function i kept cp instad of Cp 

*not mentioned function in m_wt

*i wrote Str2num insterd of str2num

*in cd i given wrong file location

*didn't wrote "cd.." at the end

*get problem in opening the THERMO.dat file on mac

*got error on the taking the extera decemals in temperature low,mid,high.

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.