# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # Copyright (C) Zvi Leve, INRO Consultants, 1999. All rights reserved. # # The right to use this script is granted to all EMME/2 users, provided the # following conditions are met: # 1) The script cannot be sold for a fee (but it can be used and distributed # without charge within consulting projects). # 2) The user is aware that this script is not a part of the EMME/2 software # licence and there is no explicit or implied warranty or support # provided with this script. # 3) The comments in this script must not be removed and any additions or # modification must be appropriately identified as such and give at least # date, name and the reason of the modification. #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # # The script shiftnod.awk 1.7 converts an EMME/2 network file # (nodes,links,lines,turns,matrices,extra-attributes) so that # node numbers within a range are shifted by a specified value # (positive or negative). # # 25-10-99 modification Zvi Leve: Additional options to allow shifting of # matrices and additional attributes (one type at a time); # improved efficiency # # 02-11-99 modification Diane Larin: Add possibility to specify variables on # the command line # # That is: + SHIFT VALUE ==> # # The user is interactively prompted to enter a RANGE of node # numbers for modification. All node numbers between the # START and END values will be changed by the shift value. # Node numbers outside the specified range are not modified. # # NOTE that it is IMPERATIVE to assure that existing node numbers will # not be affected by the transformation! # # If different ranges of node numbers are to be shifted, or # different shift values are to be used, then the output # file from one iteration of this script can be re-entered as # input for the next shift-operation. Caution must be used to assure # that the shifted node numbers will not be modified again! # # The input file must be one of the EMME/2 batch output files ("punch"): # network (from module 2.14) # transit lines (from module 2.24) # turns (from module 2.31) # network attributes (from module 2.41) # matrices (from module 3.14) # # The script will create a converted file containing the network elements # based on the 'shifted' node numbers. This file is in EMME/2 batch input format. # # USAGE: # interactive: gawk -f shiftnod.awk # UNIX: gawk -f shiftnod.awk [-v min=] [-v max=] # [-v shift=] [-v ofile=] # BEGIN { if (ARGC < 2) { print "This script must be called with an input file!!!" exit 1 } if (min || max || shift || ofile) {skip_usage=1} if (! skip_usage) { print print "SHIFTNOD.AWK 1.7 - EMME/2 Node Number Adjustment Utility" print print "********************************************************" print "** **" print "** USAGE: gawk -f shiftnod.awk **" print "** **" print "** Enter RANGE of numbers to shift: **" print "** START from: XXXX **" print "** END at: YYYY **" print "** Enter SHIFT value: ZZZZ **" print "** NAME of output file: OUTPUT FILE **" print "** **" print "********************************************************" print print "Enter RANGE of numbers to shift: " } while (! min) { printf "START from: " getline min <"-" } while (! max) { printf "END at: " getline max < "-" } if (min>=max) { print "START must be less than END!!!" exit 2 } while (! shift) { printf "Enter shift value (positive or negative): " getline shift < "-" if (! shift) print "A shift value must be ENTERED!!!" } while (! ofile) { printf "NAME of output file: " getline ofile < "-" if (! ofile) print "AN OUTPUT FILE must be ENTERED!!!" } min=min*1 max=max*1 shift=shift*1 modify="header" } modify == "header" { if (NR == 1) { # Make sure that input file is not overwritten!!! while (ofile == FILENAME) { print "INPUT AND OUPUT FILES ARE THE SAME!!!" ofile="" while (! ofile) { printf "ENTER A NEW FILE NAME: " getline ofile < "-" if (! ofile) print "A NEW FILE NAME must be ENTERED!!!" } } print "Converting ... \""FILENAME"\" INTO \""ofile"\"" print "c SHIFTNOD.AWK 1.7 converted \""FILENAME"\" INTO \""ofile"\"">ofile } # Output comments unchanged.... if ($1 == "c") { print >> ofile next} # Check type of element to modify # network elements.... if ($1 == "t") { if ($2 == "nodes") modify="nodes" if ($2 == "lines") modify="lines" if ($2 == "turns") modify="turns" if ($2 == "matrices") modify="matrices" } # extra-attributes.... if ($1 == "inode") modify="node_attributes" if ($2 == "jnode") modify="link_attributes" if ($3 == "jnode") modify="segment_attributes" if ($3 == "knode") modify="turn_attributes" # Unknown file type if (modify == "header") { print "ERROR: Unrecognizable file type!!!" exit} print >> ofile next } modify == "nodes" { # check if done with node section.... if ($1 == "t") { printf("t links\n") >> ofile modify="links" next} # check centroid/node number if ($2 >= min && $2 <= max) $2=$2+shift # modify label (if necessary) if ($8 >= min && $8 <= max) $8=$8+shift print ($0) >> ofile } modify == "links" { if ($1 == "a") { # check inode if ($2 >= min && $2 <= max) $2=$2+shift # check jnode if ($3 >= min && $3 <= max) $3=$3+shift print ($0) >> ofile } else {exit} } modify == "lines" { if (substr($0,1,1) == "a") {print >> ofile } else { for (i = 1; i <= NF; ++i) { if ($i ~ /\=/) {printf " %s ", $i >> ofile } else { if ($i >= min && $i <= max) { node=$i+shift } else {node=$i} printf " %s ",node >> ofile } } printf("\n") >> ofile } } modify == "turns" { if (substr($0,1,1) == "a") { # check "at" node if ($2 >= min && $2 <= max) $2=$2+shift # check "from" node if ($3 >= min && $3 <= max) $3=$3+shift # check "to" node if ($4 >= min && $4 <= max) $4=$4+shift print ($0) >> ofile } else {exit} } modify == "matrices" { if (substr($0,1,1) == "a") {print >> ofile } else { if ($1 >= min && $1 <= max && $1 != "all") $1=$1+shift for (i = 2; i <= NF; ++i) { if ($i ~ /\:/) { split($i,D,"\:") if (D[1] >= min && D[1] <= max) D[1]=D[1]+shift $i=D[1]"\:"D[2] } } print (" "$0) >> ofile } } modify == "node_attributes" { if ($1 >= min && $1 <= max) $1=$1+shift print ($0) >> ofile } modify == "link_attributes" { if ($1 >= min && $1 <= max) $1=$1+shift if ($2 >= min && $2 <= max) $2=$2+shift print ($0) >> ofile } modify == "segment_attributes" { if ($2 >= min && $2 <= max) $2=$2+shift if ($3 >= min && $3 <= max) $3=$3+shift print ($0) >> ofile } modify == "turn_attributes" { if ($1 >= min && $1 <= max) $1=$1+shift if ($2 >= min && $2 <= max) $2=$2+shift if ($3 >= min && $3 <= max) $3=$3+shift print ($0) >> ofile } END {}