directory=$1 #basedir containing dirs for mdl
#$4 #basedir for diana output
#not used yet so only echo
echo "got outputdir (base dir for diana output): $outputdir"
logdir=$2 #place to look for existing looks
logoutputdir=$3
#put new logs into outputdir or central place (would be better)

#usage <base-dir containing dirs for mdl>
#	<log-dir foreach log found the corresponding mdl is exported to diana>
# 	<log-output dir for this run>
# 	<base dir for generated diana models>


logfile="mdl2diana-runner.log"
scriptfile="mdl2diana-runner.sh" 
#reset logfile, otherwise logs will be always appended
echo "running $0 $*">$logfile
#needs to be started with absolute path
mdl2dianascript="/home/rempel/Promot/promot/scripts/promot-server -mdl2dianafromsbml"


#reset scriptfile
echo "#!/bin/sh">$scriptfile 
for file in $logdir/*log
#check existing logs only proceed if log exists (moving logs to control next step)
do
    echo "$file"
#replace xml extension to mdl, in output dir 
	mdldir=$1/`basename $file ".log"`
	mdlfile=$mdldir/`basename $file ".log"`.mdl
	echo "mdl dir: $mdldir"
	echo "mdl file: $mdlfile"
	outputdir=$4/`basename $file ".log"`
	echo "output dir: $outputdir"
	if [ ! -d $outputdir ]; then mkdir -p $outputdir; fi 
	
#replace xml extension to log, in log dir $3
    logfilename=$logoutputdir/`basename $file $extension`
    echo "$logfilename"
    
#log found and generated filenames
	echo "found: $file -> $mdlfile $logfilename" >> $logfile
		echo "$mdl2dianascript \"$mdlfile\" > $logfilename" >> $logfile
		echo "cd $outputdir" >> $scriptfile
	    echo "$mdl2dianascript \"$mdlfile\"" >> $scriptfile 	    
done
`chmod +x $scriptfile`
exec $scriptfile

