; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=MATRIX PRNFILE="{SCENARIO_DIR}\output\MCMAT00C.PRN" MSG='Convert modeshares and CBD shares to DBF'
FILEI LOOKUPI[2] = "{SCENARIO_DIR}\output\CBDSHARES.CSV"
FILEI LOOKUPI[1] = "{SCENARIO_DIR}\output\MODESHARES.CSV"
FILEO RECO[2] = "{SCENARIO_DIR}\output\CBDSHARES.DBF",
FORM=10.6,FIELDS=N2,HBW1,HBNW1,NHB1
FILEO RECO[1] = "{SCENARIO_DIR}\output\MODESHARES.DBF",
FORM=10.6,FIELDS=N1,HBW,HBNW,NHB

zones=1
array Pshr=108, Pcbdshr=12

; LOOKUP for previuos run shares
LOOKUP NAME=SHARES, 
       LOOKUP[1]=1, 
       RESULT=4,
       FAIL=0,0,0,
       LIST=Y,
       INTERPOLATE=N, 
       LOOKUPI=1

LOOKUP NAME=CBDSHARES, 
       LOOKUP[1]=1, 
       RESULT=3,
       FAIL=0,0,0,
       LIST=Y,
       INTERPOLATE=N, 
       LOOKUPI=2

; records 1 through 6 are for 6 choices for HBW purpose and 0 car households, next 6 is for HBW purpose and 1 car household....
LOOP _ww=1,54
 Pshr[_ww] = SHARES(1,_ww)
ENDLOOP

; 3 cbd targets (for walk, pnr,knr ) and 3 purposes
LOOP _ww=1,9
 Pcbdshr[_ww] = CBDSHARES(1,_ww)
ENDLOOP

; print REVISED modal constants
LOOP _ww=1,18
 _idx=_idx+1
 RO.N1=_ww
 RO.HBW=Pshr[_idx]
 RO.HBNW=Pshr[_idx+18]
 RO.NHB=Pshr[_idx+36]
 WRITE RECO=1
ENDLOOP

LOOP _xx=1,3
 RO.N2=_xx
 RO.HBW1=Pcbdshr[_xx]
 RO.HBNW1=Pcbdshr[_xx+3]
 RO.NHB1=Pcbdshr[_xx+7]
 WRITE RECO=2
ENDLOOP

ENDRUN
