#!/bin/bash

ni=20 #number of images in smwst
nc=5 # number of copies in smwst
job_id=4 # last smwst job_id
force=5000 # force constant
# pick the right directory
output=../../../1-smwst/0-parallel/output

for i in `seq 0 $((ni-1))`
do
    output_root=$output/$i/glpt
    for j in `seq 0 4`
    do
	cp $output_root.job$job_id.$((i*nc+j)).coor ../input/init.$((i*nc+j)).coor
	cp $output_root.job$job_id.$((i*nc+j)).vel ../input/init.$((i*nc+j)).vel
	cp $output_root.job$job_id.$((i*nc+j)).xsc ../input/init.$((i*nc+j)).xsc
    done
done

cat $output/job$job_id.log.0 | \
grep "TCL: Reparametrized " | tail -$ni | awk -v force=$force '{
    printf "set centers(%d) [list harm \"forceConstant \{ %s \} centers \{ ",$4,force
    for(i=1;i<NF/4;i++) printf "( %s , %s , %s , %s ) ",$(4*i+1),$(4*i+2),$(4*i+3),$(4*i+4)
    printf "\} \" ]",$i;printf"\n"
}' > ../centers.tcl
