#!/usr/bin/perl use Getopt::Long; use File::Copy; $correctname=substr($0,0); use lib "/mt/apps/gpms/DateTrans/lib"; use DateTrans qw(monName monNumber timeFormat AmPmFormat dayNumbeFormat); use lib "/mt/apps/gpms/DateTrans/lib"; use xsdxsltcheck qw(xsdcheck xsltcheck FGDC2MRFcheck xsl4mrf2fgdccheck); use File::Basename; sub usage() { print "Usage: perl $correctname [-directory=-theme=]\n"; print "Example:\n"; print "perl $correctname -directory=directory -theme=theme \n"; print "theme is one of the following shortcut theme words: boundaries: Governmental Units, and Administrative and Statistical Boundaries cultural: Cultural Resources transportation: Transportation governmental units: Governmental Units, and Administrative and Statistical Boundaries \n"; }; %gOptions; &GetOptions(\%gOptions, qw(theme=s directory=s) ); unless ($gOptions{theme} and $gOptions{directory} ) { usage(); exit(1); }; chomp($NGDATheme=$gOptions{theme}); chomp($InDir =$gOptions{directory}); #print "\$NGDATheme = $NGDATheme\n"; #print "\$InDir = $InDir\n"; $outDir = "/mtdata001/geo/gpms/output/ISO"; if ($NGDATheme eq "boundaries"){ $correctNGDATheme = "Governmental Units, and Administrative and Statistical Boundaries"; }elsif($NGDATheme eq "Boundaries"){ $correctNGDATheme = "Governmental Units, and Administrative and Statistical Boundaries"; }elsif($NGDATheme eq "cultural"){ $correctNGDATheme = "Cultural Resources"; }elsif($NGDATheme eq "Cultural"){ $correctNGDATheme = "Cultural Resources"; }elsif($NGDATheme eq "Transportation"){ $correctNGDATheme = "Transportation"; }elsif($NGDATheme eq "transportation"){ $correctNGDATheme = "Transportation"; }elsif($NGDATheme eq "governmental units"){ $correctNGDATheme = "Governmental Units, and Administrative and Statistical Boundaries"; }; #print "\$correctNGDATheme = $correctNGDATheme\n"; #------------------------------------getting the date--------------------------------------------------------------------------------------------------------- my $now=`date`; $mon = substr($now,4,3); $day=substr($now,8,2); $year =substr($now,24,4); $hour = substr($now,11,2); $min = substr($now,14,2); my $daynum= dayNumbeFormat($day); my $monName=monName($mon); my $monnum =monNumber($mon); if ($day<10){ $singleDay= substr($day,1,1); $dayNum="0" . $singleDay; }else{ $dayNum=$day; }; $dateString = $year . "-" . $monnum . "-" . $dayNum; #print "\$dateString = $dateString\n"; opendir INDIR, $InDir or die "Cannot open $InDir $!"; foreach $file (readdir INDIR){ #print "\$file = $file\n"; $dotPos=rindex($file,"."); $firstDot=index($file,"."); $dashPos=rindex($file,"_"); $length=$firstDot-$dashPos-1; #print "\$dotPos = $dotPos\n"; #print "\$dashPos = $dashPos\n"; #print "\$length = $length\n"; $ext=substr($file,$dotPos+1,3); $gcoDateCounter=0; $themeCounter=0; $TemporalExtentCounter=0; if ($ext eq "xml"){ $fileTheme=substr($file,$dashPos+1,$length); $finalOutDir = $outDir . "/" . $fileTheme; $outFile= $finalOutDir . "/" . $file; $inFile = $InDir . "/" . $file; system "mkdir $finalOutDir"; open INFILE, "<$inFile"; open OUTFILE, ">$outFile "; print "\$ext = $ext\n"; print "\$fileTheme = $fileTheme\n"; print "\$finalOutDir = $finalOutDir\n"; print "\$outFile = $outFile\n"; print "\$inFile = $inFile\n"; while (){ if ($_ =~ /gco:Date/){ if ($gcoDateCounter <1 ){ print OUTFILE "$dateString "; $gcoDateCounter++; }else{ print OUTFILE "$_" };#if ($gcoDateCounter <1 ){ }elsif($_ =~ //){ print OUTFILE ""; print OUTFILE " dvdRom "; print OUTFILE ""; print OUTFILE ""; print OUTFILE ""; print OUTFILE "iso9660"; print OUTFILE " "; print OUTFILE ""; }elsif($_ =~ /\<\/gmd:descriptiveKeywords>/){ print "\$themeCounter = $themeCounter\n"; if ($themeCounter<1){ print OUTFILE "$_"; $themeCounter++; print "\$themeCounter = $themeCounter\n"; print "------------------------------------------------\n"; }else{ print OUTFILE "$_"; print OUTFILE ""; print OUTFILE ""; print OUTFILE " "; $GcoString = " " . $correctNGDATheme . ""; print OUTFILE "$GcoString"; print OUTFILE ""; print OUTFILE ""; print OUTFILE " theme \n"; print OUTFILE " \n"; print OUTFILE "\n"; print OUTFILE "\n"; print OUTFILE "\n"; print OUTFILE " NGDA Portfolio Themes\n"; print OUTFILE " \n"; print OUTFILE " \n"; print OUTFILE "\n"; print OUTFILE "\n"; print OUTFILE "2010-02-01"; print OUTFILE "\n"; print OUTFILE "\n"; print OUTFILE " revision \n"; print OUTFILE " \n"; print OUTFILE " \n"; # print OUTFILE " \n"; # print OUTFILE " http://www.fgdc.gov/initiatives/resources/2013-2-1-ngda-data-themes-fgdc-sc-revised.pdf \n"; # print OUTFILE " \n"; print OUTFILE " \n"; print OUTFILE " \n"; print OUTFILE " \n"; print OUTFILE " http://www.fgdc.gov/initiatives/resources/2013-2-1-ngda-data-themes-fgdc-sc-revised.pdf \n"; print OUTFILE " \n"; print OUTFILE " \n"; print OUTFILE " \n"; # print OUTFILE " \n"; print OUTFILE " \n"; print OUTFILE " \n"; }; }elsif ($_ =~ /codeList=\"http:\/\/www.tc211.org\/ISO19139\/resources\/codeList.xml#MD_MaintenanceFrequencyCode\"/){ if ($_ =~ /gmd:MD_MaintenanceFrequencyCode/){ print OUTFILE "\n"; $TemporalExtentCounter++; #elsif($_ =~/"publication "/){ #qLoc=index($_, }else{ print OUTFILE "$_"; }; }elsif($_ =~/unpublished material/){ print OUTFILE "\n"; }elsif($_ =~/"publication "/){ $qLoc=index($_,"\""); $firstPart=substr($_,0,$qLoc); $newString= $firstPart . "\"publication\""; print OUTFILE "$newString\n"; }elsif($_ =~/"dataset "/){ $qLoc=index($_,"\""); $firstPart=substr($_,0,$qLoc); $newString= $firstPart . "\"dataset\">"; #print OUTFILE ""; print OUTFILE "$newString\n"; }elsif($_ =~/.\/resources\/codeList.xml#CI_DateTypeCode/){ $qLoc=index($_,"\"")+1; $lastqLoc=rindex($_,"#"); $firstPart=substr($_,0,$qLoc); $codeValue=index($_,"codeListValue"); if ($codeValue >0){ $lastPartA=substr($_,$lastqLoc); $lastqLocPartA=rindex($_,"\""); #$lastPart=substr($lastPartA,$lastqLocPartA); $lastPart=substr($lastPartA,$lastqLoc); $newString= $firstPart . "http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_DateTypeCode\"" . " codeListValue=\"publication\"" . $lastPart; print OUTFILE ""; print OUTFILE "$newString\n"; }else{ #print OUTFILE ""; #print OUTFILE ""; #print OUTFILE ""; $newString= $firstPart . "http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_DateTypeCode\"" . $lastPart; print OUTFILE "$newString\n"; #print OUTFILE ""; }; }elsif($_ =~/http:\/\/www.isotc211.org\/2005\/#MD_ScopeCode/){ $qLoc=index($_,"\"")+1; $lastqLoc=rindex($_,"#"); $firstPart=substr($_,0,$qLoc); $lastqLoc=rindex($_,"#")+13; $lastPart=substr($_,$lastqLoc); $newString= $firstPart . "http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_ScopeCode" . $lastPart; print OUTFILE "$newString\n"; }elsif($_ =~/sepereating/){ $sepLoc=index($_,"sep")-1; $preSep=substr($_,0,$sepLoc); $newString=$preSep . " separating the stylesheets into sections. "; print OUTFILE "$newString\n"; }elsif($_ =~/deliveried/){ $preDeLoc=index($_,"del"); $preDe=substr($_,0,$preDeLoc); $postIedLoc=index($_,"ied")+3; $postIed=substr($_,$postIedLoc); $newString = $preDe . "delivered" . $postIed; print OUTFILE "$newString\n"; }elsif($_ =~/Catolog/){ $preCatLoc=index($_,"Cat")-1; $preCat=substr($_,0,$preCatLoc); $postLogLoc=index($_,"log")+3; $postLog=substr($_,$postLogLoc); $newString= $preCat . " catalog" . $postLog; print OUTFILE "$newString\n"; }elsif($_ =~/descriptions.Coordinates/){ $preonLoc=index($_,"s.C"); $partOne=substr($_,0,$preonLoc+1); $partTwo=substr($_,$preonLoc+2); $newString=$partOne . ". " . $partTwo; print OUTFILE "$newString\n"; }elsif($_ =~/pointofContact/){ $pointLoc=index($_,"pointofContact")-1; $postLoc=index($_,"act"); $prePoint=substr($_,0,$pointLoc); $postPoint=substr($_,$postLoc+3); $newString=$prePoint . "\"pointOfContact" . $postPoint; #print OUTFILE "\n"; #print OUTFILE "\n"; print OUTFILE "$newString\n"; }else{ print OUTFILE "$_" };#if ($_ =~ /gco:Date/){ };#while (){ };#if ($ext eq "xml"){ };#foreach $file (readdir INDIR){