#!/bin/bash

# generate random tile
[ -f 3145728 ] || head -c 3145728 /dev/urandom > 3145728

# width/height of the image
l=45

R="directql --user rasadmin --passwd rasadmin -d $RASDATA/RASBASE"
C="test_coll_7GB_rgb"

$R -q "create collection $C RGBSet" > /dev/null
$R -q "insert into $C values \$1" -f 3145728 --mddtype RGBImage --mdddomain [0:1023,0:1023] > /dev/null

echo "Updating collection $C..."

for i in $(seq 0 $l); do
  for j in $(seq 0 $l); do
   lox=$(($i * 1024))
   loy=$(($j * 1024))
   hix=$(($lox + 1024 - 1))
   hiy=$(($loy + 1024 - 1))
   echo "i: $i, j: $j..."
   $R -q "update $C as m set m assign \$1" -f 3145728 --mddtype RGBImage --mdddomain [$lox:$hix,$loy:$hiy] > /dev/null
  done
done

echo "done ingestion of collection $C".
