Project 1 - Parsing NASA thermodynamic data
File parsing basically is used to read data from external files/externl data basis and we can include that data from calculation. so if we talk about big data processing. There is usually interface between program and large amount of data either data is stored in a file or it comes from server.
1. J = fopen . f open keyword is basically stands for file opening and assign the output of this particular command is 'J' . Here J is read data from file. The value of J is really does't matters but it must be in positive.
2. Here i am used inbuilt function 'fgetl' in order to read the first 5 lines instead of species.
3. using for loop in order to evaluate 53 species .
4. Here, agian i am using 'fgetl' inbulit function in order to read 1st specie's all lines.
5. Now, i am using the variable name 'split' and inbulit function 'strsplit' on line L1 inorder to split the whole line into a 'string'
6. In the line no. 24 i am using function name split{1} in order to take species and the split the med_temp value into number and vice-versa for high and low temperature ranges.
7. using funaction 'findstr' and variable name as 'pose' in order to finding the position of 'E' and after that check out the value and convert this string value into number and apply same concept iin every line for each species one by one. There are tota 14 keywords in each species.
8. Now 100 values can be made for low temperature range and medium temperature range in ordre to make a garph and asign as a variable name T_lowrange and same thing for high temperature and medium temperature values as a variable name T_highrange.
9. On the other hand, i call the function 'NASA' for getting the values of high temperature range and low temperature range into the main program.
10. Assign the figure (1) and plot graph for temperature and specific heat for lowrange.
11. Give 'hold on' command in order to hold the previous figure.
12. plot the graph for highrange temperature and specific heat .
13. follow the same procedure for figure (2) and figure (3) in order to plot the graph for both lowrange and highrange temperature & enthalpy and both for lowrange and highrange for entropy and temperature.
14. mkdir command is used inorder to create a directory to store the output figures.
15. current folder is defined where the figure should be stored and saveas command is used to store the figure to that particular folder created.
16. current folder is again defined to make the directory back to parent folder and all the open files are closed with the fclose command.
function [Cp,H,S] = NASA (A1 ,A2 ,A3 ,A4 ,A5 ,A6 , A7 , T)
Cp = A1 + A2.*T + A3.*T.^2 + A4.*T.^3 + A5.*T.^4
H = A1 + A2.*T/2 + (A3.*T.^2)/3 + (A4.*T.^3)/4 + (A5.*T.^4)/5 + A6./T
S = A1.*log(T) + A2.*T +(A3.*T.^2)/2 + (A4.*T.^3)/3 + (A5.*T.^4)/4 + A7
end
clear all
close all
clc
J = fopen('THERMO.DAT' , 'r');
kolkata1 = fgetl(J);
kolkata2 = fgetl(J);
kolkata3 = fgetl(J);
kolkata4 = fgetl(J);
kolkata5 = fgetl(J);
%we are going to read one component at a time
for i = 1:53
L1 = fgetl(J);
L2 = fgetl(J);
L3 = fgetl(J);
L4 = fgetl(J);
split = strsplit(L1,' ')
name= split{1}
temp_med = split{end-1}
temp_med = str2num(temp_med)
temp_high = split{end-2}
temp_high = str2num(temp_high)
temp_low = split{end-3}
temp_low = str2num(temp_low)
pos = findstr(L2,'E')
A1 = L2(1:pos(1)+3)
A1 = str2num(A1)
A2 = L2(pos(1)+4 : pos(2)+3)
A2 = str2num(A2)
A3 = L2(pos(2)+4 : pos(3)+3)
A3 = str2num(A3)
A4 = L2(pos(3)+4 : pos(4)+3)
A4 = str2num(A4)
A5 = L2(pos(4)+4 : pos(5)+4)
A5 = str2num(A5)
A6 = L3(1:pos(1)+3)
A6 = str2num(A6)
A7 = L3(pos(1)+4 : pos(2)+3)
A7 = str2num(A7)
A8 = L3(pos(2)+4 : pos(3)+3)
A8 = str2num(A8)
A9 = L3(pos(3)+4 : pos(4)+3)
A9 = str2num(A9)
A10 = L3(pos(4)+4 : pos(5)+3)
A10 = str2num(A10)
A11 = L4(1:pos(1)+3)
A11 = str2num(A11)
A12 = L4(pos(1)+4 : pos(2)+3)
A12 = str2num(A12)
A13 = L4(pos(2)+4 : pos(3)+3)
A13 = str2num(A13)
A14 = L4(pos(3)+4 : pos(4)+3)
A14 = str2num(A14)
T_lowrange = linspace(temp_low,temp_med,100)
T_highrange = linspace(temp_med,temp_high,100)
[Cp_L,H_L,S_L] = NASA(A1,A2,A3,A4,A5,A6,A7,T_highrange)
% L stands for low range
[Cp_H,H_H,S_H] = NASA(A8,A9,A10,A11,A12,A13,A14,T_lowrange)
% Plotting Cp V/s T
figure(1)
plot(T_lowrange,Cp_L)
hold on
plot(T_highrange,Cp_H)
% plotting H V/s T
figure(2)
plot(T_lowrange,H_L)
hold on
plot(T_highrange,H_H)
% Plotting H v/s T
figure(3)
plot(T_lowrange,S_L)
hold on
plot(T_highrange,S_H)
mkdir('species')
cd('species')
mkdir(name)
cd(name)
% Savings the images in current folder in specific folder
saveas(1,'specific_heat.jpg')
saveas(2,'enthalpy.jpg')
saveas(3,'entropy.jpg')
% Defining current folder back as parent folder
cd ..
cd ..
molecularweight(name)
close all
end
fclose(J)