#!/bin/bash
#####################################################
# copy the last image of each simulation into the images
# directory and name it after its original directory
#####################################################

nb_dir=$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)
echo "number of directories: $nb_dir"

if [ $nb_dir = 0 ]; then
  echo "nothing to do"
  exit
fi

list_dir=$(ls -d */ | tr -d '/')
#echo list_dir = $list_dir

if [ ! -e images ]; then
  echo "creating the images directory"
  mkdir images
fi

i=0

for dir in $list_dir ; 
do
#  echo dir = $dir
  if [ $dir = "images" ]; then
    continue
  fi
  img=$(ls -1 ${dir}/*.png | tail -1)
  if [ -e "$img" ] && [ ! -e images/${dir}.png ];  then
    echo "creating ${dir}.png"
    cp $img images/${dir}.png
    ((i++))
  fi
done

echo "done : $i image(s)"

