#!/bin/csh -f

# compiling and running the code

set tables = (DC12)

if($1 == "clean") then
  foreach t ($tables)
    rm -rf $t".txt"
    rm -rf a.out
    rm -rf mother-geom.dat
    rm -rf layers-geom.dat
  end
  rm -rf tmp.txt
else
  g++ dc12geom.cc
  ./a.out

  foreach t ($tables)
    rm -rf $t".txt"
  end
  rm -rf tmp.txt

  # Default database - first argument defines new one
  set database = $1
  if($database =="") then
    set database = "user_geometry"
  endif

  # creates files. Should match the tables name above
  ./dc12_geometry.pl 1
  ./dc12_geometry.pl 2
  ./dc12_geometry.pl 3

  # Remaking the tables
  foreach t ($tables)
    echo "y" | $GEMC/database_io/drop_geo_table  $t   $database
    $GEMC/database_io/create_new_geo_table  $t  $database
  end

  rm -rf tmp.txt
  echo use $database";" > tmp.txt;
  foreach t ($tables)
    echo  LOAD DATA LOCAL INFILE \'$t.txt\'   into TABLE $t";" >> tmp.txt
    echo update $t" set time=NOW() where time=0;" >> tmp.txt;
  end

  mysql -h $GEMC_HOST -u $GEMC_USER < tmp.txt


endif







