#!/star/Perl/bin/perl
require 'cgiSubs.pl';
require 'server.pl';
#@diskList=&getDisks();

@diskList=&getDisksGlob();

$mfFile="/disk11/wsa/ingest/fits/20060723_v1/w20060723_01671_sf_st_two.fit";
$unfiltDirName=&getUnfiltDirName1($mfFile,@diskList);

print "$unfiltDirName \n ";


sub getDisksGlob {
    return glob("/disk[0-9]*");
}
sub getUnfiltDirName1 {
    $filtFilename=$_[0];
    my @disks=@_[1..@_];

    ($name,$path,$suffix) = fileparse($filtFilename);

    $dirname  = basename($path);

    $verPos=index($dirname,"_v",0);
    $version=substr($dirname,$verPos+2,100);
    $preVersion=$version;
    print "$preVersion $dirname \n";
    for ($preversion=$version; $preversion > 0 ; $preversion-- ) {
($unfiltDirName = $dirname) =~ s/_v${version}/_v${preVersion}/g;
print "$unfiltDirName \n";
foreach (@disks) {
    print "$_ \n";
    $ingestDir="/".$_."/wsa/ingest/fits/".$unfiltDirName;
    print "$ingestDir \n";
    if (-e $ingestDir) {
    return $ingestDir;
}
}

    }}

