Challenge

Project 1 - Parsing NASA thermodynamic data

File parsing in simple words can be described as the reading the data fronm the any file. Here we have a recived a data having the molecular data.
f1 = fopen('THERMO.dat', 'r') %reading the data
first_line = fgetl(f1); %reading the firast line
%exteacting the global maxima , medium and minuma.
global_temp = fgetl(f1) %reading the second line
temp_range = strsplit(global_temp, ' ');
%obtaining the temp values from the data
global_min_temp = str2num(temp_range{2})
global_mid_temp = str2num(temp_range{3})
global_max_temp = str2num(temp_range{4})
%create a vector of 400 evenly spaced temperature points
T = linspace(global_min_temp, global_max_temp,400);
R = 8.314; %gas constant
comment1 = fgetl(f1); %readline 3
comment2 = fgetl(f1); %readline 4
comment3 = fgetl(f1); %readline 5
for i = 1:53
line1 = fgetl(f1);
element_name = strtok(line1);
line2 = fgetl(f1);
A = strfind(line2, 'E');
line3 = fgetl(f1);
B = strfind(line3, 'E');
line4 = fgetl(f1);
C = strfind(line4, 'E');
a1 = str2num(line2(1:A(1)+3));
a2 = str2num(line2(A(1)+4:A(2)+3));
a3 = str2num(line2(A(2)+4:A(3)+3));
a4 = str2num(line2(A(3)+4:A(4)+3));
a5 = str2num(line2(A(4)+4:A(5)+3));
a6 = str2num(line3(A(4)+4:A(5)+3));
a5 = str2num(line2(A(4)+4:A(5)+3));
a6 = str2num(line3(1:B(1)+3));
a7 = str2num(line3(B(1)+4:C(4)+3));
b1 = str2num(line3(B(2)+4:B(3)+3));
b2 = str2num(line3(B(2)+4:B(4)+3));
b3 = str2num(line4(B(2)+4:B(5)+3));
b4 = str2num(line4(1:C(1)+3));
b5 = str2num(line4(C(1)+4:C(2)+3));
b6 = str2num(line4(C(2)+4:C(2)+3));
b7 = str2num(line4(C(3)+4:C(2)+3));
%specific_heat
c_p = specificheat(a1, a2, a3, a4, a5 , a6,a7,a8, a9, a10, a11, a12, a13, a14,R,globa6l_mid_temp);
%enthalpy
h = enthalpy(a1, a2, a3, a4, a5 , a6,a7,a8, a9, a10, a11, a12, a13, a14,T,R,global_mid_temp);
%entropy
s = entropy_cal(a1, a2, a3, a4, a5 , a6,a7,a8, a9, a10, a11, a12, a13, a14,T,R,global_mid_temp);
%plottng
fig(1)
plot(T,cp,'linewidth','color','r')
end
fclose(f1)

The program starts ih the "fopen" command, to open the file.

First line consists of the text( thermo). 'fgetl' command to read the first line in the given file.

Second line consists of 3 temperature values.

Nowto obtain the global minimum , medium and the maximum temperature from the split data, use "str2num' as this comand converts the character array to the nuerical array.

Then create a vector of 400 eventually spaced temperature points ucing "linspace" command and provide universal gas constant.

3,4,5 lines in the data file are commands. Use 'fgetl' for reading theses commands.

From line 6 to 218 there are set of 4 lines. The first line consists o the species name and the next three linea contain the experimental valuies.

Read the line 6 using 'fgetl' and started it in line variable. Read ine 7 using 'fgetl' and statred it in line 2 variable.

Use strfind command to find the place of E in line 7, strfind is used to find stringsd with other strings. Now store them in an array named "A".

Simirally, follow these steps for the next 2 lines. Then, you will get A,B,C, arrays respectively.

Now extract all the coedfficients (a1,a2,a3, a4, a5, a6, a7,b1, b2, b3, b4, b5, b6, b7) using "str2num" command.

All this process should be done again gor nthe line 7 to line 212. therefore, we have created a for loop for all the 53 species.

At the start the file was running the but the file wasn't running after removing the error I came to the error as unidentified error "specific_heat". After removing that error to The program wasn't showing any command.

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.