#! /usr1/local/bin/perl -w
$dataroot = "wget -q -nH --cut-dirs=3 -r -l0 -c -nc -np ftp://legacy.gsfc.nasa.gov/FTP/integral/data//";
$auxroot  = "wget -q -nH --cut-dirs=3 -r -l0 -c -nc -np ftp://legacy.gsfc.nasa.gov/FTP/integral/data//aux/adp/";
$auxold = " ";

print "What is the file containing the list of SCWs?\n";
$filename = <STDIN>;
substr($filename,-1,1) = "";

open(POINT,"$filename");
open(POINT2,">scw-aux_download");

print POINT2 "#!/bin/sh\n";

print "Would you like to download AUX reference data? (yes/no)\n";
$query1 = <STDIN>;
substr($query1,-1,1) = "";

print "Would you like to download AUX revolution data? (yes/no)\n";
$query2 = <STDIN>;
substr($query2,-1,1) = "";

if ($query1 eq "yes")
   {
   $foo = "ref";
   print POINT2 "$auxroot$foo\/\n";
   }

while ($scw = <POINT>)
	{
        $scw    = substr($scw,0,25);
        $newscw = "$dataroot$scw";
        print POINT2 "$newscw\/\n";

        $auxnew = substr($scw,4,4);

        if ($auxnew ne $auxold)
           {
           $rev = "$dataroot\scw\/$auxnew\/rev.001\/";

           if ($query2 eq "yes")
              {
              $aux = "$auxroot$auxnew\.001\/";
              print POINT2 "$aux\n";
              }

           print POINT2 "$rev\n";
           $auxold = $auxnew;
           }
        }

system("chmod 755 scw-aux_download");

close(POINT);
