#!/bin/bash

##Script to batch process TAPSIM simulation output per pillar
##Markus Kuehbach, 2018/05/07, m.kuehbach at mpie.de

##user required input
##which pillar queue
simid=$1

##start id and end id
pids=$2
pide=$3
ini="meshgen.ini"
cfg="AlMeshCorrected.cfg"
vbs="*.txt"

for ((pid = $pids; pid <= $pide; pid += 1)); do
	prefix="TAPSIMSimID$pid"
	echo $prefix
	
	eval "cd BatchMillSimID$pid"
	
	eval "rm dump*"
	eval "tar -zcvf $prefix.Input.tar.gz $ini $cfg $vbs TAPSIMInputMesh$pid"
	echo "Input"
	
	eval "tar -zcvf $prefix.Temporaries.tar.gz geometry.dat grid_data.00000000 surface_data.00000000"
	echo "Temporaries"
	eval "rm geometry.dat"
	eval "rm grid_data.00000000"
	eval "rm surface_data.00000000"
	
	eval "tar -zcvf $prefix.DetectorHits.tar.gz $ini $cfg $vbs TAPSIMInputMesh$pid TAPSIMSimID$pid.0*"
	echo "DetectorHits"
	
	eval "tar -zcvf $prefix.Trajectories.tar.gz $ini $cfg $vbs TAPSIMInputMesh$pid trajectory_data*"
	
	eval "mkdir -p raw"
	#eval "mv *.dat raw/"
	eval "mv *.txt raw/"
	#eval "mv grid_data* raw/"
	eval "mv *.ini raw/"
	#eval "mv surface_data* raw/"
	eval "mv TAPSIM* raw/"
	eval "mv trajectory_data* raw/"
	eval "mv *.cfg raw/"
	
	eval "mv raw/*.tar.gz ../"
	
	eval "cd ../"
done
