
print "Make_flux.pl, Matt, 7 May 2007\n";
print "Edit file 'list' and the directories in 'path' variable to required values\n";
print "  before running script.  Be sure the directories are made.  \n";
print "  Comment out mirsi_flux line if want to test script and GDL first.\n";
print "  (Cancel now if need to abort.)\n\n";
$ans=<>;
open(fp1,">flux.batch") || die;

$list_file="list_flux";

open(fp0,"$list_file") || die;
print fp1 "infiles = [ \$\n";

$line=<fp0>;
chomp($line);
$infile="$line";
print fp1 "	\"$infile\"";
while ($line=<fp0>) {
	chomp($line);
	$infile="$line";
	print fp1 ",\$\n	\"$infile\"";
}
print fp1 " \$\n]\n";

open(fp0,"$list_file") || die;
print fp1 "outfiles = [ \$\n";

$line=<fp0>;
chomp($line);
$line=~/b(.+)\.fits/;
$outfile="flux/c$1.txt";
print fp1 "	\"$outfile\"";
while ($line=<fp0>) {
	chomp($line);
	$line=~/b(.+)\.fits/;
	$outfile="flux/c$1.txt";
	print fp1 ",\$\n	\"$outfile\"";
}
print fp1 " \$\n]\n";
close(fp0);

print fp1 "paths = [\"reg\", \".\"]\n";
print fp1 "aper = [1, 15, 15]\n";
print fp1 "skyrad = [20, 30]\n";
print fp1 "n = n_elements(infiles)\n";
print fp1 "for i = 0, (n-1) do begin\n";
print fp1 "	print, infiles[i], outfiles[i], paths\n";
print fp1 "	flux, infiles[i], outfiles[i], paths, aper, skyrad\n";
print fp1 "endfor\n";
print fp1 "end\n";

close(fp1);

