From 3d3dbe701e22f5d8989e184cf11b5f95e35a3c7e Mon Sep 17 00:00:00 2001
From: Samuel Hanot <samuel.hanot@pasteur.fr>
Date: Tue, 13 Mar 2018 11:15:39 +0100
Subject: [PATCH] make recursive_gmconvert.sh get the number of gaussians from
 an array. This opens the door to reading num of gaussians lists from a file

---
 recursive_gmconvert.sh | 36 +++++++++++++++++++++++-------------
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/recursive_gmconvert.sh b/recursive_gmconvert.sh
index 0b37711..e8c6b8a 100755
--- a/recursive_gmconvert.sh
+++ b/recursive_gmconvert.sh
@@ -18,8 +18,8 @@ Optional arguments:
 #defaults
 map_name=
 threshold=
-n_gaussians=
-n_gaussians0=
+ng=
+ng0=
 N=
 i0=1
 serial=0
@@ -29,8 +29,8 @@ do
     case "$opt" in
       f)  map_name="$OPTARG";;
 			t)  threshold="$OPTARG";;
-			n)  n_gaussians="$OPTARG";;
-			0)  n_gaussians0="$OPTARG";;
+			n)  ng="$OPTARG";;
+			0)  ng0="$OPTARG";;
 			N)  N="$OPTARG";;
 			i)  i0="$OPTARG";;
 			s)  serial=1;;
@@ -44,17 +44,29 @@ do
 done
 
 #check that necessary options were set
-if [[ ! -e "$map_name" ]] || [[ -z "$threshold" ]] || [[ -z "$n_gaussians" ]] || [[ -z "$N" ]]
+if [[ ! -e "$map_name" ]] || [[ -z "$threshold" ]] || [[ -z "$ng" ]] || [[ -z "$N" ]]
 then
 	usage
 	exit 1
 fi
 
-if [[ -z "$n_gaussians0" ]]
+if [[ -z "$ng0" ]]
 then
-	n_gaussians0=$n_gaussians
+	ng0=$ng
 fi
 
+num_gaussians=()
+for ((i=$i0 ; i<=N ; i++))
+do
+	if ((i==1))
+	then
+		num_gaussians+=$ng0
+	else
+		num_gaussians+=$ng
+	fi
+done
+
+
 MaxArraySize=100000
 get_max_jobs(){
 	echo ${MaxArraySize}
@@ -71,12 +83,10 @@ map_name=$(basename $map_name)
 cd $map_root_dir
 
 
-
 mkdir -p converged
-for ((i=$i0 ; i<=N ; i++))
+for ((i=$i0 ; i<=${#num_gaussians} ; i++))
 do
-	echo "i=$i"
-	n=$((i))
+	n=${num_gaussians[$i]}
 	jobname=${map_name}_${n}
 
 	n_jobs=1
@@ -86,7 +96,7 @@ do
 		then
 			${gmconvert} -imap ${map_name} -zth ${threshold} -oimap threshold.map -ogmm /dev/null -ng 0
 	  fi
-		echo ${profile_cmd} ${gmconvert} -imap ${map_name} -ogmm $n/${n}_0.gmm -ng ${n_gaussians0} -zth ${threshold}
+		echo ${profile_cmd} ${gmconvert} -imap ${map_name} -ogmm $n/${n}_0.gmm -ng ${ng0} -zth ${threshold}
 		echo ${gmconvert}  -igmm $n/${n}_0.gmm -imap ${map_name} -omap /dev/null
 	else
 		n_prev=$((i-1))
@@ -97,7 +107,7 @@ do
 			n_jobs=$((n_jobs + $(awk '/NGAUSS/{s+=$3}END{print s}' ${gmm_file}) ))
 		done
 		echo echo ${gmm_name} '$((SLURM_ARRAY_TASK_ID-1+offset))' \> 'tmp_$((SLURM_ARRAY_TASK_ID+offset)).txt'  
-		echo ${profile_cmd} ${gmconvert} -imap ${map_name}  -gmml 'tmp_$((SLURM_ARRAY_TASK_ID+offset)).txt' -ogmm $n/${n}_'$((SLURM_ARRAY_TASK_ID-1+offset))'.gmm -ng ${n_gaussians} -zth ${threshold}
+		echo ${profile_cmd} ${gmconvert} -imap ${map_name}  -gmml 'tmp_$((SLURM_ARRAY_TASK_ID+offset)).txt' -ogmm $n/${n}_'$((SLURM_ARRAY_TASK_ID-1+offset))'.gmm -ng ${ng} -zth ${threshold}
 		echo ${gmconvert}  -igmm $n/${n}_'$((SLURM_ARRAY_TASK_ID-1+offset)).gmm' -imap ${map_name}  -gmml 'tmp_$((SLURM_ARRAY_TASK_ID+offset)).txt' -omap /dev/null
 	fi > commands_$i.sh
 	mkdir -p $n
-- 
GitLab