#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#
# This script check if the simulation in relandir gave crashed or not
# and write the list of crashed simulation in relandir/crashed.txt  
#
# Septembre 2026 Maëlle CD & Romain R

import os

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("-relandir", help="Path to the not postprocessed simulations (relances/group/WAVE$nwave)", type=str, required=True)

args = parser.parse_args()
relandir=args.relandir

with open(f'{relandir}/crashed.txt','w') as fc:
    for exp in os.listdir(relandir) :
      exppath = os.path.join(relandir, exp)
      if os.path.isdir(exppath):
        with open(f'{relandir}/{exp}/{exp}_his', 'r') as f:
            lines = f.readlines()
            for line in lines:
                if '#' not in line and 'DAFC' in line:
                    DAFC = line.split()[1]
                    if DAFC != '20511130':
                        fc.write(f'{exp}\n')
                    break

