Advertisement
Amnacog

(GNU/Linux) gengrids.sh / gen BSQ & perf script 42

Jul 22nd, 2014
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.98 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ##Jonglez avec les densités comme vous voulez (résultat de RANDOM un peu binaire)
  4.  
  5. function gen {
  6. perl << END
  7. print "$2.ox\n";
  8. for (my \$i = 0; \$i < $2; \$i++) {
  9.         for (my \$j = 0; \$j < $2; \$j++) {
  10.                 if (int(rand($2) * 2) < $3) {
  11.                         print "o";
  12.                 }
  13.                 else {
  14.                         print ".";
  15.                 }
  16.         }
  17.         print "\n";
  18. }
  19. END
  20. }
  21.  
  22. cd `dirname $0`;i=1;j=1;k=1;x=0
  23. if [[ -z $2 ]] || [ ! -f $1 ]; then echo -e "usage: `basename $0` bsq nb \"c\" \nPS: \
  24. More grids More size More time\nPSPS: the script create only valid grids" ; exit ; fi
  25. if [[ ! -z $3 ]]; then rep=$3 ;else rep=" "; fi
  26. if [ ! -d grids ]; then mkdir grids;fi
  27. echo "Part 1: gen $2 grids" ; sleep 1
  28. coordx=(); coordy=(); density=()
  29. while [ $x -le $2 ]; do
  30.                 gen $i $j $k > grids/pl$x
  31.                 echo -e "\r$((100 * $x / $2))%\c";k=$((RANDOM / 1000))
  32.                 j=$((i + 10));i=$((i + 50 + x));coordx[$x]=$i;coordy[$x]=$j
  33.                 density[$x]=$k;((x++))
  34. done
  35. echo -e "\nPart 2: testing" ; sleep 1
  36. # the tricky part: since we removed F..
  37. x=1
  38. result=()
  39. while [ $x -le $2 ]; do
  40.         echo "Grid $x"
  41.         echo -e "`cat grids/pl$x | time -f "%e seconds" $1 2>&1 | tee grids/result | \
  42.       grep -v "seconds" | sed "s/o/\\\\\033[0;33mo\\\\\033[0m/g" | \
  43.       sed "s/x/\\\\\033[0;32mx\\\\\033[0m/g" | tr "." "$rep"`"
  44.         result[$x]="`cat grids/result | tail -n1 | cut -d' ' -f1`"
  45.                 ((x++))
  46. done
  47. x=1
  48. echo -e "\nPerfs :"
  49. while [ $x -le $2 ];do
  50.                 res=`echo ${result[$x]} | cut -d. -f1 | perl -pe 's/[^\x20-\x7f]//g'` #le petit ^C qui se balade :P
  51.                 if [ $res -eq 0 ]; then color="\033[0;32m"
  52.                 elif [ $res -le 2 ]; then color="\033[0;33m"
  53.                 else color="\033[0;31m" ; fi
  54.                 echo -e "Grid $x - x:${coordx[$x]} y:${coordy[$x]} dens:${density[$x]}\t=>$color ${result[$x]}s\033[0m"; ((x++))
  55. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement