#!/bin/csh -f

set tables = (LH2target NH3target LD2target Bonustarget CarbonTarget  IronTarget LeadTarget)

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
# Files are already there


# 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










