#!/bin/csh
#-----------------------------------------------------------------------
#;  Copyright (C) 2010
#;  Associated Universities, Inc. Washington DC, USA.
#;
#;  This program is free software; you can redistribute it and/or
#;  modify it under the terms of the GNU General Public License as
#;  published by the Free Software Foundation; either version 2 of
#;  the License, or (at your option) any later version.
#;
#;  This program is distributed in the hope that it will be useful,
#;  but WITHOUT ANY WARRANTY; without even the implied warranty of
#;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#;  GNU General Public License for more details.
#;
#;  You should have received a copy of the GNU General Public
#;  License along with this program; if not, write to the Free
#;  Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
#;  MA 02139, USA.
#;
#;  Correspondence concerning AIPS should be addressed as follows:
#;         Internet email: aipsmail@nrao.edu.
#;         Postal address: AIPS Project Office
#;                         National Radio Astronomy Observatory
#;                         520 Edgemont Road
#;                         Charlottesville, VA 22903-2475 USA
#-----------------------------------------------------------------------
set day = "`date +%Y.%j.%H%M%S`"
set tmp = "/tmp"
set run = "${tmp}/BDFLIST.run.${day}"
set log = "${tmp}/BDFLIST.log.${day}"
echo "Time is ${day}"
#                                    aips_root
if (-f $AIPS_ROOT/LOGIN.CSH ) then
   set air = "$AIPS_ROOT"
else
   echo -n "enter $AIPS_ROOT"
   set air = $<
endif
source ${air}/LOGIN.CSH
echo "Obit is `which ObitTalk`"
#                                    ask questions
echo -n "BDF dir-path : "
set bdfd = $<
echo -n "AIPS usrnumb : "
set anum = $<
if ( ${anum} == "" ) then
   echo -n "AIPS usrnumb REQUIRED: "
   set anum = $<
endif
#echo "path ${PATH}"
touch ${log}
cat > ${run} << EOF
#LS@NRAO: Runfile for ObitTalk auto-created ${day} (Y.j.HM)
user=${anum}
from OTObit import *
AIPS.AIPS.userno=user
OSystem.PSetAIPSuser (user)
err=OErr.OErr()
x=ObitTask("ASDMList")
x.DataRoot="${bdfd}"
x.DataType="FITS"
x.doCrt=-1
x.prtFile="${log}"
x.taskLog="${log}"
x.i
x.g
EOF
cat ${run} >> ${log}
echo >> ${log}
echo "Run file ${run}"
echo "ObitTalk ${run} >> ${log}" >> ${log}
echo "Resulting log from above input and command line follows:" >> ${log}
echo >> ${log}
ObitTalk ${run} >> ${log}
echo >> ${log}
echo "Done at `date +%H%M`" >> ${log}
echo "Log file ${log}"
cat ${log}
#echo "Done at `date +%H%M`"
exit
