I have a file from which I only need to read certain values into an array. The file is divided by rows which specify a TIMESTEP
value. I need the section of data following the highest TIMESTEP
in the file.
The files will contain over 200,000 rows although I won't know which row the section I need begins for any given file and I won't know what the largest TIMESTEP
value will be.
Am assuming that if I can find the row number of the largest TIMESTEP
then I can import starting at that line. All these TIMESTEP
lines begin with a space character. Any ideas on how I might proceed would be helpful.
Sample file
headerline 1 to skip
headerline 2 to skip
headerline 3 to skip
TIMESTEP = 0.00000000
0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
1, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
2, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
2, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
TIMESTEP = 0.119999997
0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
1, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
2, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
3, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
TIMESTEP = 3.00000000
0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
1, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
1, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
2, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
Basic code
import numpy as np
with open('myfile.txt') as f_in:
data = np.genfromtxt(f_in, skip_header=3, comments=" ")