; 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\TPNET00L.PRN" MSG='Transit speeds for off-peak period'
FILEI LINKI[1] = "{SCENARIO_DIR}\output\unloaded_{alt}{year}.net"
FILEO PRINTO[1] = "{SCENARIO_DIR}\Output\XY_{alt}{year}.DAT"
FILEI LOOKUPI[1] = "{Catalog_Dir}\Parameters\TRANSPD.dbf"
FILEO NETO = "{SCENARIO_DIR}\output\unloaded2_{alt}{year}.net"

PROCESS  PHASE=NODEMERGE
; Use this phase to make computations and selections of any data on the NODEI files.
  print list=n(6.0),x(20.2),y(20.2),printo=1
ENDPROCESS

PROCESS PHASE=LINKMERGE

  ;If auto travel time is not present or is zero, a default value of 15 mph is used.
  IF (TIME>0)
    _AUTOSPEED=60*DISTANCE/TIME
  ELSE
    _AUTOSPEED=15
  ENDIF

;**************************************************************
;BEGIN POTENTIAL SCRIPT ADJUSTMENT
;**************************************************************

;************************************************************************************************
;* DEFAULT TRANSIT SPEEDS SET EQUAL TO AUTO SPEEDS. APPLY APPROPRIATE TRANSIT SPEED CURVES HERE.*
;************************************************************************************************

lookup name=curve,
     lookup[1]=CURVE_NO, result=LOW_MODE,
     lookup[2]=CURVE_NO, result=HIGH_MODE,
     lookup[3]=CURVE_NO, result=LOW_FT,
     lookup[4]=CURVE_NO, result=HIGH_FT,
     lookup[5]=CURVE_NO, result=LOW_AT,
     lookup[6]=CURVE_NO, result=HIGH_AT,
     lookup[7]=CURVE_NO, result=SPEEDRATIO,
     interpolate=n,fail=0,0,0,list=y,lookupi=1
array lm=500,hm=500,lf=500,hf=500,la=500,ha=500,sr=500

loop _nn=1,500
   LM[_nn]=CURVE(1,_nn)
   HM[_nn]=CURVE(2,_nn)
   LF[_nn]=CURVE(3,_nn)
   HF[_nn]=CURVE(4,_nn)
   LA[_nn]=CURVE(5,_nn)
   HA[_nn]=CURVE(6,_nn)
   SR[_nn]=CURVE(7,_nn)
if (lm[_nn]>0) _numberofcurves=_nn ; obtain the total number of curves fromt he curve file
if (lm[_nn]<=0) break
endloop
  LOOP _nn=1,_numberofcurves
    if ((FACILITY_TYPE >= LF[_nn]) & (FACILITY_TYPE <= HF[_nn]) & (AREA_TYPE >= LA[_nn]) & (AREA_TYPE <= HA[_nn]))
     if ((LM[_nn] >= 21) & (HM[_nn] <= 21)) spdratioM21 = SR[_nn]
     if ((LM[_nn] >= 22) & (HM[_nn] <= 22)) spdratioM22 = SR[_nn]
endif
  ENDLOOP
  IF (_AUTOSPEED>0)
       _TSPD21=spdratioM21*_AUTOSPEED  ; Bus Speeds
       _TSPD27=spdratioM22*_AUTOSPEED  ; Project mode

       M21TIMEOP=60*(DISTANCE)/_TSPD21
       M27TIMEOP=60*(DISTANCE)/_TSPD27
    ENDIF
  ; WALK CONTROLS
       WALKTIME=60*DISTANCE/{AVGWLKSPD}
     IF(FACILITY_TYPE=10-19,70-99)
       WALKTIME=999.99
     ENDIF
     IF(FACILITY_TYPE=59)
       WALKTIME=1
       distance=0.05
       ADJDISTANCE = DISTANCE
     ENDIF

     IF (A=={FromNode} && B=={ToNode})
       list="\n\n"
       list="     An     Bn   Dist   ASpd   Atim   TSpd   Ttim    Crv"
       list=A(7.0),B(7.0),DISTANCE(7.2),_AUTOSPEED(7.2),TIME(7.2),_TSPD21(7.2),M21TIMEOP(7.2),_CURVEMODE21(7.0)," MODE21"
       list=A(7.0),B(7.0),DISTANCE(7.2),_AUTOSPEED(7.2),TIME(7.2),_TSPD22(7.2),M27TIMEOP(7.2),_CURVEMODE27(7.0)," MODE27"
       ;list=A(7.0),B(7.0),DISTANCE(7.2),_AUTOSPEED(7.2),TIME(7.2),_TSPD23(7.2),M23TIMEOP(7.2),_CURVEMODE23(7.0)," MODE23"
       ;list=A(7.0),B(7.0),DISTANCE(7.2),_AUTOSPEED(7.2),TIME(7.2),_TSPD24(7.2),M24TIMEOP(7.2),_CURVEMODE24(7.0)," MODE24"
       ;list=A(7.0),B(7.0),DISTANCE(7.2),_AUTOSPEED(7.2),TIME(7.2),_TSPD25(7.2),M25TIMEOP(7.2),_CURVEMODE25(7.0)," MODE25"
       ;list=A(7.0),B(7.0),DISTANCE(7.2),_AUTOSPEED(7.2),TIME(7.2),_TSPD26(7.2),M26TIMEOP(7.2),_CURVEMODE26(7.0)," MODE26"
       ;list=A(7.0),B(7.0),DISTANCE(7.2),_AUTOSPEED(7.2),TIME(7.2),_TSPD27(7.2),M27TIMEOP(7.2),_CURVEMODE27(7.0)," MODE27"
       ;list="\n\n"
     ENDIF

ENDPROCESS

ENDRUN
