Hi, welcome. It's not a complicated question, it's an unclear one.
- What is a timestep?
- Are the files guaranteed to have synchronized timesteps, or are the lines timestamped?
- What are the rules that define a "cluster"?
- Why do you want separate output files for clusters and cluster sizes? You'll need another script to read that data.
Please supply:
- Data samples with at least 10 - 20 timesteps represented
- ... inside <code></code> tags as shown on the posting form
- The code you have now
- ... and how it does not do what you want (error messages if any)
- A higher-level description of what you plan to do with the output. There may be a better strategy than the one you've developed so far
Make your question clearer and you'll get better answers. Thanks!
The way forward always starts with a minimal test.