A text file generated by a Fortran program contains "blocks" data, that need to be reformatted (Python script).
Each "block" of data in this file corresponds to the "Time:" specified in the beginning of the block. All "blocks" have a fixed size and structure.
I need to extract the data from "Head" and "Moisture" columns corresponding to different "Depths" (0, -1, and -2) for each "Time:".
Note: The header at the beginning is not part of the repeating "blocks" of data.
Sample input file:
******* Program Simulation
*******
This is initial header information for Simulation
Date: 1. 6. Time: 15: 3:39
Units: L = cm , T = min , M = mmol
Time: 0.0000
Node Depth Head Moisture K
[L] [L] [-] [L/T]
1 0.0000 -37.743 0.0630 0.5090E-05
2 -1.0000 -36.123 0.0750 0.5090E-05
3 -2.0000 -33.002 0.0830 0.5090E-05
end
Time: 360.0000
Node Depth Head Moisture K
[L] [L] [-] [L/T]
1 0.0000 -0.1000E+07 0.0450 0.1941E-32
2 -1.0000 -253.971 0.0457 0.4376E-10
3 -2.0000 -64.510 0.0525 0.2264E-06
end
Time: 720.0000
Node Depth Head Moisture K
[L] [L] [-] [L/T]
1 0.0000 -0.1000E+07 0.0550 0.1941E-32
2 -1.0000 -282.591 0.0456 0.2613E-10
3 -2.0000 -71.829 0.0513 0.1229E-06
end
Desired output:
Time Head(Depth=0) Head(Depth=-1) Head(Depth=-2) Moisture(Depth=0) Moisture(Depth=-1) Moisture(Depth=-2)
0.0000 -37.743 -36.123 -33.002 0.0630 0.0750 0.0830
360.0000 -0.1000E+07 -253.971 -64.510 0.0450 0.0457 0.0525
720.0000 -0.1000E+07 -282.591 -71.829 0.0550 0.0456 0.0513
How I read the input file block-by-block from each "Time:" to "end" keywords and reformat to the desired output?