import sys, os

i=sys.argv[1]
cid = "C"+str(i).zfill(3)
for PFphase in [0,1]:
    with open(cid+".PF"+str(PFphase)+".daint.restart", "w") as fp:
        fp.write("#!/bin/bash -l\n")
        fp.write("#SBATCH --account=pr48\n")
        fp.write("#SBATCH --mail-type=ALL\n")
        fp.write("#SBATCH --mail-user=zbox.msg@gmail.com\n")
        fp.write("#SBATCH --time=24:00:00\n")
        fp.write("#SBATCH --nodes=32\n")
        fp.write("#SBATCH --ntasks-per-core=2\n")
        fp.write("#SBATCH --ntasks-per-node=1  # This is a PKDGRAV3-specific setting that must not be changed in any case!\n")
        fp.write("#SBATCH --cpus-per-task=24\n")
        fp.write("#SBATCH --partition=normal\n")
        fp.write("#SBATCH --constraint=gpu\n")
        fp.write("#SBATCH --hint=multithread\n")
        fp.write("\n")
       	fp.write("\n")
        fp.write("#SET UP SRUN COMMAND:\n")
        fp.write("#====================\n")
        fp.write("\n") 
        fp.write("export OMP_NUM_THREADS=${SLURM_CPUS_PER_TASK}\n")
        fp.write("\n")
        fp.write("printf -v CHKSTEP \"%05d\" $1\n")
        fp.write("NAME=\""+cid+".PF"+str(PFphase)+"\"\n")
        fp.write("\n")
        fp.write("cmd=\"srun ./pkdgrav3 chk/${NAME}.${CHKSTEP}.chk\"\n")
        fp.write("\n")
        fp.write("\n")
        fp.write("#START EXECUTION:\n")
        fp.write("#================\n")
        fp.write("\n")
        fp.write("STARTTIME=`date '+%Y-%m-%d %H:%M:%S'`\n")
        fp.write("\n")
        fp.write("echo \"*****************************************************\"\n")
        fp.write("echo \"Parameter file: ${NAME}.par\"\n")
        fp.write("echo \"Job name: ${SLURM_JOB_NAME}\"\n")
        fp.write("echo \"No of nodes: ${SLURM_NNODES}\"\n")
        fp.write("echo \"Start: ${STARTTIME}\"\n")
        fp.write("echo \"*****************************************************\"\n")
        fp.write("\n")
        fp.write("echo ${cmd}\n")
        fp.write("${cmd}\n")
        fp.write("\n")
        fp.write("ENDTIME=`date '+%Y-%m-%d %H:%M:%S'`\n")
        fp.write("echo \"End: ${ENDTIME}\"\n")
        fp.write("echo \"Done!\"\n")
