#!/bin/bash

#
# make image squence orderd by AQI and date
#
# Gareth Kennedy 21/1/2015
#

dirx="resize/posi3/"
diro="movie/posi3/"

ls -1 $dirx > list.txt
sort list.txt > list_date.txt
sort -n -k1.15,1.17 list.txt > list_aqi.txt

i=0
while read p; do
  if [ "$i" -lt "10" ]; then
    cp $dirx$p $diro"date/image00"$i".jpg"
  elif [ "$i" -lt "100" ]; then
    cp $dirx$p $diro"date/image0"$i".jpg"
  else
    cp $dirx$p $diro"date/image"$i".jpg"
  fi
  i=$[$i+1]
done <list_date.txt

i=0
while read p; do
  if [ "$i" -lt "10" ]; then
    cp $dirx$p $diro"AQI/image00"$i".jpg"
  elif [ "$i" -lt "100" ]; then
    cp $dirx$p $diro"AQI/image0"$i".jpg"
  else
    cp $dirx$p $diro"AQI/image"$i".jpg"
  fi
  i=$[$i+1]
done <list_aqi.txt

