#!/usr/bin/perl


$theme="addr";

$mainDir = "/home/m/mccre004/GPMSscripts/FileMoverDir";
$metadataDir ="http://meta.geo.census.gov/data/existing/decennial/GEO/GPMB/TIGERline/TIGER2013/";
$FirstPartOfLine ="<gco:CharacterString xmlns:gco=\"http:\/\/www.isotc211.org\/2005\/gco\">";
$lastPartOfLine="</gco:CharacterString>";

$indir = $mainDir . "/" . $theme;

opendir INDIR, $indir or die "cannot open $indir: $!";

foreach $file (readdir INDIR ){
print "\$file = $file\n";

$firstdot = index($file, ".");
$predicate = substr($file,0,$firstdot);
$suffix= substr($file,$firstdot);
$newFile = $predicate . "_ver2" . $suffix;

#print "\$predicate = $predicate\n";
#print "\$suffix = $suffix\n";
#print "\$newFile = $newFile\n";

$inFile = $indir  . "/" . $file;
$outnewFile = $indir  . "/" . $newFile;
open INPUT, "<$inFile";
open OUTPUT, ">$outnewFile";

while (<INPUT>){
$line =$_;
#print "\$line= $line";

if ($line =~ /<gco:CharacterString xmlns:gco=\"http:\/\/www.isotc211.org\/2005\/gco\">http:\/\/www2.census.gov\/geo\/tiger\/TIGER2013/){
$newLine =  $FirstPartOfLine .  $metadataDir . $theme . "/" . $file . $lastPartOfLine;
print OUTPUT $newLine;
}else{
print OUTPUT $line;
};





};

};
