#!/bin/csh -f
# master.csh
#source /nfs/soft/jchem/current/env.csh
source /nfs/soft/mitools/env.csh
source /nfs/soft/www/apps/zinc15/envs/production/env.csh
setenv ZINC_CONFIG_ENV admin
setenv ZINC_CONFIG_SETUP_SKIP blueprints
#setenv ZINC_CONFIG_OVERRIDE ~/.zinc15/export-override.cfg

cd /nfs/db/export/catalogs/

setenv i $1
mkdir -p $i
cd $i
#psql -h mem -U test zinc15 -c "select short_name from catalog where free and purchasable = $i order by original_size" -t -F '\t' -o list
foreach j (`cat list`)
	echo $j
	if (-d $j.d) then
		echo $j.d exists
	endif
	mkdir -p $j.d
	pushd $j.d
	#ln -sf ../../filtered/$j.filt.txt $j.filtered.txt
	#ln -sf ../../source/$j.src.txt $j.original.txt
	#ln -sf ../../unique/$j.unique.txt.gz $j.unique.txt.gz
	#ln -sf ../../errors/$j.err.txt $j.errors.txt

	@ I = 0
	@ delta = 1000000
	while ($I < 1300)
		@ lo = $I * $delta
		@ I = $I + 1
		@ hi = $I * $delta
		time /nfs/export/catalogs/fetchVendorC.py $j $lo $hi > $j.$lo.info.new
	end
	exit;
	time ~/bin/fetchVendorP.py $j > $j.3d.new
	~/bin/getme.csh  $j lead-like "C D E" 
	~/bin/getme.csh  $j frag-like "A B" 
	/bin/mv -f $j.info.new $j.info.txt
	# get predictions
	~/bin/ding.csh $j
	popd
	if (-d "$j") /bin/mv $j $j.old
	/bin/mv $j.d $j
        endif
end
