
import os
import sys

# check the python version
if float(sys.version[:3]) <= 3.6:
	print("This script require Python 3.6 !")
	print("Try:")
	print("\n\tmodule load python3\n\n")
	print("and restart this script again.")
	print("Aborting...")
	sys.exit(1)

if len(sys.argv) < 4:
	print('Bad arguments:', sys.argv)
	print('Usage:')
	print('\n\t python3 start_ensemble_experiment.py where experiment ensemble_size\n')
	print('Arguments:\n')
	print('\twhere :\t\t\tWhere the experiment ensemble folders are located.')
	print('\texperiment :\t\tName of the experiment.')
	print('\tensemble_size :\t\tSize of the ensemble.')
	sys.exit(0)

where = sys.argv[1]
experiment = sys.argv[2]
ensemble_size = int(sys.argv[3])
experiment_folder = where+"/"+experiment+"/"

if not os.path.isdir(experiment_folder):
	print("Experiment folder not found!")
	print("Create the experiment "+experiment+" first.")
	print("Aborting...")
	sys.exit(1)

#os.system('qsub '+ensemble_member_folder+'/PBS_'+job_name)
#job_name = 'plasim_'+experiment+'_'+member_number
#print('Starting the ensemble runs...')
for i in range(1, ensemble_size+1):
	member_number = str(i).rjust(2, '0')
	ensemble_member_folder = experiment_folder+'run_'+experiment+'_'+member_number
    #print(ensemble_member_folder)
    #os.system('cd '+ensemble_member_folder)

print("Experiment '"+experiment+"' ensemble started.")
#print('Check the status with: qstat -u '+os.getenv('USER'))

