Connection Culv=This is Line1
111 111
Conn Culvert Barrel=Culvert1
*
Connection Culv=This is Line2
222 222
Conn Culvert Barrel=Culvert2
*
Connection Culv=This is Line3
333 333
Conn Culvert Barrel=Culvert3
*
####
Connection Culv=This is Line3 - New text here
333 333 This should be new too
Conn Culvert Barrel=Culvert3
*
Connection Culv=This is Line1 - New text here
111 111 This should be new too
Conn Culvert Barrel=Culvert1
*
Connection Culv=This is Line2 - New text here
222 222 This should be new too
Conn Culvert Barrel=Culvert2
*
####
Connection Culv=This is Line1 - New text here
111 111
Conn Culvert Barrel=Culvert1
*
Connection Culv=This is Line2 - New text here
222 222
Conn Culvert Barrel=Culvert2
*
Connection Culv=This is Line3 - New text here
333 333
Conn Culvert Barrel=Culvert3
*
####
Connection Culv=This is Line1 - New text here
111 111 This should be new too
Conn Culvert Barrel=Culvert1
*
Connection Culv=This is Line2 - New text here
222 222 This should be new too
Conn Culvert Barrel=Culvert2
*
Connection Culv=This is Line3 - New text here
333 333 This should be new too
Conn Culvert Barrel=Culvert3
*
####
# HEC-RAS Replacement Perl Script
# This will find and replace values in the HEC-RAS geometry file for modified culvet barrels. The process is:
# 1. In existing model file (HECRAS_Ex.txt) find where there is a "Connection Culv" (this is the line that needs to be replaced)
# 2. It then down for the next Conn Culvert Barrel line (this is the unique identifier)
# 3. It then takes from the new culvert file (culvNEW.txt) the new "Connection Culv" line and replaces it in the existing HECRAS_Ex.txt file.
# 4. Repeats for all and then saves out Output_HECRAS.txt
# Nomenclature for running Perl Script:
# C:\MyDir> perl PERL_SCRIPT.pl culvNEW.txt HECRAS_Ex.txt OutPut_HECRAS.txt
# Read Existing HEC-RAS Geometry File (HECRAS_Ex) with Old Culvert Connection Attributes
open (TEMPLATE, @ARGV[1]) or die;
@HECRAS_Ex = ;
close TEMPLATE;
# Read New Culvert Data File (culvNEW) with new Connection culvert Attributes
open (TEMPLATE, @ARGV[0]) or die;
@culvNEW = ;
close TEMPLATE;
for ($i=0; $i<@HECRAS_Ex; $i++) {
# only check lines starting with "Connection Culv" in the HECRAS_Ex file
if ($HECRAS_Ex[$i] =~ /^Connection Culv/) {
#print $HECRAS_Ex[$i];
#look for Connection Culv backwards
$iback=$i-1;
while ($HECRAS_Ex[$iback] !~ /^Conn Culvert Barrel/) {
$iback=$iback+1;
}
$local0=$HECRAS_Ex[$iback];
chomp($local0);
# print $HECRAS_Ex[$iback];
for ($j=0; $j<@culvNEW; $j++) {
# for ($j=0; $j<1; $j++) {
$local = $culvNEW[$j];
chomp($local);
# print $local;
# Remove the trailing new line
# chomp $local;
# print ($local eq $HECRAS_Ex[$iback]);
if ($local =~ /^$local0/) {
# print "match";
$jforward=$j-1;
while ($culvNEW[$jforward] !~ /^Connection Culv/) {
$jforward=$jforward-1;
}
# print $culvNEW[$jforward];
# Perform substitutions of LG card
$HECRAS_Ex[$i]=$culvNEW[$jforward];
# print $HECRAS_Ex[$i];
}
}
}
}
#write out the Geometry File based on the HECRAS_Ex file structure and the new values in the culvNEW file
open (OUT, ">" . @ARGV[2]) or die;
# Write output
print OUT @HECRAS_Ex;
# Close OUT
close OUT;