1. Consider the given files, data_total.dat and data_phi.dat, that include simulation data generated by simulation software. You do not need to know the technical details of the simulation. You are asked to write a Python code that reads data_total.dat, extracts certain data from it and generates data_phi.dat by writing the extracted data in it. The file, data_phi.dat, is given to you to show how it must look like once your code generates it.
a. Write a Python code that reads the file, data_total.dat, and ignores the lines that start with ‘%’. For the lines that do not start with ‘%’, the code is expected to start with empty lists, populate these lists, data_Phi, data_ReEphi and data_ImEphi, by appending them the float numbers in columns 2, 5 and 6, respectively. Each list must have a length of 361.
Hint: Use .readlines() method to read the lines of the file in a list. In a for loop over all the lines in the file, if a line does not start with ‘%’, split the numbers in the line using .split() method, extract the required numbers from it and append them to the three separate lists. When its argument is omitted, .split() method can extract substrings in a line separated by arbitrary strings of whitespace characters.
b. Extend the Python code developed in question 3.a to write the extracted lists in the file, data_phi.dat. Columns 1, 2 and 3 in the file must have the numbers from the lists, data_Phi, data_ReEphi and data_ImEphi, respectively, as shown in the file, data_phi.dat, provided.