; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=DISTRIBUTION PRNFILE="{Scenario_Dir}\OUTPUT\TDDST00A.PRN"
FILEI MATI[2] = "{Scenario_Dir}\OUTPUT\KFACTOR.MAT"
FILEI MATI[1] = "{SCENARIO_DIR}\OUTPUT\FREESKIM_{ALT}{Year}.MAT"
FILEO MATO[1] = "{Scenario_Dir}\OUTPUT\PSNTRIPS_TEMP_{ALT}{YEAR}.MAT",
MO=1-7,DEC=7*S, NAME=HBW,HBSH,HBSR,HBO,NHB,TRKTAXI,IE
FILEI LOOKUPI[1] = "{Catalog_Dir}\Parameters\FF.DBF"
FILEI ZDATI[1] = "{Scenario_Dir}\OUTPUT\PANDA_{ALT}{Year}.DBF"
;FILEI MATI[2] = "{Scenario_Dir}\OUTPUT\KFACTOR.MAT"

PAR MAXITERS={TDistIters},MAXRMSE=10.0, ZONEMSG=100

    LOOKUP, LOOKUPI=1,
        INTERPOLATE=Y, NAME=FF,
        LOOKUP[1]=1,RESULT=2,
        LOOKUP[2]=1,RESULT=3,
        LOOKUP[3]=1,RESULT=4,
        LOOKUP[4]=1,RESULT=5,
        LOOKUP[5]=1,RESULT=6,
        LOOKUP[6]=1,RESULT=7,
        LOOKUP[7]=1,RESULT=8

;   ----- SETUP THE WORKING P'S AND A'S
;HBWKP,HBWKA,HBSHP,HBSHA,HBSRP,HBSRA,HBOTP,HBOTA,NHBSP,NHBSA,LTRKP,LTRKA,
;MTRKP,MTRKA,HTRKP,HTRKA,SOIEP,SOIEA,HOIEP,HOIEA,LDIEP,LDIEA,HDIEP,HDIEA

    SETPA P[1]=P1  A[1]=A1;HBWKA;*ATRFAC(1,I)
    SETPA P[2]=P2  A[2]=A2;HBSHA;*ATRFAC(2,I)
    SETPA P[3]=P3  A[3]=A3;HBSRA;*ATRFAC(3,I)
    SETPA P[4]=P4  A[4]=A4;HBOTA;*ATRFAC(4,I)
    SETPA P[5]=P5  A[5]=A5;NHBSA;*ATRFAC(5,I)
    SETPA P[6]=P6  A[6]=A6;LTRKA;*ATRFAC(6,I)
    SETPA P[7]=P7  A[7]=A7;MTRKA;*ATRFAC(7,I)

;   ----- DO 12 GRAVITY MODELS
    MW[20]=MI.1.STIME+MI.1.STERMINALTIME
    GRAVITY PURPOSE=1, LOS=MW[20], FFACTORS=FF, KFACTORS=MI.2.1
    GRAVITY PURPOSE=2, LOS=MW[20], FFACTORS=FF, KFACTORS=MI.2.2
    GRAVITY PURPOSE=3, LOS=MW[20], FFACTORS=FF, KFACTORS=MI.2.3
    GRAVITY PURPOSE=4, LOS=MW[20], FFACTORS=FF, KFACTORS=MI.2.4
    GRAVITY PURPOSE=5, LOS=MW[20], FFACTORS=FF, KFACTORS=MI.2.5
    GRAVITY PURPOSE=6, LOS=MW[20], FFACTORS=FF, KFACTORS=MI.2.6
    GRAVITY PURPOSE=7, LOS=MW[20], FFACTORS=FF, KFACTORS=MI.2.7

;   ----- GENERATE FREQUENCY DISTRIBUTION REPORTS
FREQUENCY VALUEMW=1  BASEMW=20,  RANGE=1-100, TITLE='HBW TRIP LENGTH FREQUENCY {descr,EditBox-CHARACTER,"Model Description","Base Model"}'
FREQUENCY VALUEMW=2  BASEMW=20,  RANGE=1-100, TITLE='HBSH TRIP LENGTH FREQUENCY {descr}'
FREQUENCY VALUEMW=3  BASEMW=20,  RANGE=1-100, TITLE='HBSR TRIP LENGTH FREQUENCY {descr}'
FREQUENCY VALUEMW=4  BASEMW=20,  RANGE=1-100, TITLE='HBO TRIP LENGTH FREQUENCY {descr}'
FREQUENCY VALUEMW=5  BASEMW=20,  RANGE=1-100, TITLE='NHB TRIP LENGTH FREQUENCY {descr}'
FREQUENCY VALUEMW=6  BASEMW=20,  RANGE=1-100, TITLE='LTRK TRIP LENGTH FREQUENCY {descr}'
FREQUENCY VALUEMW=7  BASEMW=20,  RANGE=1-100, TITLE='MTRK TRIP LENGTH FREQUENCY {descr}'

;IF (ITERATION=1)
;  PRINT FORM=9.0, LIST=I,ZI.1.HBWKP[I],
;        FILE = "C:\FSUTMS\DISTRICT2\NERPM\CUBE\IPFME.ROW"
;  PRINT FORM=9.0, LIST=I,ZI.1.HBWKA[I],
;        FILE = "C:\FSUTMS\DISTRICT2\NERPM\CUBE\IPFME.COL"
;  JLOOP
;      PRINT FORM=9.0, LIST=I,J,MW[2],
;        FILE = "C:\FSUTMS\DISTRICT2\NERPM\CUBE\IPFME.SED"
;  ENDJLOOP
;ENDIF


mw[31]=mw[1]*mw[20]/60
mw[32]=mw[2]*mw[20]/60
mw[33]=mw[3]*mw[20]/60
mw[34]=mw[4]*mw[20]/60
mw[35]=mw[5]*mw[20]/60
mw[36]=mw[6]*mw[20]/60
mw[37]=mw[7]*mw[20]/60

; The DISTRIBUTION module does not have any explicit phases.  The module does run within an implied ILOOP
; where I is the origin zones.  The module has a built in GRAVITY statement for implementing this commonly
; used distribution method.  User defined distribution process can also be defined.

ENDRUN
