; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=NETWORK PRNFILE="{Scenario_Dir}\OUTPUT\HNNET00A.PRN" MSG='Process Highway Network'
FILEO LINKO = "{Scenario_Dir}\OUTPUT\LINK4CNT.DBF",
FORMAT=DBF,INCLUDE=A,B
FILEO NETO = "{Scenario_Dir}\OUTPUT\TEMP.NET",
EXCLUDE=LINKCNT
FILEI LOOKUPI[2] = "{Scenario_Dir}\Input\SPDCAP_{Year}{ALT}.CSV"
FILEI LOOKUPI[1] = "{Scenario_Dir}\Input\Vfactors_{Year}{ALT}.CSV"
FILEI LINKI[2] = "{SCENARIO_DIR}\\Input\Tolllink_{Year}{ALT}.DAT",
var=TOLL,beg=1,len=2,  
 var=TOLLTYPE,beg=3,len=2,
 var=A,beg=5,len=6, 
 var=B,beg=11,len=6, 
 var=PLAZADESC,beg=17,len=25,typ=a,
 var=PLZALNSMIN,beg=55,len=2,
 var=PLZALNSMAX,beg=61,len=2,
 var=CARTOLL,beg=67,len=5,
 var=SVCMINUTES,beg=75,len=2,
 var=SVCSECONDS,beg=79,len=2,
 var=DECELCODE,beg=85,len=1,
 var=ACCELCODE,beg=91,len=1,
 var=EXACTCHGLNS,beg=97,len=2,
 var=AVILANES,beg=103,len=2,
 var=PCTTRUCKS,beg=109,len=4 

FILEI LINKI[1] = "{Scenario_Dir}\Input\HWYNET_{Year}{ALT}.NET"

;PROCESS  PHASE=INPUT
;Use this phase to modify data as it is read, such as recoding node numbers.


;ENDPROCESS


;PROCESS  PHASE=NODEMERGE  
; Use this phase to make computations and selections of any data on the NODEI files.


;ENDPROCESS

PAR  LIST_ERRS=0 MAX_IP_ERRS=10000
ARRAY _ATCNT=99,_FTCNT=99
LOOKUP, NAME=VFACTORS, 
    LOOKUP[1]=1, RESULT=2,
    LOOKUP[2]=1, RESULT=3,
    LOOKUP[3]=1, RESULT=4,
    LOOKUP[4]=1, RESULT=5,
    INTERPOLATE=N, LOOKUPI=1
LOOKUP, NAME=SPDCAP, 
    LOOKUP[1]=1, RESULT=2,
    LOOKUP[2]=1, RESULT=3,
    INTERPOLATE=N, LOOKUPI=2

PROCESS PHASE=LINKMERGE
; if no distance in network, calculate one
  distance=ROUND(100*sqrt((a.x-b.x)^2+(a.y-b.y)^2)/{units})/100
; PUT VFACTORS ON NETWORK
  CARTOLL=0
  UROADFACTOR=VFACTORS(1,Facility_Type)
  CONFAC=VFACTORS(2,Facility_Type)
  BPRCOEFFICIENT=VFACTORS(3,Facility_Type)
  BPREXPONENT=VFACTORS(4,Facility_Type)

; PUT SPEEDS AND CAPACITIES ON NETWORK
  _INDEXVAL=10000*Area_Type+100*Facility_Type+Num_LANES

  CAPACITY=SPDCAP(1,_INDEXVAL)
  SPEED=SPDCAP(2,_INDEXVAL)

  IF (SPEED!=0)
    TIME=ROUND(100*60*distance/speed)/100
  ENDIF
  if (time<0.01) time=0.01
ENDPROCESS



;PROCESS  PHASE=SUMMARY   
; Use this phase for combining and reporting of working variables.


;ENDPROCESS

ENDRUN
