; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=HIGHWAY PRNFILE="{Scenario_Dir}\OUTPUT\TDHWY00B.PRN" MSG='Develop Congested Skims'
FILEI LOOKUPI[1] = "{Catalog_Dir}\Parameters\TTPREP.CSV"
FILEO MATO[1] = "{Scenario_Dir}\OUTPUT\CONGSKIM_{ALT}{Year}.MAT",
MO=1-9,NAME=STOLL,SDISTANCE,STIME,STERMINALTIME,STIME2,HTOLL,HDISTANCE,HTIME,HTIME2
FILEI TURNPENI = "{SCENARIO_DIR}\Input\TURN_{Year}{ALT}.PEN"
FILEI NETI = "{SCENARIO_DIR}\OUTPUT\PREASSIGN_{ALT}{Year}.NET"

PAR ZONES={ZONESA}

PAR ZONEMSG=100

 LOOKUP,NAME=TERMTIME,LOOKUP[1]=1, RESULT=2, INTERPOLATE=N, LOOKUPI=1

PROCESS PHASE=LINKREAD
; Use this phase to obtain initial values from the input network (LI.varname) and compute 
; link values (LW.varname) that can be used in other phases.
;IF (LI.FACILITY_T=80-89) ADDTOGROUP=1
;IF(LI.FACILITY_T=49,59,69) ADDTOGROUP=9
LW.TIME=LI.TIME_1
 ; IF (LI.AREA_TYPE=10-19) _ATYPE1=1
;IF (LI.AREA_TYPE=20-29) _ATYPE1=2
;IF (LI.AREA_TYPE=30-39) _ATYPE1=3
;IF (LI.AREA_TYPE=40-49) _ATYPE1=4
;IF (LI.AREA_TYPE=50-59) _ATYPE1=5
;IF (A=1-{ZONESA}) TERMTIME[A]=TERM[_ATYPE1]
ENDPROCESS


PROCESS PHASE=ILOOP
; This phase performs a zonal loop (I=1,Zones).  This phase is required and must contain
; at least 1 PATHLOAD statement.  Almost all MATRIX operation are available in this phase
; and the PATHLOAD statement can be used to build and load paths for assignment
   PATHLOAD PATH=LW.TIME, PENI=1, 
      MW[1]=PATHTRACE(LI.CARTOLL), NOACCESS=0,
      MW[2]=PATHTRACE(LI.DISTANCE), NOACCESS=0,
      MW[3]=PATHTRACE(LI.TIME_1), NOACCESS=0,
     ;MW[4]=PATHTRACE(LW.TIME), NOACCESS=0
; BUILD TERMINAL TIME MATRIX
      MW[4]=TERMTIME(1,I)+TERMTIME(1,J)
    ;  PATHLOAD PATH=LW.TIME, PENI=1, ;Pathload      
    ;  MW[1]=PATHTRACE(LW.TIME),NOACCESS=0, 
    ;  MW[2]=PATHTRACE(LI.DISTANCE),NOACCESS=0,
    ;  MW[4]=PATHTRACE(LI.CARTOLL),NOACCESS=0,
    ;  MW[5]=PATHTRACE(LW.TIME),NOACCESS=0
    ;  MW[3]=TERMTIME(1,I)+TERMTIME(1,J) ; BUILDS TERMINAL TIME MATRIX
    ;  EXCLUDEGROUP=1,9
 ; MW[1][I]=lowest(1,{IZzone})/{IZzone} ; INTRAZONAL TIME = 1/2 THE AVERAGE OF THE {IZzone} NEAREST ZONES
 ; MW[2][I]=lowest(2,{IZzone})/{IZzone} ; INTRAZONAL DISTANCE = 1/2 THE AVERAGE OF THE {IZzone} NEAREST ZONES
 ; MW[4][I]=lowest(4,{IZzone})/{IZzone} ; INTRAZONAL TOLL = 1/2 THE AVERAGE OF THE {IZzone} NEAREST ZONES
 ; MW[5][I]=lowest(5,{IZzone})/{IZzone} ; INTRAZONAL TIME2 = 1/2 THE AVERAGE OF THE {IZzone}NEAREST ZONES
AG={IZzONE};*2
loop _IZ=1,3;4
  mw[_IZ][i]=lowest(_IZ,{IZzone})/AG
endloop

MW[5]=MW[3]
MW[6]=MW[1]
MW[7]=MW[2]
MW[8]=MW[3]
MW[9]=MW[5]
;JLOOP
; IF (99999=MW[1]*2) MW[1]=99999 ;Make NOACCESS intrazonals 99999
;ENDJLOOP
ENDPROCESS


;PROCESS PHASE=ADJUST
; This phase is automatically run after the ILOOP phase.  The volume-delay functions (TC) are
; automatically recomputed in this phase to update the link congested travel times based 
; on the volumes from the ILOOP phase.  User defined link computations (LW.varname) that 
; need to be updated based on the new congested travel times should be coded in this phase.


;ENDPROCESS

ENDRUN
