www.pudn.com > sphinx_recipe.zip > ConvertAndCopy.pl


#!/usr/bin/perl

# Given a list of *.WV1 files, convert them to uncompressed
# sphere headed wave files using sph2pipe and copy them to
# a new directory location, creating directories as needed.
#
# Also creates a parallel directory structure in another
# directory where we'll eventually put the .mfc files.
#
# Copyright 2006 by Keith Vertanen
#

use strict;

if ( @ARGV < 3 )
{
    print "$0   \n"; 
    exit(1);
}

my $dirFeature;
my $dirTarget;
my $wv1File;
my $line;
my %dirsCreated;
my @chunks;
my $i;
my $dir;
my $target;

($wv1File, $dirTarget, $dirFeature)  = @ARGV;

open(IN, $wv1File);
while ($line = ) 
{
    $line =~ s/\n//g;
    $line =~ s/\r//g;

    if ($line)
    {
#	print $line . "\n";
	
	# Lines is like:
	#	./SI_TR_S/40O/40OA010Z.WV1
	# Create any directories needed for this file
	
	@chunks = split(/\//, $line);
	$dir = "";
	for ($i = 1; $i < scalar @chunks - 1; $i++)
	{
	    $dir = $dir . $chunks[$i];
	    $dir = $dir . "/";
	    
	    if (!$dirsCreated{$dir})
	    {
		mkdir $dirTarget . "/" . $dir;
		
		# Create the parallel directory structure in the other directory.
		mkdir $dirFeature . "/" . $dir;
		
		#print $dirTarget . "/" . $dir . "\n";

		$dirsCreated{$dir} = 1;
	    }
	}
	
	$target = $dirTarget . substr($line, index($line, "/"));
	$target = substr($target, 0, rindex($target, "."));
	$target = $target . ".sph";
	
#	print $target . "\n";
	
	system "sph2pipe -f sph $line >$target";
	
    }    
}
close IN;