; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TGMAT00B.S"


; 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\EXT.PRN" MSG='Creat EETrips Matrix'

FILEI MATI[1] = "{SCENARIO_DIR}\INPUT\EETRIPS_{Year}{ALT}.DBF",
    PATTERN=IJ:V, FIELDS=ORZ,DSZ,AUTO_TRIPS

FILEO MATO[1] = "{Scenario_Dir}\OUTPUT\EETRIPS_{ALT}{Year}.MAT",
  MO=1 
PARAMETERS ZONES={ZONESA} ZONEMSG=100

  MW[1]=MI.1.1

ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TGMAT00C.S"
; 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\DUWEIGHTS.PRN" MSG='Dwelling Unit Weights'
FILEO RECO[1] = "{Scenario_Dir}\OUTPUT\DUWEIGHTS.DBF",
FIELDS=SIZERANGE,PCT1PER,PCT2PER,PCT3PER,PCT4PER,PCT5PER
FILEI RECI = "{Catalog_Dir}\Parameters\DUWEIGHTS.DBF"

SIZERANGE = SIZERANGE +1
PCT1PER=RI.1PERSONHH
PCT2PER=RI.2PERSONHH
PCT3PER=RI.3PERSONHH
PCT4PER=RI.4PERSONHH
PCT5PER=RI.5PERSONHH

WRITE RECO=1



; The MATRIX module does not have any explicit phases.  The module does run within an implied ILOOP
; where I is the origin zones.  All user statements in the module are processed once for each origin.
; Matrix computation (MW[#]=) are solved for all values of J for each I.  Thus for a given origin zone I
; the values for all destination zones J are automatically computed.  The user can control the computations
; at each J by using a JLOOP.

ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TGMAT00D.S"
; 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\GENERATES.PRN" MSG='Production Rates Permanent Population'
FILEO RECO[2] = "{SCENARIO_DIR}\OUTPUT\GRATES_MC.DBF",
FIELDS=COUNTER,PPDU,APDU,DUTYPE,HBWPR,HBSHPR,HBSRPR,HBOPR
FILEO RECO[1] = "{Scenario_Dir}\OUTPUT\GENRATES.DBF",
FIELDS=PAD,PERSONS_DU,AUTO_DU,DU_TYPE,PRATEHBW,PRATEHBSH,PRATEHBSR,PRATEHBO
FILEI RECI = "{Catalog_Dir}\Parameters\GENRATES.DBF"

ARRAY HBW_PRATE=999,HBSR_PRATE=999,HBSH_PRATE=999,HBO_PRATE=999

PAD=100*RI.PERSONS_DU+10*(RI.AUTOS_DU-1)+RI.DU_TYPE
COUNTER=0
HBW_PRATE[PAD]=RI.HBW_PRATE
HBSH_PRATE[PAD]=RI.HBSH_PRATE
HBSR_PRATE[PAD]=RI.HBSR_PRATE
HBO_PRATE[PAD]=RI.HBO_PRATE


IF(I=0)
 LOOP P=1,5
  LOOP A=1,3
   LOOP D=1,3
    PAD=100*P+10*(A-1)+D
    COUNTER=COUNTER +1
    IF (HBW_PRATE[PAD]>0|HBSH_PRATE[PAD]>0|HBSR_PRATE[PAD]>0|HBO_PRATE[PAD]>0)
     RO.PERSONS_DU=P
     RO.AUTOS_DU=A-1
     RO.DU_TYPE=D
     RO.PRATEHBW=HBW_PRATE[PAD]
     RO.PRATEHBSH=HBSH_PRATE[PAD]
     RO.PRATEHBSR=HBSR_PRATE[PAD]
     RO.PRATEHBO=HBO_PRATE[PAD]
    
     RO.PPDU=P
     RO.APDU=A-1
     RO.DUTYPE=D
     RO.HBWPR=HBW_PRATE[PAD]
     RO.HBSHPR=HBSH_PRATE[PAD]
     RO.HBSRPR=HBSR_PRATE[PAD]
     RO.HBOPR=HBO_PRATE[PAD]



     WRITE RECO=1
     WRITE RECO=2
    ENDIF
   ENDLOOP
  ENDLOOP
 ENDLOOP
ENDIF

; The MATRIX module does not have any explicit phases.  The module does run within an implied ILOOP
; where I is the origin zones.  All user statements in the module are processed once for each origin.
; Matrix computation (MW[#]=) are solved for all values of J for each I.  Thus for a given origin zone I
; the values for all destination zones J are automatically computed.  The user can control the computations
; at each J by using a JLOOP.

ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TGMAT00E.S"
; 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\GENRATESNP.PRN" MSG='Production Rates Non-Permanent Population'
FILEO RECO[1] = "{Scenario_Dir}\OUTPUT\GENRATESNP.DBF",
FIELDS=PAD,PERSONS_DU,AUTOS_DU,DU_TYPE,PRATEHBW,PRATEHBSH,PRATEHBSR,PRATEHBO
FILEI RECI = "{Catalog_Dir}\Parameters\GENRATESNP.DBF"



ARRAY HBW_PRATE=999, HBSH_PRATE=999, HBSR_PRATE=999, HBO_PRATE=999

PAD=100*RI.PERSONS_DU+10*(RI.AUTOS_DU-1)+RI.DU_TYPE

HBW_PRATE[PAD]=RI.HBW_PRATE
HBSH_PRATE[PAD]=RI.HBSH_PRATE
HBSR_PRATE[PAD]=RI.HBSR_PRATE
HBO_PRATE[PAD]=RI.HBO_PRATE

IF (I=0)
  LOOP P=1,5
   LOOP A=1,3
     LOOP D=1,3
     PAD=100*P+10*(A-1)+D
        IF (HBW_PRATE[PAD]>0|HBSH_PRATE[PAD]>0|HBSR_PRATE[PAD]>0|HBO_PRATE[PAD]>0)
           RO.PERSONS_DU=P
           RO.AUTOS_DU=A-1
           RO.DU_TYPE=D
           RO.PRATEHBW=HBW_PRATE[PAD]
           RO.PRATEHBSH=HBSH_PRATE[PAD]
           RO.PRATEHBSR=HBSR_PRATE[PAD]
           RO.PRATEHBO=HBO_PRATE[PAD]
           WRITE RECO=1
        ENDIF ; HBW_PRATE[PAD], ETC
     ENDLOOP;  D
    ENDLOOP ;  A
  ENDLOOP   ;  P
ENDIF
; The MATRIX module does not have any explicit phases.  The module does run within an implied ILOOP
; where I is the origin zones.  All user statements in the module are processed once for each origin.
; Matrix computation (MW[#]=) are solved for all values of J for each I.  Thus for a given origin zone I
; the values for all destination zones J are automatically computed.  The user can control the computations
; at each J by using a JLOOP.

ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TGMAT00F.S"
; 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\ATTRACTIONRATE.PRN" MSG='Attraction Rates File'
FILEO RECO[1] = "{Scenario_Dir}\OUTPUT\ARATES.DBF",
FIELDS=PURPOSE,ARATEIND,ARATECOM,ARATESVC,ARATETOT,ARATEDUS,ARATESCH
FILEI RECI = "{Catalog_Dir}\Parameters\ATTRRATES.DBF"

PURPOSE=RI.ATTR_PURPO
ARATEIND=RI.INEMP_RATE
ARATECOM=RI.COEMP_RATE
ARATESVC=RI.SEEMP_RATE
ARATETOT=RI.TOEMP_RATE
ARATEDUS=RI.TOTDU_RATE
ARATESCH=RI.SCHOO_RATE

WRITE RECO=1
; The MATRIX module does not have any explicit phases.  The module does run within an implied ILOOP
; where I is the origin zones.  All user statements in the module are processed once for each origin.
; Matrix computation (MW[#]=) are solved for all values of J for each I.  Thus for a given origin zone I
; the values for all destination zones J are automatically computed.  The user can control the computations
; at each J by using a JLOOP.

ENDRUN


; Script for program GENERATION in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TGGEN00B.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=GENERATION PRNFILE="{Scenario_Dir}\OUTPUT\TGGEN00A.PRN"
FILEO PAO[1] = "{Scenario_Dir}\OUTPUT\PANDA_{ALT}{Year}.DBF",
LIST=Z,P[1],P[2],P[3],P[4],P[5],P[6],P[7],A[1],A[2],A[3],A[4],A[5],A[6],A[7],DBF=T
FILEO PRINTO[2] = "{Scenario_Dir}\OUTPUT\GENERRORS.PRN"
FILEO PRINTO[1] = "{Scenario_Dir}\OUTPUT\GENSUMMARY.PRN"
FILEI ZDATI[4] = "{SCENARIO_DIR}\Input\SPECGEN_P_{Year}{ALT}.DBF"
FILEI ZDATI[3] = "{SCENARIO_DIR}\Input\INTEXT_{Year}{ALT}.DBF"
FILEI ZDATI[2] = "{SCENARIO_DIR}\Input\SPECGEN_A_{Year}{ALT}.DBF"
FILEI ZDATI[1] = "{SCENARIO_DIR}\Input\ZONEDATA_{Year}{ALT}.dbf"
FILEI LOOKUPI[4] = "{Scenario_Dir}\OUTPUT\ARATES.DBF"
FILEI LOOKUPI[3] = "{Scenario_Dir}\OUTPUT\DUWEIGHTS.DBF"
FILEI LOOKUPI[2] = "{Scenario_Dir}\OUTPUT\GENRATESNP.DBF"
FILEI LOOKUPI[1] = "{Scenario_Dir}\OUTPUT\GENRATES.DBF"


; ================================================================
; OVERALL PROGRAM CONTROLS

PARAMETERS ZONES={ZONESA}, ZONEMSG=100

ARRAY CAR=4 CELL=999 CELLT=999 SPAFRAC=12 SPPFRAC=12
ARRAY PERDU=3 NDU=3 ODU=3
ARRAY HHCATN=999 THOUSEN=999 THHCATN=999 TTRIPHN=999
ARRAY HHCAT=999  THOUSE=999  THHCAT=999 TTRIPH=999

LOOKUP LOOKUPI=1,
       NAME=PRATE, ;TRIP PRODUCTION RATES PERMANENT POPULATION
         LOOKUP[1]=PAD, RESULT=PRATEHBW,
         LOOKUP[2]=PAD, RESULT=PRATEHBSH,
         LOOKUP[3]=PAD, RESULT=PRATEHBSR,
         LOOKUP[4]=PAD, RESULT=PRATEHBO,
       FAIL[1]=0,FAIL[2]=0,FAIL[3]=0, INTERPOLATE=N, LIST=N

LOOKUP LOOKUPI=2,
       NAME=PRATENP, ;TRIP ATTRACTION RATES NON PERMANENT POPULATION
         LOOKUP[1]=PAD, RESULT=PRATEHBW,
         LOOKUP[2]=PAD, RESULT=PRATEHBSH,
         LOOKUP[3]=PAD, RESULT=PRATEHBSR,
         LOOKUP[4]=PAD, RESULT=PRATEHBO,
       FAIL[1]=0,FAIL[2]=0,FAIL[3]=0, INTERPOLATE=N, LIST=N

LOOKUP LOOKUPI=3,
       NAME=DUWEIGHT, 
         LOOKUP[1]=SIZERANGE, RESULT=PCT1PER, ; %1 PERSON
         LOOKUP[2]=SIZERANGE, RESULT=PCT2PER, ; %2 PERSON
         LOOKUP[3]=SIZERANGE, RESULT=PCT3PER, ; %3 PERSON
         LOOKUP[4]=SIZERANGE, RESULT=PCT4PER, ; %4 PERSON
         LOOKUP[5]=SIZERANGE, RESULT=PCT5PER, ; %5+PERSON
       INTERPOLATE=N, LIST=N

LOOKUP LOOKUPI=4,
       NAME=ARATE, ;TRIP ATTRACTION RATES
       LOOKUP[1]=PURPOSE, RESULT=ARATEIND,
       LOOKUP[2]=PURPOSE, RESULT=ARATECOM,
       LOOKUP[3]=PURPOSE, RESULT=ARATESVC,
       LOOKUP[4]=PURPOSE, RESULT=ARATETOT,
       LOOKUP[5]=PURPOSE, RESULT=ARATEDUS,
       LOOKUP[6]=PURPOSE, RESULT=ARATESCH,
     FAIL[1]=0,FAIL[2]=0,FAIL[3]=0, INTERPOLATE=N, LIST=y

PROCESS PHASE=ILOOP 

; . . . . . . . . . . . . . . . . . . 

; Calculation of Resident Population per DU

      OPDUS = ZI.1.SFDU * (1. - (ZI.1.SF_PCTVNP/100.))
      OPDUM = ZI.1.MFDU * (1. - (ZI.1.MF_PCTVNP/100.))

      IF(OPDUS<=0.0)
      PERDUS=0.0
      ELSE
      PERDUS = ZI.1.SFPOP/OPDUS
      IF(PERDUS>5.99) PERDUS = 5.99
      ENDIF

      IF(OPDUM<=0.0)
      PERDUM = 0.0
      ELSE
      PERDUM = ZI.1.MFPOP/OPDUM
      IF(PERDUM>5.99) PERDUM = 5.99
      ENDIF

;---------------
;  CALCULATION OF HOTEL-MOTEL POPULATION PER DU
;
      ODUH   = ZI.1.HMDU * (ZI.1.HMOCC/100.)
      IF(ODUH<=0.0)
      PERDUH=0.0
      ELSE
      PERDUH = ZI.1.HMPOP/ODUH
      IF(PERDUH>5.99) PERDUH = 5.99
      ENDIF

;-------------
;  DETERMINATION OF RANGE OF POP. PER DU AND INTERPOLATION FOR RATE OF
;    TRIPS PER DU FOR A GIVEN DU TYPE AND PURPOSE.
;
;     THE POINT-SLOPE FORMULA IS USED, WITH THE MIDPOINTS OF THE
;     PERSONS PER DU RANGES BEING THE X'S, AND THE TRIP RATES FOR
;     THE GIVEN MIDPOINTS FROM THE HBLK MATRIX BEING THE Y'S.
;              SLOPE=(Y2-Y1)/(X2-X1)=M, IN TRADITIONAL NOTATION.
;              Y= MX+B, FOR ANY X AND Y.
;              B=Y2-MX2, FOR Y=Y2.
;              Y=MX+Y2-MX2, OR
;              Y=M(X-X2)+Y2.
;     IF X IS A PERDU(1),(2), OR (3), CALCULATED FROM THE ZDATA1
;     CARD, ITS FOUR HB-PURPOSE RATES ARE CALCULATED AS FOUR Y'S
;     FROM THE EQUATION.  THE ACTUAL RATE FOR A GIVEN PURPOSE AND
;     SF-MF-HM VALUE IS THE WEIGHTED SUM OF 3 INTERPOLATED RATES.  THE
;     WEIGHTS ARE THE PERCENTAGES OF 0,1, AND 2+ AUTO HOUSEHOLDS READ
;     FROM THE ZDATA1 CARD. THE PROPER SLOPES TO USE ARE FIRST CALCU-
;     LATED AS IF EACH PERDU RANGE HAD A WIDTH OF .25. EXCEPT THE
;     16TH ON AND THE LAST ONE WHICH IS OPEN ENDED.  YOU CAN'T HAVE
;     A ZONE USE THE LAST ONE AND STILL INTERPOLATE.  NOTE NSLOPE(17)
;     SPECIFIED ON PAGE 89 OF MUI,TASK B.
;
      PERDU[1] = PERDUS
      PERDU[2] = PERDUM
      PERDU[3] = PERDUH

;      IF (RNP2.EQ.2) THEN
      ODUS = ZI.1.SFDU * (1. - (ZI.1.SF_PCTVNP/100.))
      ODUM = ZI.1.MFDU * (1. - (ZI.1.MF_PCTVNP/100.))

      xx  = (ZI.1.MF_PCTVNP/100.)
      xxx = (ZI.1.MF_PCTVAC/100.)
;     CHECK FOR RESIDENT AND NON-RESIDENT PERCENTAGES
      ODUSNR = ZI.1.SFDU * ((ZI.1.SF_PCTVNP/100.) - (ZI.1.SF_PCTVAC/100.))


      IF(ODUSNR<0.0) ODUSNR = 0.0


      ODUMNR = ZI.1.MFDU * ((ZI.1.MF_PCTVNP/100.) - (ZI.1.MF_PCTVAC/100.))

      IF(ODUMNR<0.0) ODUMNR = 0.0

      NDU[1] = ODUSNR
      NDU[2] = ODUMNR
      NDU[3] = 0

;     ODUH = AS CALCULATED ABOVE
      ODU[1] = ODUS
      ODU[2] = ODUM
      ODU[3] = ODUH
;
;      DO  890 IDUTYP=1,3
;      LOOP HHTYPE=1,3

; ================================================================
; This is the main program feedback to calculate initial production
; and attraction values for each zone for each trip purpose
; ================================================================
LOOP HHTYPE=1,3 ; ESTABLISH VARIABLES FOR EACH HOUSEHOLD CLASS

IF (HHTYPE=1) ; SINGLE-FAMILY
   UNITS=   ZI.1.SFDU
   VACRATE= ZI.1.SF_PCTVNP
   POP=     ZI.1.SFPOP
   CAR[1]=ZI.1.SF_0AUTO/100, CAR[2]=ZI.1.SF_1AUTO/100, CAR[3]=ZI.1.SF_2AUTO/100
ELSEIF (HHTYPE=2); MULTI-FAMILY
   UNITS=   ZI.1.MFDU
   VACRATE= ZI.1.MF_PCTVNP
   POP=     ZI.1.MFPOP
   CAR[1]=ZI.1.MF_0AUTO/100, CAR[2]=ZI.1.MF_1AUTO/100, CAR[3]=ZI.1.MF_2AUTO/100
ELSEIF (HHTYPE=3) ; HOTEL/MOTEL
   UNITS=   ZI.1.HMDU
   VACRATE= 100-ZI.1.HMOCC
   POP=     ZI.1.HMPOP
   CAR[1]=0, CAR[2]=1.0, CAR[3]=0
ENDIF

; ================================================================
; From here down, the same equations get applied to each
; household size, auto ownership and dwelling unit type.
; Since it is being run in the HHTYPE feedback, the same equations
; will be applied and running totals by zone will be accumulated.
; ================================================================

VAC=UNITS*(VACRATE/100), OCC=UNITS-VAC

; . . . . . . . . . . . . . . . . . . 

IF (OCC>0) 
   POPDU=POP/OCC
ELSE
   POPDU=0
ENDIF

; . . . . . . . . . . . . . . . . . . 

IF (POPDU<=1.12) RANGE=1
IF (POPDU>1.12)  RANGE=2
IF (POPDU>1.37)  RANGE=3
IF (POPDU>1.62)  RANGE=4
IF (POPDU>1.87)  RANGE=5
IF (POPDU>2.12)  RANGE=6
IF (POPDU>2.37)  RANGE=7
IF (POPDU>2.62)  RANGE=8
IF (POPDU>2.87)  RANGE=9
IF (POPDU>3.12)  RANGE=10
IF (POPDU>3.37)  RANGE=11
IF (POPDU>3.62)  RANGE=12
IF (POPDU>3.87)  RANGE=13
IF (POPDU>4.12)  RANGE=14
IF (POPDU>4.37)  RANGE=15
IF (POPDU>4.62)  RANGE=16
IF (POPDU>5.99)  RANGE=17
IF (HHTYPE=1) HHDESC='SF'
IF (HHTYPE=2) HHDESC='MF'
IF (HHTYPE=3) HHDESC='HM'

if (POPDU<1&OCC>0) PRINT LIST="TAZ=",I(5.0),"  POP/DU ERROR, HHTYPE=",HHDESC(2)," Population=",POP(4.0C)," Occupied Units=",occ(4.0c), printo=2

; . . . . . . . . . . . . . . . . . . 

;  LOOP PR=1,5
;   LOOP AU=1,3
;         CL=100*PR+10*(AU-1)+HHTYPE
;         CELL[CL]=OCC*DUWEIGHT(PR,RANGE)*CAR[AU]
;         CELLT[CL]=CELLT[CL]+CELL[CL]
;         LOOP PURP=1,4
;            PRODRATE=PRATE(PURP,CL)
;            PRDDRATENP=PRATENP(PURP,CL)
;            P[PURP]=P[PURP]+PRATE(PURP,CL)*CELL[CL]+PRATENP(PURP,CL)*CELL[CL]
;         ENDLOOP ; ON PURP
;   ENDLOOP ; ON AU
;  ENDLOOP  ; ON PR

; . . . . . . . . . . . . . . . . . . 

;C   -------
;C  CALCULATE WHICH PERSONS PER HOUSEHOLD GROUP( 1-17) SHOULD BE USED
;C  THE FACT THAT PERS/DU RANGES ARE ALMOST ALL EQUAL TO .25, AS WELL AS
;C  THAT A REAL EXPRESSION IS TRUNCATED WHEN PUT INTO AN INTEGER.
;C  INTERPOLATION BETWEEN RATES HAS BEEN REMOVED FROM THIS PROGRAM
;C
      NSLOPE = INT (4. * PERDU[HHTYPE] - 2.5)
      IF (NSLOPE<1) NSLOPE = 1
      IF (NSLOPE>16) NSLOPE = 17

;C
;C CALCULATE WHAT PORTION OF THE HOUSEHOLDS ARE IN EACH GROUP
;C BY DU TYPE, BY PERS PER DU, BY AUTOS PER DU
;C
;      DO  890 IHHSZE=1,5
;      DO  890 IADU=1,3
      LOOP PR=1,5
       LOOP AU=1,3
         CL=100*PR+10*(AU-1)+HHTYPE
         HHCATN[CL]=NDU[HHTYPE]*DUWEIGHT(PR,NSLOPE)*CAR[AU]
         THOUSEN[CL]=THOUSEN[CL]+HHCATN[CL]

         HHCAT[CL]=ODU[HHTYPE]*DUWEIGHT(PR,NSLOPE)*CAR[AU]
         THOUSE[CL]=THOUSE[CL]+HHCAT[CL]


;      HHCATN(IHHSZE,IADU,IDUTYP) =NDU(IDUTYP) * DUWT(NSLOPE,IHHSZE) * PCA(IDUTYP,IADU)
;      THOUSEN(IHHSZE,IADU,IDUTYP) =THOUSEN(IHHSZE,IADU,IDUTYP) + HHCATN(IHHSZE,IADU,IDUTYP)
;C
;C NOW IF EVERYTHING HAS GONE RIGHT THUS FAR WE WILL MULTIPLY THE
;C APPROPRIATE HHCAT BY THE CORRESPONDING TRIP RATE FOR EACH OF 4
;C HOMEBASED PURPOSES FOR NON RESIDENTS
;C
         LOOP PURP=1,4
            THHCATN[CL]=HHCATN[CL]*PRATENP(PURP,CL);*CELL[CL]
            THHCAT[CL]=HHCAT[CL]*PRATE(PURP,CL);*CELL[CL]


;      DO  890 IPURP=1,4
;      THHCATN(IHHSZE,IADU,IDUTYP,IPURP) =HHCATN(IHHSZE,IADU,IDUTYP) * MATNP(IHHSZE,IADU,IDUTYP,IPURP)
;C
;      IF(TRACE(19))WRITE(6,19) IZ,IPURP,IDUTYP,IADU,(HHCATN(I,IADU,IDUTYP),I=1,5),(THHCATN(K,IADU,IDUTYP,IPURP),K=1,5)
;   19 FORMAT(1X,I4,'PURP= ',I2,'DUTYP= ',I2,'ADU= ',I2,'HOUSEHOLD = ',5F6.3,'TRIPS= ',5F6.3)
;C
;C AND THEN CALCULATE HOMEBASED PRODUCTIONS
;C
            TTRIPHN[CL]=TTRIPHN[CL]+THHCATN[CL]
            TTRIPH[CL]=TTRIPH[CL]+THHCAT[CL]
            P[PURP]=P[PURP]+THHCATN[CL]+THHCAT[CL]


;      TTRIPHN(IHHSZE,IADU,IDUTYP,IPURP) = TTRIPHN(IHHSZE,IADU,IDUTYP,IPURP)+ THHCATN(IHHSZE,IADU,IDUTYP,IPURP)
;      P(IZ,IPURP) = P(IZ,IPURP) + THHCATN(IHHSZE,IADU,IDUTYP,IPURP)
;  890 CONTINUE
         ENDLOOP ; PURP
       ENDLOOP ; AU
      ENDLOOP ; PR
     ENDLOOP ; HHTYPE


;
; CALCULATE ATTRACTIONS FOR A ZONE AND NHB & TRUCK/TAXI PRODUCTIONS
;
;TOTALDUS=(ODUS+ODUM+ODUSNR+ODUMNR)  ;Start Attractions
TOTALDUS=ZI.1.SFDU+ZI.1.MFDU  ;Start Attractions

LOOP WPURP=1,6
   A[WPURP]=ARATE(1,WPURP)*ZI.1.IND_EMP+
            ARATE(2,WPURP)*ZI.1.COMM_EMP+
            ARATE(3,WPURP)*ZI.1.SERV_EMP+
            ARATE(4,WPURP)*ZI.1.TOT_EMP+
            ARATE(5,WPURP)*TOTALDUS+
            ARATE(6,WPURP)*ZI.1.SCHOOL
ENDLOOP
; . . . . . . . . . . . . . . . . . . 

; .........................................................................


; ================================================================
; NOW PROCESS SPECIAL GENERATORS
; The way this is written, only 1 SPGEN per zone is allowed .

;SP ATTRACTIONS
SPAFRAC[1]=ZI.2.PCT_HBW/100
SPAFRAC[2]=ZI.2.PCT_HBSH/100
SPAFRAC[3]=ZI.2.PCT_HBSR/100
SPAFRAC[4]=ZI.2.PCT_HBO/100
SPAFRAC[5]=ZI.2.PCT_NHB/100
;SP PRODUCTIONS
SPPFRAC[1]=ZI.4.PCT_HBW/100
SPPFRAC[2]=ZI.4.PCT_HBSH/100
SPPFRAC[3]=ZI.4.PCT_HBSR/100
SPPFRAC[4]=ZI.4.PCT_HBO/100
SPPFRAC[5]=ZI.4.PCT_NHB/100

; . . . . . . . . . . . . . . . . . . 
;P[5]=0
LOOP PRP=1,5
    IF (ZI.2.OPERAND='+')
       IF (ZI.2.PA='A','a') A[PRP]=A[PRP]+ZI.2.TRIPS_DIFF*SPAFRAC[PRP]
    ELSEIF (ZI.2.OPERAND='-')
       IF (ZI.2.PA='A','a') A[PRP]=A[PRP]-ZI.2.TRIPS_DIFF*SPAFRAC[PRP]
    ELSEIF (ZI.2.OPERAND='*')
       IF (ZI.2.PA='A','a') A[PRP]=A[PRP]*ZI.2.TRIPS_DIFF*SPAFRAC[PRP]    
    ELSEIF (ZI.2.OPERAND='T')
       IF (ZI.2.PA='A','a') A[PRP]=ZI.2.TRIPS_DIFF*SPAFRAC[PRP]

    ENDIF

    IF (ZI.4.OPERAND='+')
       IF (ZI.4.PA='P','p') P[PRP]=P[PRP]+ZI.4.TRIPS_DIFF*SPPFRAC[PRP]
    ELSEIF (ZI.4.OPERAND='-')
       IF (ZI.4.PA='P','p') P[PRP]=P[PRP]-ZI.4.TRIPS_DIFF*SPPFRAC[PRP]
    ELSEIF (ZI.4.OPERAND='*')
       IF (ZI.4.PA='P','p') P[PRP]=P[PRP]*ZI.4.TRIPS_DIFF*SPPFRAC[PRP]
    ELSEIF (ZI.4.OPERAND='T')
       IF (ZI.4.PA='P','p') P[PRP]=ZI.4.TRIPS_DIFF*SPPFRAC[PRP]

    ENDIF

ENDLOOP


; . . . . . . . . . . . . . . . . . . 

; ================================================================

P[7]=ZI.3.IE_PROD

IF (I={ZONESA})

  LOOP k=1,{ZONESI}

;C--------------
;C    SET NHB AND TT PRODUCTIONS EQUAL TO NHB AND TT ATTRACTIONS
;C

   P[5][k]=A[5][k]+P[5][K]
   P[6][k]=A[6][k]


      HBWPT  = HBWPT  + P[1][k]
      HBWAU  = HBWAU  + A[1][k]
      HBSHPT = HBSHPT + P[2][k]
      HBSHAU = HBSHAU + A[2][k]
      HBSRAU = HBSRAU + A[3][k]
      HBSRPT = HBSRPT + P[3][k]
      HBOPT  = HBOPT  + P[4][k]
      HBOAU  = HBOAU  + A[4][k]
      NHBPT  = NHBPT  + P[5][k]
      NHBAU  = NHBAU  + A[5][k]
      TVEHAU = TVEHAU + A[6][k]
      TVEHPT = TVEHPT + P[6][k]
  ENDLOOP

EIPT=PTOT(7)
EIAT=EIPT
IIAT = HBWAU + HBSHAU + HBSRAU + HBOAU + NHBAU + TVEHAU
R=EIPT/IIAT

  LOOP t=1,{ZONESI}

  A[7][t]=(A[1][t]+A[2][t]+A[3][t]+A[4][t]+A[5][t]+A[6][t])*R

  ENDLOOP

  HBWR  = HBWPT/HBWAU
  HBSHR = HBSHPT/HBSHAU
  HBSRR = HBSRPT/HBSRAU
  HBOR  = HBOPT/HBOAU
  NHBR  = NHBPT/NHBAU
  TTR   = TVEHPT/TVEHAU

  LOOP s=1,{ZONESA}

      A[1][s] = INT( A[1][s] * HBWR + 0.5)
      A[2][s] = INT( A[2][s] * HBSHR + 0.5)
      A[3][s] = INT( A[3][s] * HBSRR + 0.5)
      A[4][s] = INT( A[4][s] * HBOR + 0.5)
      A[5][s] = INT( A[5][s] * NHBR + 0.5)
      A[6][s] = INT( A[6][s] * TTR + 0.5)
      A[7][s] = INT(A[7][s] + 0.5) 


      P[1][s] = INT(P[1][s] + 0.5) 
      P[2][s] = INT(P[2][s] + 0.5) 
      P[3][s] = INT(P[3][s] + 0.5) 
      P[4][s] = INT(P[4][s] + 0.5) 
      P[5][s] = INT(P[5][s] + 0.5) 
      P[6][s] = INT(P[6][s] + 0.5) 
      P[7][s] = INT(P[7][s] + 0.5) 

  ENDLOOP

ENDIF

ENDPROCESS







ENDRUN


; Script for program NETWORK in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\HNNET00A.S"
; 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


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\HNMAT00A.S"
; 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\HNMAT00A.PRN" MSG='Count Times Nodes Used by Links'
FILEO RECO[1] = "{Scenario_Dir}\OUTPUT\NODECNT.DBF",
FIELDS=N,TIMESUSED
FILEI RECI = "{Scenario_Dir}\OUTPUT\LINK4CNT.DBF"

ARRAY NODECNT=999999

NODECNT[RI.A]=NODECNT[RI.A]+1
NODECNT[RI.B]=NODECNT[RI.B]+1
IF (RI.A>HINODE) HINODE=RI.A
IF (RI.B>HINODE) HINODE=RI.B

IF (I=0)

  LOOP N=1,HINODE
    IF (NODECNT[N]>0)
     TIMESUSED=NODECNT[N] 
     WRITE RECO=1
    ENDIF
  ENDLOOP

ENDIF

; The MATRIX module does not have any explicit phases.  The module does run within an implied ILOOP
; where I is the origin zones.  All user statements in the module are processed once for each origin.
; Matrix computation (MW[#]=) are solved for all values of J for each I.  Thus for a given origin zone I
; the values for all destination zones J are automatically computed.  The user can control the computations
; at each J by using a JLOOP.

ENDRUN


; Script for program NETWORK in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\HNNET00B.S"
; 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\HNNET00B.PRN"
FILEO PRINTO[1] = "{Scenario_Dir}\OUTPUT\TEMPNODE.DAT"
FILEI LINKI[1] = "{Scenario_Dir}\OUTPUT\TEMP.NET"

if (li.1.TOLLTYPE=1); Toll Road
  a_accel=0
  a_decel=1
  b_accel=1
  b_decel=0
  PRINT form=0, LIST=A,' ',a_accel,' ',a_decel,' ',li.1.toll,printo=1
  PRINT form=0, LIST='NODE= ',A,' ACCEL_NODE= ',a_accel,' DECEL_NODE= ',a_decel,' PLAZA ID= ',li.1.toll
  PRINT form=0, LIST=B,' ',b_accel,' ',b_decel,' ',li.1.toll,printo=1
  PRINT form=0, LIST='NODE= ',B,' ACCEL_NODE= ',b_accel,' DECEL_NODE= ',b_decel,' PLAZA ID= ',li.1.toll
endif

if (li.1.TOLLTYPE=2); ORT
  a_accel=0
  a_decel=1 ; added for ORT
  b_accel=1 ; added for ORT
  b_decel=0
  PRINT form=0, LIST=A,' ',a_accel,' ',a_decel,' ',li.1.toll,printo=1
  PRINT form=0, LIST='NODE= ',A,' ACCEL_NODE= ',a_accel,' DECEL_NODE= ',a_decel,' PLAZA ID= ',li.1.toll
  PRINT form=0, LIST=B,' ',b_accel,' ',b_decel,' ',li.1.toll,printo=1
  PRINT form=0, LIST='NODE= ',B,' ACCEL_NODE= ',b_accel,' DECEL_NODE= ',b_decel,' PLAZA ID= ',li.1.toll
endif


ENDRUN


; Script for program NETWORK in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\HNNET00D.S"
; 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\HNNET00D.PRN"
FILEO PRINTO[2] = "{Scenario_Dir}\OUTPUT\LINKS.CSV"
FILEO PRINTO[1] = "{Scenario_Dir}\OUTPUT\NODES.CSV"
FILEO NETO = "{Scenario_Dir}\OUTPUT\UNLOADED_{ALT}{Year}.NET"
FILEI NODEI[3] = "{Scenario_Dir}\OUTPUT\NODECNT.DBF"
FILEI NODEI[2] = "{Scenario_Dir}\OUTPUT\TEMPNODE.DAT",
 VAR=N,_TOLL_ACC,_TOLL_DEC,_PLAZAID
FILEI LINKI[1] = "{Scenario_Dir}\OUTPUT\TEMP.NET"



PROCESS  PHASE=INPUT, FILEI=LI.1
  TOLL_ACC=0
  TOLL_DEC=0
ENDPROCESS

PROCESS PHASE=NODEMERGE
   PRINT CSV=T, LIST=N(8.0),X,Y printo=1
   IF (TIMESUSED=0) DELETE
ENDPROCESS

PROCESS PHASE=LINKMERGE   
  IF(B._TOLL_DEC=1 & B._PLAZAID>0)
     TOLL_DEC=1
     TOLL=B._PLAZAID;_PLAZAID
  ENDIF
  IF(A._TOLL_ACC=1 & A._PLAZAID>0)
     TOLL_ACC=1
     TOLL=A._PLAZAID;_PLAZAID
  ENDIF

  if (time>0)
    _AUTOSPEED=60*(DISTANCE/{units})/TIME
  else
    _AUTOSPEED=15
  ENDIF
  if (Distance=0) distance=0.01 

_focus=1
_ft=int(facility_type/10)
_at=int(area_type/10)
print list=_focus(2.0),a(5.0),b(5.0),distance*100/{units}(4.0),toll(2.0),_ft(1.0),_at(1.0), printo=2


ENDPROCESS
;ENDPROCESS

ENDRUN


; Script for program HIGHWAY in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\HNHWY00A.S"
; 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\HNHWY00A.PRN"
FILEO MATO[1] = "{SCENARIO_DIR}\OUTPUT\FREESKIM_{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 LOOKUPI[1] = "{Catalog_Dir}\Parameters\TTPREP.CSV"
FILEI NETI = "{Scenario_Dir}\OUTPUT\UNLOADED_{ALT}{Year}.NET"

PAR ZONES={ZONESA}
PAR ZONEMSG=100

; ARRAY TERMINAL TIMES INTO MEMORY
;ARRAY ATYPE={ZONESA}
LOOKUP, NAME=TERMTIME, LOOKUP[1]=1, RESULT=2, INTERPOLATE=N, LOOKUPI=1

PROCESS PHASE=LINKREAD
   LW.TIME=li.time+li.svcminutes+li.svcseconds/60+li.cartoll*{ctoll}*60
ENDPROCESS

PROCESS PHASE=ILOOP
   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), NOACCESS=0
     ;MW[4]=PATHTRACE(LW.TIME), NOACCESS=0
; BUILD TERMINAL TIME MATRIX
      MW[4]=TERMTIME(1,I)+TERMTIME(1,J)
AG={IZzONE};*2
loop _IZ=1,3;4
  mw[_IZ][i]=lowest(_IZ,{IZzone})/AG
endloop
; set intrazonal array to zero for cost
mw[1][i]=0
MW[5]=MW[3]
MW[6]=MW[1]
MW[7]=MW[2]
MW[8]=MW[3]
MW[9]=MW[5]

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


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\HNMAT00B.S"
; 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\HNMAT00B.PRN" MSG='Build Transit Pahts/Skims'
FILEO MATO[1] = "{Scenario_Dir}\OUTPUT\FHSKIMTT.{ALT}{Year}",
MO=1-4,NAME=COST,DISTANCE,TIME,TIME2, FORMAT=TRANPLAN

FILEI MATI[1] = "{SCENARIO_DIR}\OUTPUT\FREESKIM_{ALT}{Year}.MAT"

; The MATRIX module does not have any explicit phases.  The module does run within an implied ILOOP
; where I is the origin zones.  All user statements in the module are processed once for each origin.
; Matrix computation (MW[#]=) are solved for all values of J for each I.  Thus for a given origin zone I
; the values for all destination zones J are automatically computed.  The user can control the computations
; at each J by using a JLOOP.
MW[1]=MI.1.1*100
MW[2]=MI.1.2*100
MW[3]=MI.1.3*100
MW[4]=MI.1.5*100
ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TDMAT00A.S"
; 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\TDMAT00A.PRN" MSG='Creat K factors'
FILEO MATO[1] = "{Scenario_Dir}\OUTPUT\KFACTOR.MAT",
MO=1-7, DEC=1*S, NAME=KFACTOR1,KFACTOR2,KFACTOR3,KFACTOR4,KFACTOR5,KFACTOR6,KFACTOR7
PAR ZONES={ZONESA} ZONEMSG=100

MW[1]=1
MW[2]=1
MW[3]=1
MW[4]=1
MW[5]=1
MW[6]=1
MW[7]=1

JLOOP
;Purpose1
IF (I=1001-1600 & J=1-1000)   MW[1]=0.16
IF (I=1-1000 & J=1001-1600)   MW[1]=0.16
;IF (I=1601-1713 & J=1-1000)   MW[1]=0.16
;IF (I=1-1000 & J=1601-1713)   MW[1]=0.16
IF(I=1-1000 & J=2001-2200) MW[1]=0.2
IF(I=2001-2200 & J=1-1000)  MW[1]=0.2
;IF(I=1-1000 & J=2001-2200) MW[1]=0.06
;IF(I=2001-2200 & J=1-1000)  MW[1]=0.06
;Purpose2
IF (I=1001-1600 & J=1-1000)   MW[2]=0.06
IF (I=1-1000 & J=1001-1600)   MW[2]=0.06
;IF (I=1601-1713 & J=1-1000)   MW[2]=0.06
;IF (I=1-1000 & J=1601-1713)   MW[2]=0.06
IF(I=1-1000 & J=2001-2200) MW[2]=0.06
IF(I=2001-2200 & J=1-1000)  MW[2]=0.06

;Purpose3
IF (I=1001-1600 & J=1-1000)   MW[3]=0.034
IF (I=1-1000 & J=1001-1600)   MW[3]=0.034
;IF (I=1601-1713 & J=1-1000)   MW[3]=0.034
;IF (I=1-1000 & J=1601-1713)   MW[3]=0.034
IF(I=1-1000 & J=2001-2200) MW[3]=0.34
IF(I=2001-2200 & J=1-1000)  MW[3]=034
;Purpose4
IF (I=1001-1600 & J=1-1000)   MW[4]=0.07
IF (I=1-1000 & J=1001-1600)   MW[4]=0.07
;IF (I=1601-1713 & J=1-1000)   MW[4]=0.07
;IF (I=1-1000 & J=1601-1713)   MW[4]=0.07
IF(I=1-1000 & J=2001-2200) MW[4]=0.07
IF(I=2001-2200 & J=1-1000)  MW[4]=0.07


ENDJLOOP

/*
~ reduce travel anna maria to bradenton
GK, 1, 1001-1600, 1-1000, 0.16
GK, 1, 1-1000, 1001-1600, 0.16
GK, 1, 1601-1713, 1-1000, 0.16
GK, 1, 1-1000, 1601-1713, 0.16
GK, 2, 1001-1600, 1-1000, 0.06
GK, 2, 1-1000, 1001-1600, 0.06
GK, 2, 1601-1713, 1-1000, 0.06
GK, 2, 1-1000, 1601-1713, 0.06
GK, 3, 1001-1600, 1-1000, 0.034
GK, 3, 1-1000, 1001-1600, 0.034
GK, 3, 1601-1713, 1-1000, 0.034
GK, 3, 1-1000, 1601-1713, 0.034
GK, 4, 1001-1600, 1-1000, 0.07
GK, 4, 1-1000, 1001-1600, 0.07
GK, 4, 1601-1713, 1-1000, 0.07
GK, 4, 1-1000, 1601-1713, 0.07
*/
; The MATRIX module does not have any explicit phases.  The module does run within an implied ILOOP
; where I is the origin zones.  All user statements in the module are processed once for each origin.
; Matrix computation (MW[#]=) are solved for all values of J for each I.  Thus for a given origin zone I
; the values for all destination zones J are automatically computed.  The user can control the computations
; at each J by using a JLOOP.

ENDRUN


; Script for program DISTRIBUTION in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TDDST00A.S"
; 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


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TDMAT00B.S"
; 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\TDMAT00B.PRN" MSG='Prepare Vehicle Trip Table for Preassignment'
FILEO MATO[1] = "{Scenario_Dir}\OUTPUT\VEHTRIPS_PREASSIGN.MAT",
MO=1,NAME=PRELOADVEH
FILEI MATI[2] = "{Scenario_Dir}\OUTPUT\EETRIPS_{ALT}{Year}.MAT"
FILEI MATI[1] = "{Scenario_Dir}\OUTPUT\PSNTRIPS_TEMP_{ALT}{YEAR}.MAT"
PAR ZONEMSG=100

;P1=HBW,P2=HBS,P3=HBSR,P4=HBO,P5=NHB,P6=TT,P7=IE,P8=EE
MW[1]=(MI.1.HBW+MI.1.HBW.T)*0.5*{AOFAC_HBW}+
      (MI.1.HBSH+MI.1.HBSH.T)*0.5*{AOFAC_HBSH}+
      (MI.1.HBSR+MI.1.HBSR.T)*0.5*{AOFAC_HBSR}+
      (MI.1.HBO+MI.1.HBO.T)*0.5*{AOFAC_HBO}+
      (MI.1.NHB+MI.1.NHB.T)*0.5*{AOFAC_NHB}+
      (MI.1.TRKTAXI+MI.1.TRKTAXI.T)*0.5+
      (MI.1.IE+MI.1.IE.T)*0.5+
       MI.2.M1
;[2]=MW[1]*0.5

; The MATRIX module does not have any explicit phases.  The module does run within an implied ILOOP
; where I is the origin zones.  All user statements in the module are processed once for each origin.
; Matrix computation (MW[#]=) are solved for all values of J for each I.  Thus for a given origin zone I
; the values for all destination zones J are automatically computed.  The user can control the computations
; at each J by using a JLOOP.

ENDRUN


; Script for program HIGHWAY in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TDHWY00A.S"
; 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\TDHWY00A.PRN" MSG='Preassignment'
FILEI TURNPENI = "{SCENARIO_DIR}\Input\TURN_{Year}{ALT}.PEN"
FILEO NETO = "{SCENARIO_DIR}\OUTPUT\PREASSIGN_{ALT}{Year}.NET"
;FILEI TURNPENI = "{SCENARIO_DIR}\Input\TURN_{Year}{ALT}.PEN"
FILEI NETI = "{Scenario_Dir}\OUTPUT\UNLOADED_{ALT}{Year}.NET"
FILEI MATI[1] = "{Scenario_Dir}\OUTPUT\VEHTRIPS_PREASSIGN.MAT"

PAR ZONEMSG=100 MAXITERS={AssignIters}
ZONES={ZONESA}
LOOKUP,
INTERPOLATE=Y,LIST=Y,NAME=DECEL,
LOOKUP[1]=1,RESULT=2,
R='30 4',
  '70 6.2'


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 
  T0=li.TIME
  LW.FFTIME=LI.TIME ; USE FOR PRELOAD PURPOSES (FFTIME)
  C=LI.CAPACITY*LI.NUM_LANES*LI.UROADFACTOR/LI.CONFAC

  IF (LI.{PATHGROUP}) ADDTOGROUP=7 
      LINKCLASS=1 ; no toll
      if (li.tolltype=1) 
       LINKCLASS=2 ; with toll
       T0=({CTOLL}*LI.CARTOLL)*60 + LI.SVCMINUTES + LI.SVCSECONDS/60
       if (iteration=0)
          LW.ARRIVR=(V/LI.UROADFACTOR)*LI.CONFAC/LI.PLZALNSMAX  ; hourly volume per toll lane ie. arrival rate in vehicles per hour
        LW.SERVT=LI.SVCMINUTES+(LI.SVCSECONDS/60)           ; Plaza lane service time in minutes per vehicle
        LW.SERVR=(1/LW.SERVT)*60                            ; Plaza lane service rate in vehicle per hour
        PRINT LIST='ARRIVR= ',LW.ARRIVR
        PRINT LIST='SERVT= ',LW.SERVT
        PRINT LIST='SERVR= ',LW.SERVR
        if (LW.ARRIVR>=LW.SERVR) LW.ARRIVR=0.99*LW.SERVR    ; prevent infinite or negative queue 
       endif
      endif
; classify links based on presence/absence of Open Road Toll
      if (li.tolltype=2) 
       LINKCLASS=3 ; with ORT
       T0=({CTOLL}*LI.CARTOLL)*60
       endif
       if (li.TOLL_ACC>0) 
       LINKCLASS=4 ; Toll Plaza Acceleration link
       T0= T0 + (LI.SPEED/2.5)/60
      endif
      if (li.TOLL_DEC>0) 
       LINKCLASS=5 ; Toll Plaza Deceleration link
       T0 = T0 + (LI.SPEED/DECEL(1,LI.SPEED))/60
      endif
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
MW[1]=MI.1.PRELOADVEH
;MW[2]=MI.1.TEST
PATHLOAD PATH=TIME, VOL[1]=MW[1]
;PATHLOAD PATH=TIME, PENI=1, VOL[2]=MW[2]
IF (I=ZONES)
  LINKLOOP
    LW.PREVTIME=TIME
  ENDLINKLOOP
ENDIF


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.
IF(TIME>0) LW.CGSTSPEED=(LW.DISTANCE/TIME)*60
IF(LI.TOLLTYPE=1)
 LW.ARRIVR=(V/LI.UROADFACTOR)*LI.CONFAC/LI.PLZALNSMAX  ; hourly volume per toll lane ie. arrival rate in vehicles per hour
 LW.SERVT=LI.SVCMINUTES+(LI.SVCSECONDS/60)           ; Plaza lane service time in minutes per vehicle
 LW.SERVR=(1/LW.SERVT)*60                            ; Plaza lane service rate in vehicle per hour
IF(LW.ARRIVR>=LW.SERVR) LW.ARRIVR=0.99*LW.SERVR; prevent infinite or negative queue 
;PRINT LIST='ARRIVR= ',LW.ARRIVR
;PRINT LIST='SERVT= ',LW.SERVT
;PRINT LIST='SERVR= ',LW.SERVR
;PRINT LIST='TOLLTIME= ',TIME
ENDIF
FUNCTION V=VOL[1]
;FUNCTION TC[1]={DAMPINGFACTOR}*LW.PREVTIME+(1.0-{DAMPINGFACTOR}*LI.TIME*(1+LI.BPRCOEFFICIENT*MIN(V/C),{VCMAX}*LI.BPREXPONENT);Congested time for non-toll links
 FUNCTION TC[1]={DAMPINGFACTOR}*LW.PREVTIME+(1.0-{DAMPINGFACTOR})*LI.TIME*(1+LI.BPRCOEFFICIENT*MIN((V/C),{vcmax})^LI.BPREXPONENT)
 FUNCTION TC[2]=MIN((1/(LW.SERVR-LW.ARRIVR))*60,20)+{CTOLL}*LI.CARTOLL*60;CONGESTED TIME FOR TOLL LINKS
 FUNCTION TC[3]={CTOLL}*LI.CARTOLL*60;CONGESTED TIME FOR ORT TOLL LINKS
;FUNCTION TC[4]=LI.TIME*(1+LI.BPRCOEFFICIENT*MIN(V/C),{VCMAX})^LI.BPREXPONENT)+(LW.CGSPEED/2.5)/60;CONGESTED TIME TOLL ACCELERATION LINKS
 FUNCTION TC[4]=LI.TIME*(1+LI.BPRCOEFFICIENT*MIN((V/C),{vcmax})^LI.BPREXPONENT) + (LW.CGSTSPEED/2.5)/60
 FUNCTION TC[5]=LI.TIME*(1+LI.BPRCOEFFICIENT*MIN((V/C),{vcmax})^LI.BPREXPONENT)+(LW.CGSTSPEED/DECEL(1,LW.CGSTSPEED))/60; congested time toll deceleration links
;if (li.cartoll>0) print list="Iter:",iteration(2.0)," TOLLFM Summary, A=",A(6.0)," B=",B(6.0)," PLAZAID=",li.TOLL(3.0)," NAME=",li.PLAZADESC(24)," MAX LNS=",li.PLZALNSMAX," GCOST=",TIME(6.2),
 ;       printo=1
ENDPROCESS

ENDRUN


; Script for program HIGHWAY in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TDHWY00B.S"
; 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


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TDMAT00C.S"
; 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\TDMAT00C.PRN" MSG='Develop Transit  Congested Skims'
FILEO MATO[1] = "{Scenario_Dir}\OUTPUT\RHSKIMTT.{ALT}{Year}",
MO=1-4,NAME=COST,DISTANCE,TIME,TIME2, FORMAT=TRANPLAN
FILEI MATI[1] = "{Scenario_Dir}\OUTPUT\CONGSKIM_{ALT}{Year}.MAT"

MW[1]=MI.1.1*100
MW[2]=MI.1.2*100
MW[3]=MI.1.3*100
MW[4]=MI.1.5*100

; The MATRIX module does not have any explicit phases.  The module does run within an implied ILOOP
; where I is the origin zones.  All user statements in the module are processed once for each origin.
; Matrix computation (MW[#]=) are solved for all values of J for each I.  Thus for a given origin zone I
; the values for all destination zones J are automatically computed.  The user can control the computations
; at each J by using a JLOOP.

ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TDMAT00E.S"
; 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\TDMAT00D.PRN" MSG='Build trip table for Mode choice'
FILEO MATO[1] = "{Scenario_Dir}\OUTPUT\PSNTRIPS_{ALT}{YEAR}.MAT",
MO=1-5,DEC=7*S, NAME=HBW,HBO,NHB,TRKTAXI,IE

FILEI MATI[1] = "{Scenario_Dir}\OUTPUT\PSNTRIPS_TEMP_{ALT}{YEAR}.MAT"

MW[1]=MI.1.1
MW[2]=MI.1.2+MI.1.3+MI.1.4
MW[3]=MI.1.5
MW[4]=MI.1.6
MW[5]=MI.1.7
; The MATRIX module does not have any explicit phases.  The module does run within an implied ILOOP
; where I is the origin zones.  All user statements in the module are processed once for each origin.
; Matrix computation (MW[#]=) are solved for all values of J for each I.  Thus for a given origin zone I
; the values for all destination zones J are automatically computed.  The user can control the computations
; at each J by using a JLOOP.

ENDRUN


; PILOT Script
FILEO PRINTO[1] = "{CATALOG_DIR}\applications\transit.mas"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.



; Create TRANSIT.MAS file
copy,
 FILE = "{CATALOG_DIR}\APPLICATIONS\TRANSIT.MAS"

DESCRIPTION                  {SCENARIO_FULLNAME}
ZONESA                       {ZONESA}

; AutoCon-Related Files
; Input
StatDataFile                 {SCENARIO_DIR}\output\STATION_{ALT}{YEAR}.DAT
XtraAutoFileAM               {SCENARIO_DIR}\input\XTRAAUTO_{YEAR}{ALT}.DAT
XtraAutoFileMD               {SCENARIO_DIR}\input\XTRAAUTO_{YEAR}{ALT}.DAT
AutoDelFileAM                {SCENARIO_DIR}\input\AUTDELPK_{YEAR}{ALT}.DAT
AUTODELFILEMD                {SCENARIO_DIR}\input\AUTDELOP_{YEAR}{ALT}.DAT
NodesFile                    {SCENARIO_DIR}\output\XY_{ALT}{YEAR}.DAT
TransitLineFile              {SCENARIO_DIR}\input\troute_{YEAR}{ALT}.lin
RHSKIMS                      {SCENARIO_DIR}\output\RHSKIMTT.{ALT}{YEAR}
FHSKIMS                      {SCENARIO_DIR}\output\FHSKIMTT.{ALT}{YEAR}
; Output
AUTOCONRPT                   {SCENARIO_DIR}\output\AUTOCON.OUT
PNRAUTOAM                    {SCENARIO_DIR}\output\NTLEG2PK_{ALT}{YEAR}.NTL
PNRAUTOMD                    {SCENARIO_DIR}\output\NTLEG2OP_{ALT}{YEAR}.NTL
KNRAUTOAM                    {SCENARIO_DIR}\output\NTLEG2PK_KNR{ALT}{YEAR}.NTL
KNRAUTOMD                    {SCENARIO_DIR}\output\NTLEG2OP_KNR{ALT}{YEAR}.NTL
; AutoCon Parameters
AUTOCONVERSION               1
ZONESI                       {ZONESI}
CBDZONE                      {CBDZONE,EditBox-INTEGER,"","733",1,1640}
TERM                         2.00
DEF                          2.00
NOPT                         1
BACK                         1
BACKD                        4.0
BACKPC                       0.30
UNITS                        200
MAXMODE                      27
MODENUM (not used)            21 22 23 24 25 26 27
PREMIUMFLAG                    0  1  0  1  1  1  1
MODEPRIORITY                   7  5  7  2  1  4  3
VOTAM                         6.00
VOTMD                         3.00
OVTRATIOAM                    2.00
OVTRATIOMD                    2.00
AATRATIOAM                    1.50
AATRATIOMD                    1.50
AUTOCCPNR                    {OCCPNRAccess}
AUTOCCKNR                    {OCCPNRAccess}
AOC                          {hwyopcost}
InflTransitFare              {InflationFare}
InflAOC                      {InflationAOC}
InflParkingCost              {InflationParkCost}
AUTODATAM                    {SCENARIO_DIR}\output\NTLDA2PK_{ALT}{YEAR}.TIM
AUTODATMD                    {SCENARIO_DIR}\output\NTLDA2OP_{ALT}{YEAR}.TIM
ACONLISTAM                   {SCENARIO_DIR}\output\NTLEG2PK_{ALT}{YEAR}.PRN
ACONLISTMD                   {SCENARIO_DIR}\output\NTLEG2OP_{ALT}{YEAR}.PRN


endcopy

; End of PILOT Script

LOOP ACCESS = 1, 2, 1

; PILOT Script


IF (ACCESS == 1)
    ACCESS_NAME='Walk'
    ACCESS_MODE=0
    DELACCMODE='2'
    DELEGRMODE='2'
ELSEIF (ACCESS == 2)
    ACCESS_NAME='Auto'
    ACCESS_MODE=1
    DELACCMODE='1'
    DELEGRMODE='2'
ENDIF

; End of PILOT Script

  LOOP MODE = 1, 1, 1

; PILOT Script



IF (MODE==1)                                  ; transit paths
  MODE_NAME='Transit'
  DELMOD=''
ENDIF

FAVMODE=1.00
LOWMODE=1.30
NOMODE=9.99
CRMODE=1.00




; End of PILOT Script

; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TPMAT00B.S"

; 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\TPMAT00G.PRN" MSG='create FACTORS file'
FILEI LOOKUPI[1] = "{CATALOG_DIR}\parameters\TRN_COEFFICIENTS.DBF"
FILEO PRINTO[1] = "{SCENARIO_DIR}\output\@Access_Name@@Mode_Name@.FAC"

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

ZONES=1
_ovtam =COEFF(1,3)/COEFF(1,1)     ; out-of-vehicle time factor (OVT time and Wait factor)
valtime   =0.6*COEFF(1,1)/COEFF(1,4)  ; value of time (in $/hr)
aatfactor =COEFF(1,5)/COEFF(1,1)     ; drive access to transit time factor
_xpena=COEFF(1,6)/COEFF(1,1)

  comment=';'

  PRINT FORM=5.0,
    list="",comment, " PT Factors File for ********",'@ACCESS_NAME@'," Access - ",'@MODE_NAME@'," ********",
         "\n",comment, " FSUTMS Transit Model - July 2008, AECOM Consult",
         "\n",
         "\n",comment, "Global Settings",
         "\n BESTPATHONLY=T",
         "\n MAXFERS=5",
         "\n SERVICEMODEL=FREQUENCY",
         "\n RECOSTMAX=300.0",
         "\n FREQBYMODE=T",
         "\n\n",comment, "Global Settings",
         "\n DELACCESSMODE = ",'@DELACCMODE@',
         "\n DELEGRESSMODE = ",'@DELEGRMODE@',
         "\n\n",comment, "Fare and Wait Times",
         "\n FARESYSTEM=1, OPERATOR=1",
         "\n FARESYSTEM=2, OPERATOR=2",
         "\n FARESYSTEM=3, OPERATOR=3",         
         "\n IWAITCURVE=1,  NODES={NODEMIN}-99999",
         "\n XWAITCURVE=1, NODES={NODEMIN}-99999",
         "\n WAITFACTOR=2.00, NODES={NODEMIN}-99999",
         "\n\n",comment, "Runfactors",
         "\n RUNFACTOR[1]   =",_ovtam(5.2),
         "\n RUNFACTOR[2]   = 1.00",
         "\n RUNFACTOR[4]   = 9.99",
         "\n RUNFACTOR[11]  =",_ovtam(5.2),
         "\n RUNFACTOR[12]  =",_ovtam(5.2),
         PRINTO=1

    if (@MODE@==1)
      list="",
         "\n RUNFACTOR[21]  = ",@FAVMODE@(4.2),
         "\n RUNFACTOR[22]  = ",@FAVMODE@(4.2),
         "\n RUNFACTOR[23]  = ",@FAVMODE@(4.2),
         "\n RUNFACTOR[24]  = ",@FAVMODE@(4.2),
         "\n RUNFACTOR[25]  = ",@FAVMODE@(4.2),
       
         PRINTO=1
    
    endif

    list="",
         "\n\n",comment, "Boarding and Transfer Penalties",
         "\n BRDPEN[21]  = 2.0",
         "\n BRDPEN[22]  = 2.0",
         "\n BRDPEN[23]  = 2.0",
         "\n BRDPEN[24]  = 2.0",
         "\n BRDPEN[25]  = 2.0",  
         "\n XFERPEN=0.00, from=21-200, to=21-200",
         "\n XFERFACTOR=1.00, from=21-200, to=21-200",
         "\n XFERCONST=",_xpena(4.2),", from=21-200, to=21-200",
         "\n  ",
         PRINTO=1

ENDRUN


  ENDLOOP

; PILOT Script



; End of PILOT Script

ENDLOOP

; Script for program NETWORK in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TPNET00C.S"

; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=NETWORK PRNFILE="X:\Projects\CRTPA\Model\C\APPLICATIONS\TPNET00C.PRN" MSG='Transit speed for peak period'
FILEI LINKI[1] = "{SCENARIO_DIR}\OUTPUT\PREASSIGN_{ALT}{Year}.NET"
FILEI LOOKUPI[1] = "{Catalog_Dir}\Parameters\TRANSPD.dbf"
FILEO NETO = "{SCENARIO_DIR}\output\HWYLOAD2_{Alt}{Year}.NET"

PROCESS PHASE=LINKMERGE

  ;If auto travel time is not present or is zero, a default value of 15 mph is used.
  IF (TIME_1>0)
    _AUTOSPEED=60*DISTANCE/TIME_1
  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

;**************************************************************
;END POTENTIAL SCRIPT ADJUSTMENT
;**************************************************************
      ; Bus time overrides
; IF   (TBSSPEED>0 && TBSTIME==0) TBSTIME = (DISTANCE/TBSSPEED)*60.0
; IF   (TBSTIME>0)
;       M21TIMEPK=TBSTIME
;       M22TIMEPK=TBSTIME
;       M23TIMEPK=TBSTIME
; ENDIF

  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]
   ;  if ((LM[_nn] >= 23) & (HM[_nn] <= 26)) spdratioM23 = SR[_nn]
    ; if ((LM[_nn] >= 27) & (HM[_nn] <= 27)) spdratioM27 = SR[_nn]
   ;  if ((LM[_nn] >= 31) & (HM[_nn] <= 31)) spdratioM31 = SR[_nn]
   ;  if ((LM[_nn] >= 32) & (HM[_nn] <= 32)) spdratioM32 = SR[_nn]
   ;  if ((LM[_nn] >= 33) & (HM[_nn] <= 36)) spdratioM33 = SR[_nn]
   ;  if ((LM[_nn] >= 37) & (HM[_nn] <= 37)) spdratioM37 = SR[_nn]
    endif
  ENDLOOP
     ; APPLY DEFAULT CURVES
     IF (_AUTOSPEED>0)
       _TSPD21=spdratioM21*_AUTOSPEED  ; Bus Speeds
       _TSPD27=spdratioM22*_AUTOSPEED  ; Project mode
    ;   _TSPD23=spdratioM23*_AUTOSPEED  ; Circulator Speeds (assumed same as buses)
    ;   _TSPD27=spdratioM27*_AUTOSPEED  ; Project mode
    ;   _TSPD31=spdratioM31*_AUTOSPEED  ; Bus Speeds
    ;   _TSPD32=spdratioM32*_AUTOSPEED  ; BRT Speeds (assumed same as buses)
    ;   _TSPD33=spdratioM33*_AUTOSPEED  ; Circulator Speeds (assumed same as buses)
    ;   _TSPD37=spdratioM37*_AUTOSPEED  ; Project mode

       M21TIMEPK=60*(DISTANCE)/_TSPD21
       M27TIMEPK=60*(DISTANCE)/_TSPD27
 ;      M23TIMEOP=60*(DISTANCE)/_TSPD23
 ;      M27TIMEOP=60*(DISTANCE)/_TSPD27
 ;      M31TIMEOP=60*(DISTANCE)/_TSPD31
 ;      M32TIMEOP=60*(DISTANCE)/_TSPD32
 ;      M33TIMEOP=60*(DISTANCE)/_TSPD33
 ;      M37TIMEOP=60*(DISTANCE)/_TSPD37
     ENDIF
;OVERRIDES BUS TIMES FOR BUS LINKS FROM NETWORK
  ;   IF (TBSTIME>0)
  ;      M21TIMEOP=TBSTIME
  ;      M22TIMEOP=TBSTIME
  ;   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_8(7.2),_TSPD21(7.2),M21TIMEPK(7.2),_CURVEMODE21(7.0)," MODE21"
      list=A(7.0),B(7.0),DISTANCE(7.2),_AUTOSPEED(7.2),TIME_8(7.2),_TSPD22(7.2),M27TIMEPK(7.2),_CURVEMODE22(7.0)," MODE27"
     ; list=A(7.0),B(7.0),DISTANCE(7.2),_AUTOSPEED(7.2),TIME_1(7.2),_TSPD23(7.2),M23TIMEPK(7.2),_CURVEMODE23(7.0)," MODE23"
     ; list=A(7.0),B(7.0),DISTANCE(7.2),_AUTOSPEED(7.2),TIME_1(7.2),_TSPD24(7.2),M24TIMEPK(7.2),_CURVEMODE24(7.0)," MODE24"
     ; list=A(7.0),B(7.0),DISTANCE(7.2),_AUTOSPEED(7.2),TIME_1(7.2),_TSPD25(7.2),M25TIMEPK(7.2),_CURVEMODE25(7.0)," MODE25"
     ; list=A(7.0),B(7.0),DISTANCE(7.2),_AUTOSPEED(7.2),TIME_1(7.2),_TSPD26(7.2),M26TIMEPK(7.2),_CURVEMODE26(7.0)," MODE26"
     ; list=A(7.0),B(7.0),DISTANCE(7.2),_AUTOSPEED(7.2),TIME_1(7.2),_TSPD27(7.2),M27TIMEPK(7.2),_CURVEMODE27(7.0)," MODE27"
      list="\n\n"
 ENDIF

 ENDPROCESS

ENDRUN


; Script for program NETWORK in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TPNET00B.S"
; 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


; Script for program NETWORK in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TPNET00A.S"
; 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\TPNET00A.PRN" MSG='Build CBD xfer conn, station conn, & create station data file'
FILEO PRINTO[7] = "{SCENARIO_DIR}\output\mpocounty.dat"
FILEO PRINTO[1] = "{SCENARIO_DIR}\output\ZONESAT.DAT"
FILEO PRINTO[6] = "{SCENARIO_DIR}\output\STATION_{alt}{year}.DAT"
FILEI LOOKUPI[1] = "{SCENARIO_DIR}\Output\XY_{alt}{year}.DAT"
FILEI LINKI[2] = "{SCENARIO_DIR}\output\HWYLOAD2_{Alt}{Year}.NET"
FILEI LINKI[1] = "{SCENARIO_DIR}\output\unloaded2_{alt}{year}.net"

FILEO PRINTO[5] = "{SCENARIO_DIR}\output\StationConn_{alt}{year}.DAT"
FILEO PRINTO[3] = "{SCENARIO_DIR}\output\CBDxfer_TMP.DAT"
ARRAY STATSTOP=99999 STATNUMB=99999, statspaces=99999, PNRTERM=99999, KNRTERM=99999, nrz=99999

PROCESS PHASE=NODEMERGE
; put nodes, x and y coordinates into memory for lookup nearest TAZ question
lookup lookupi=1,
       name=netcoord,
       lookup[1]=1, result=2,
       lookup[2]=1, result=3,
       fail=0

IF(N=1)
 _CNT=1
  ; Print out code for generating CBD sidewalks to a temporary file
 PRINT FORM=5.0, list="GENERATE, COST=(LW.WALKDISTANCE),EXTRACTCOST=(LW.WALKTIME),MAXCOST=200*{XFERACC},LIST=T,",
 "\n  EXCLUDELINK=(LI.FACILITY_TYPE=10-19,69,70-99),NTLEGMODE=12,MAXNTLEGS=200*{MAXWLKACCLNKS},DIRECTION=3,ONEWAY=F,",
 "\n  FROMNODE=",PRINTO=3
ENDIF

IF(n<(_zones+1)) print list=n(5.0),mpo(5.0),county(5.0),printo=7

; extract station info from network for later calculations

IF (TSTYPE=1)
 workstat=N
 workstatx=netcoord(1,workstat,0)
 workstaty=netcoord(2,workstat,0)
 mindist=99999.99
LOOP _ww=1,{ZONESA}
  zx=netcoord(1,_ww,0)
  zy=netcoord(2,_ww,0)
IF (_ww!=workstat) dist=sqrt((workstatx-zx)^2+(workstaty-zy)^2)
IF (dist<mindist) mindist=dist, nearestzone=_ww
ENDLOOP


 PRINT FORM=5.0, list="GENERATE, COST=(LW.WALKDISTANCE),EXTRACTCOST=(LW.WALKTIME),MAXCOST=200*3.0,LIST=T,",
 "\n  EXCLUDELINK=(LI.FACILITY_TYPE=10-19,69,70-99),NTLEGMODE=1,MAXNTLEGS=200*{MAXWLKACCLNKS},DIRECTION=3,ONEWAY=F,",
 "\n  FROMNODE=",N,",TONODE=1-{ZONESA}",PRINTO=5

 ; Station data file
 PRINT LIST=_CNT(4.0),N(6.0),NEARESTZONE(6.0),TSRANGE(6.1),TSPARK(6.0),TSCOSTAM(6.0),TSCOSTMD(6.0),
                           TSPNRTERM(6.1),TSKNRTERM(6.1),"  1 ",TSNAME(24),PRINTO=6
 _CNT=_CNT+1

ENDIF
ENDPROCESS

PHASE=LINKMERGE
  IF( (LI.1.A <> _lastnode) && (LI.1.A > {ZONESA}) )
  IF(LI.1.AREA_TYPE>10 && LI.1.AREA_TYPE<20)                    ;list only CBD zones
    PRINT FORM=5.0, list= LI.1.A(6.0),",", PRINTO=3
  ENDIF
  ENDIF

  ; list zones with area types (replaces CBDZONES.SYN and EXURBS.SYN files)
  IF ( (LI.1.A <> _lastnode) && (LI.1.A <= {ZONESA}) )
  IF (LI.1.A > 0) PRINT list=LI.1.A(10.0), LI.1.AREA_TYPE(10.0), printo=1
  ENDIF

  _lastnode = LI.1.A
ENDPHASE

PHASE=SUMMARY
  PRINT FORM=5.0, list= "TONODE={NODEMIN}-99999", PRINTO=3
ENDPHASE

ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TPMAT00F.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=MATRIX MSG='Create STATDATA DBF file'
FILEO RECO[1] = "{SCENARIO_DIR}\output\STATDATA_{alt}{year}.DBF",
 FORM=10.0, FIELDS=TAZ,STNODE,STNUM, FORM=10.2, FIELDS=STMAXD,STPKSP,STPKCS1,STPKCS2,STWALKPR,STWALKKR,FORM=5.0, FIELDS=TSTYPE, CFORM=30, FIELDS=STNAME
FILEI RECI = "{SCENARIO_DIR}\output\STATION_{alt}{year}.DAT",
 SORT=TAZ,
   STATION=1-4, STATNODE=5-10, TAZ=11-16, DRV=17-22, SPACES=23-28,
   A1=29-34, A2=35-40, B1=41-46, B2=47-52, C1=54-55, NAME(C)=56-85

RO.TAZ=RI.TAZ
RO.STNODE=RI.STATNODE
RO.STNUM=RI.STATION
RO.STMAXD=RI.DRV
RO.STPKSP=RI.SPACES
RO.STPKCS1=RI.A1
RO.STPKCS2=RI.A2
RO.STWALKPR=RI.B1
RO.STWALKKR=RI.B2
RO.TSTYPE=RI.C1
RO.STNAME=RI.NAME

WRITE RECO=1

ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TPMAT00G.S"
;;<<GENERATED SCRIPT>><<MATRIX>>;;
;>>>
;>>>
;;>>>
;Input Matrix File 1:
;Output DBF File:
;Output CSV File:
;**********************************************************************
;THIS SCRIPT READS A MAT FILE, CREATE TWO MATRICS IN CSV AND DBF      *  
;**********************************************************************
; BY CITILABS
;
;;<<End Parameters>>;;


; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=MATRIX MSG='Store MPO and County of TAZs in DBF File'
FILEO RECO[1] = "{SCENARIO_DIR}\output\mpocounty.dbf",
fields=taz,mpo,county
FILEI RECI = "{SCENARIO_DIR}\output\mpocounty.dat",
taz=1-5,mpo=6-10,county=11-15

RO.TAZ=RI.TAZ
ro.mpo=ri.mpo
ro.county=ri.county
write reco=1



ENDRUN


; Script for program PUBLIC TRANSPORT in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TPPTR00A.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=PUBLIC TRANSPORT PRNFILE="{SCENARIO_DIR}\output\TPPTR00A.PRN" MSG='Build peak access connectors'
FILEI NETI = "{SCENARIO_DIR}\output\HWYLOAD2_{Alt}{Year}.NET"
FILEO NETO = "{SCENARIO_DIR}\output\NTLEGPK.NET"
FILEO NTLEGO = "{SCENARIO_DIR}\output\NTLEGPK_{year}{alt}.TEM"
FILEO REPORTO = "{SCENARIO_DIR}\output\TPPTR00B.PRN"
FILEI FACTORI[1] = "{SCENARIO_DIR}\output\WalkTransit.FAC"
FILEI FAREI = "{Scenario_Dir}\Input\TFARES_{Year}{ALT}.FAR"
FILEI SYSTEMI = "{CATALOG_DIR}\parameters\TSYSD.PTS"
FILEI LINEI[1] = "{SCENARIO_DIR}\INPUT\TROUTE_{YEAR}{ALT}.LIN"

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

; OVERALL PARAMETERS OF RUN
PARAMETERS USERCLASSES=1,FARE=N, MAPSCALE={Units}, HDWAYPERIOD=1,
           NOROUTEERRS=999999, NOROUTEMSGS=999999,
           TRANTIME=LW.TRANTIME,
           TRANTIME[21]=LI.M21TIMEPK,
      ;     TRANTIME[22]=LI.M22TIMEPK,
      ;     TRANTIME[23]=LI.M23TIMEPK,
       ;    TRANTIME[24]=LI.M24TIMEPK,
           TRANTIME[27]=LI.M27TIMEPK

;**************************************************************
;END POTENTIAL SCRIPT ADJUSTMENT
;**************************************************************

REPORT LINES=T
PROCESS PHASE=LINKREAD
           LW.TRANTIME=LI.M21TIMEPK
           LW.WALKTIME=LI.WALKTIME
           LW.WALKDISTANCE=LI.DISTANCE
           LW.DISTANCE=LI.DISTANCE
ENDPROCESS

PROCESS PHASE=DATAPREP

  ; 1 - Generate Walk Access Connectors
 
 GENERATE, COST=(LW.WALKDISTANCE),EXTRACTCOST=(LW.WALKTIME),MAXCOST=200*{WALKACC},LIST=T,EXCLUDELINK=(LI.FACILITY_TYPE=10-19,69,70-99),
            NTLEGMODE=1,MAXNTLEGS=200*{MAXWLKACCLNKS},DIRECTION=3,ONEWAY=F,FROMNODE=1-{ZONESA},TONODE={NODEMIN}-99999

 ; 4 - Generate All-Walk Connectors
  GENERATE, COST=(LW.WALKDISTANCE),EXTRACTCOST=(LW.WALKTIME),MAXCOST=200*7,LIST=T,EXCLUDELINK=(LI.FACILITY_TYPE=10-19,69,70-99),
            NTLEGMODE=4,MAXNTLEGS=200*{MAXWLKACCLNKS},DIRECTION=3,ONEWAY=F,FROMNODE=1-{ZONESA},TONODE=1-{ZONESA}

  ; 11 - If micro-coding exists, generate Fixed-guideway to bus transfer connectors
   IF ({isMicroCode} <> 0)
   GENERATE, COST=(LW.DISTANCE),EXTRACTCOST=(LI.WALKTIME),MAXCOST=200*{WALKACC},LIST=T,INCLUDELINK=(LI.FACILITY_TYPE=59),
            NTLEGMODE=11,MAXNTLEGS=200*{MAXWLKACCLNKS},DIRECTION=3,ONEWAY=F,FROMNODE={NODEMIN}-99999,TONODE={NODEMIN}-99999
  endif

  ; 12 - Generate CBD sidewalk connectors
   READ, FILE = "{SCENARIO_DIR}\OUTPUT\CBDXFER_TMP.DAT"
ENDPROCESS

ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TPMAT00A.S"
; 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\TPMAT00A.PRN" MSG='Subdivide connectors into separate files by mode'
FILEO PRINTO[6] = "{SCENARIO_DIR}\output\NTLEG4PK_{alt}{year}.NTL"
FILEO PRINTO[4] = "{SCENARIO_DIR}\output\NTLEG11PK_{alt}{year}.NTL"
FILEI RECI = "{SCENARIO_DIR}\output\NTLEGPK_{year}{alt}.TEM"
FILEO PRINTO[5] = "{SCENARIO_DIR}\output\NTLEG12PK_{alt}{year}.NTL"
FILEO PRINTO[1] = "{SCENARIO_DIR}\output\NTLEG1PK_{alt}{year}.NTL"

s1=strpos('NT',reci)
s2=strpos('LEG',reci)
s3=strpos('MODE',reci)
s4=strpos('COST',reci)
s5=strpos('DIST',reci)
s6=strpos('ONEWAY',reci)
s7=strpos('XN',reci)

; get the origin and destination zone
s8=(s3-s2)
leg1=substr(reci,s2,s8)
s9=strpos('=',leg1)
s10=strpos('-',leg1)
s11=(s9+1)
s12=(s10-1)
s13=(s10+1)
zonei=val(substr(leg1,s11,s12))
zonej=val(substr(leg1,s13,strlen(leg1)))

; get the mode number
s14=(s4-s3)
mode1=substr(reci,s3,s14)
s15=strpos('=',mode1)
s16=(s15+1)
mode=val(substr(mode1,s16,strlen(mode1)))

; get the time on the connector (cost field in the NT leg file)
s17=(s5-s4)
time1=substr(reci,s4,s17)
s18=strpos('=',time1)
s19=(s18+1)
time=val(substr(time1,s19,strlen(time1)))

; get the distance
s20=(s6-s5)
dist1=substr(reci,s5,s20)
s21=strpos('=',dist1)
s22=(s21+1)
dist=val(substr(dist1,s22,strlen(dist1)))

; get the rest of the string
s23=substr(reci,s6,strlen(reci))

if (i==1 && _ctr==0)
  PRINT LIST=";;<<PT>>;;", PRINTO=1
  PRINT LIST=";;<<PT>>;;", PRINTO=4
  PRINT LIST=";;<<PT>>;;", PRINTO=5
  PRINT LIST=";;<<PT>>;;", PRINTO=6
  _ctr = _ctr + 1
endif
;modes - walk, pnr, knr, all-walk, platcform connectors, sidewalk
if (mode=1) PRINT LIST="NT LEG=",zonei(5.0),"-",zonej(5.0)," MODE=",mode(2.0)," COST=",time(6.2)," DIST=",dist(5.2)," ",s23,PRINTO=1
if (mode=4) PRINT LIST="NT LEG=",zonei(5.0),"-",zonej(5.0)," MODE=",mode(2.0)," COST=",time(6.2)," DIST=",dist(5.2)," ",s23,PRINTO=6
if (mode=11) PRINT LIST="NT LEG=",zonei(5.0),"-",zonej(5.0)," MODE=",mode(2.0)," COST=",time(6.2)," DIST=",dist(5.2)," ",s23,PRINTO=4
if (mode=12) PRINT LIST="NT LEG=",zonei(5.0),"-",zonej(5.0)," MODE=",mode(2.0)," COST=",time(6.2)," DIST=",dist(5.2)," ",s23,PRINTO=5


ENDRUN


; Script for program PUBLIC TRANSPORT in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TPPTR00B.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=PUBLIC TRANSPORT PRNFILE="{SCENARIO_DIR}\output\TPPTR00C.PRN" MSG='Build off-peak access connectors'
FILEI NETI = "{SCENARIO_DIR}\output\unloaded2_{alt}{year}.net"
FILEO NETO = "{SCENARIO_DIR}\output\NTLEGOP.NET"
FILEO NTLEGO = "{SCENARIO_DIR}\output\NTLEGOP_{year}{alt}.TEM"
FILEO REPORTO = "{SCENARIO_DIR}\output\TPPTR00D.PRN"
FILEI FACTORI[1] = "{SCENARIO_DIR}\output\WalkTransit.FAC"
FILEI FAREI = "{Scenario_Dir}\Input\TFARES_{Year}{ALT}.FAR"
FILEI SYSTEMI = "{CATALOG_DIR}\parameters\TSYSD.PTS"
FILEI LINEI[1] = "{SCENARIO_DIR}\INPUT\TROUTE_{YEAR}{ALT}.LIN"

;**************************************************************
;BEGIN POTENTIAL SCRIPT ADJUSTMENT
;**************************************************************
; OVERALL PARAMETERS OF RUN
PARAMETERS USERCLASSES=1,FARE=N, MAPSCALE={Units}, HDWAYPERIOD=2,
           NOROUTEERRS=999999, NOROUTEMSGS=999999,
           TRANTIME=LW.TRANTIME,
           TRANTIME[21]=LI.M21TIMEOP,
           ;TRANTIME[22]=LI.M22TIMEOP,
           ;TRANTIME[23]=LI.M23TIMEOP,
           ;TRANTIME[24]=LI.M24TIMEOP,
           TRANTIME[27]=LI.M27TIMEOP

;**************************************************************
;END POTENTIAL SCRIPT ADJUSTMENT
;**************************************************************

  REPORT LINES=T
  PROCESS PHASE=LINKREAD
          LW.TRANTIME=LI.M21TIMEOP
          LW.WALKTIME=LI.WALKTIME
          LW.WALKDISTANCE=LI.DISTANCE
          LW.DISTANCE=LI.DISTANCE
  ENDPROCESS

  PROCESS PHASE=DATAPREP

  ; 1 - Generate Walk Access Connectors
  GENERATE, COST=(LW.WALKDISTANCE),EXTRACTCOST=(LW.WALKTIME),MAXCOST=200*{WALKACC},LIST=T,EXCLUDELINK=(LI.FACILITY_TYPE=10-19,69,70-99),
            NTLEGMODE=1,MAXNTLEGS=200*{MAXWLKACCLNKS},DIRECTION=3,ONEWAY=F,FROMNODE=1-{ZONESA},TONODE={NODEMIN}-99999

  ; 4 - Generate All-Walk Connectors
  GENERATE, COST=(LW.WALKDISTANCE),EXTRACTCOST=(LW.WALKTIME),MAXCOST=200*7,LIST=T,EXCLUDELINK=(LI.FACILITY_TYPE=10-19,69,70-99),
            NTLEGMODE=4,MAXNTLEGS=200*{MAXWLKACCLNKS},DIRECTION=3,ONEWAY=F,FROMNODE=1-{ZONESA},TONODE=1-{ZONESA}

  ; 11 - If micro-coding exists, generate Fixed-guideway to bus transfer connectors
  IF({isMicroCode} <> 0)
  GENERATE, COST=(LW.DISTANCE),EXTRACTCOST=(LI.WALKTIME),MAXCOST=200*{WALKACC},LIST=T,INCLUDELINK=(LI.FACILITY_TYPE=59),
             NTLEGMODE=11,MAXNTLEGS=200*{MAXWLKACCLNKS},DIRECTION=3,ONEWAY=F,FROMNODE={NODEMIN}-99999,TONODE={NODEMIN}-99999
  endif

  ; 12 - Generate CBD sidewalk connectors
   READ, FILE = "{SCENARIO_DIR}\OUTPUT\\CBDXFER_TMP.DAT"

ENDPROCESS

ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TPMAT00C.S"
; 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\TPMAT00N.PRN" MSG='Subdivide connectors into separate files by mode'
FILEO PRINTO[6] = "{SCENARIO_DIR}\output\NTLEG4OP_{alt}{year}.NTL"
FILEO PRINTO[4] = "{SCENARIO_DIR}\output\NTLEG11OP_{alt}{year}.NTL"
FILEI RECI = "{SCENARIO_DIR}\output\NTLEGOP_{year}{alt}.TEM"
FILEO PRINTO[5] = "{SCENARIO_DIR}\output\NTLEG12OP_{alt}{year}.NTL"
FILEO PRINTO[1] = "{SCENARIO_DIR}\output\NTLEG1OP_{alt}{year}.NTL"

s1=strpos('NT',reci)
s2=strpos('LEG',reci)
s3=strpos('MODE',reci)
s4=strpos('COST',reci)
s5=strpos('DIST',reci)
s6=strpos('ONEWAY',reci)
s7=strpos('XN',reci)

; get the origin and destination zone
s8=(s3-s2)
leg1=substr(reci,s2,s8)
s9=strpos('=',leg1)
s10=strpos('-',leg1)
s11=(s9+1)
s12=(s10-1)
s13=(s10+1)
zonei=val(substr(leg1,s11,s12))
zonej=val(substr(leg1,s13,strlen(leg1)))

; get the mode number
s14=(s4-s3)
mode1=substr(reci,s3,s14)
s15=strpos('=',mode1)
s16=(s15+1)
mode=val(substr(mode1,s16,strlen(mode1)))

; get the time on the connector (cost field in the NT leg file)
s17=(s5-s4)
time1=substr(reci,s4,s17)
s18=strpos('=',time1)
s19=(s18+1)
time=val(substr(time1,s19,strlen(time1)))

; get the distance
s20=(s6-s5)
dist1=substr(reci,s5,s20)
s21=strpos('=',dist1)
s22=(s21+1)
dist=val(substr(dist1,s22,strlen(dist1)))

; get the rest of the string
s23=substr(reci,s6,strlen(reci))

if (i==1 && _ctr==0)
  PRINT LIST=";;<<PT>>;;", PRINTO=1
  PRINT LIST=";;<<PT>>;;", PRINTO=4
  PRINT LIST=";;<<PT>>;;", PRINTO=5
  PRINT LIST=";;<<PT>>;;", PRINTO=6
  _ctr = _ctr + 1
endif
if (mode=1) PRINT LIST="NT LEG=",zonei(5.0),"-",zonej(5.0)," MODE=",mode(2.0)," COST=",time(6.2)," DIST=",dist(5.2)," ",s23,PRINTO=1
if (mode=4) PRINT LIST="NT LEG=",zonei(5.0),"-",zonej(5.0)," MODE=",mode(2.0)," COST=",time(6.2)," DIST=",dist(5.2)," ",s23,PRINTO=6
if (mode=11) PRINT LIST="NT LEG=",zonei(5.0),"-",zonej(5.0)," MODE=",mode(2.0)," COST=",time(6.2)," DIST=",dist(5.2)," ",s23,PRINTO=4
if (mode=12) PRINT LIST="NT LEG=",zonei(5.0),"-",zonej(5.0)," MODE=",mode(2.0)," COST=",time(6.2)," DIST=",dist(5.2)," ",s23,PRINTO=5


ENDRUN


; PILOT Script
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.

*if exist {SCENARIO_DIR}\output\AUTOCON.OUT del {SCENARIO_DIR}\output\AUTOCON.OUT
*if exist {SCENARIO_DIR}\output\AUTOCONPK.OUT del {SCENARIO_DIR}\output\AUTOCONPK.OUT
*if exist {SCENARIO_DIR}\output\AUTOCONOP.OUT del {SCENARIO_DIR}\output\AUTOCONOP.OUT

*AUTOCON.exe AM
*copy {SCENARIO_DIR}\output\AUTOCON.OUT {SCENARIO_DIR}\output\AUTOCONPK.OUT
;*AUTOCON.exe MD
;*if exist {SCENARIO_DIR}\output\AUTOCON.OUT copy {SCENARIO_DIR}\output\AUTOCON.OUT {SCENARIO_DIR}\output\AUTOCONOP.OUT
;*if exist {SCENARIO_DIR}\output\AUTOCON.OUT del {SCENARIO_DIR}\output\AUTOCON.OUT
; End of PILOT Script

; PILOT Script
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.

*if exist {SCENARIO_DIR}\output\AUTOCON.OUT del {SCENARIO_DIR}\output\AUTOCON.OUT
;*if exist {SCENARIO_DIR}\output\AUTOCONPK.OUT del {SCENARIO_DIR}\output\AUTOCONPK.OUT
;*if exist {SCENARIO_DIR}\output\AUTOCONOP.OUT del {SCENARIO_DIR}\output\AUTOCONOP.OUT
*AUTOCON.exe MD
*copy {scenario_dir}\output\autocon.out {scenario_dir}\output\AUTOCONOP.out
; End of PILOT Script

; PILOT Script

DistributeMultiStep ProcessID="FSUTMSdist" ProcessNum=1

; End of PILOT Script

; Script for program PUBLIC TRANSPORT in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TRPTR00A.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=PUBLIC TRANSPORT PRNFILE="X:\Projects\CRTPA\Model\C\APPLICATIONS\TRPTR00A.PRN" MSG='Walk-Access Paths/Skims - peak'
FILEI NTLEGI[2] = "{Scenario_Dir}\Output\NTLEG2PK_{ALT}{Year}.NTL"
FILEI NETI = "{SCENARIO_DIR}\output\HWYLOAD2_{Alt}{Year}.NET"
FILEI NTLEGI[4] = "{SCENARIO_DIR}\output\NTLEG12PK_{alt}{year}.NTL"
FILEI NTLEGI[3] = "{SCENARIO_DIR}\output\NTLEG11PK_{alt}{year}.NTL"
FILEI NTLEGI[1] = "{SCENARIO_DIR}\output\NTLEG1PK_{alt}{year}.NTL"
FILEO MATO[1] = "{SCENARIO_DIR}\output\TSKIMAM1_{alt}{year}.MAT",
  MO=1-15, NAME=WALKTIME,AutoTIME,SidewalkTIME,BUSTIME,PBUSTIME,CIRCTIME,RAILTIME,COMRLTIME,OTHTIME,PRJTIME,XFER,IWAIT,XWAIT,FARE,TOTTIME
FILEO LINEO = "{SCENARIO_DIR}\output\pkwalk.lin"
FILEO NTLEGO = "{SCENARIO_DIR}\output\pkwalk.ntl"
FILEO ROUTEO[1] = "{SCENARIO_DIR}\output\TPATHAM1_{alt}{year}.RTE",
  REPORTI={FromNode}, REPORTJ={ToNode}, TRACEI={FromNode}, TRACEJ={ToNode}
FILEO REPORTO = "{SCENARIO_DIR}\output\pkwalk.rpt"
FILEO NETO = "{SCENARIO_DIR}\output\PKWalk.NET"
FILEI FACTORI[1] = "{SCENARIO_DIR}\output\WalkTransit.FAC"
FILEI FAREI = "{Scenario_Dir}\Input\TFARES_{Year}{ALT}.FAR"
FILEI SYSTEMI = "{CATALOG_DIR}\parameters\TSYSD.PTS"
FILEI LINEI[1] = "{SCENARIO_DIR}\INPUT\TROUTE_{YEAR}{ALT}.LIN"

;**************************************************************
;BEGIN POTENTIAL SCRIPT ADJUSTMENT
;**************************************************************
;PAR ZONE={ZONESA}
; OVERALL PARAMETERS
PARAMETERS USERCLASSES=1,FARE=N, MAPSCALE={Units}, HDWAYPERIOD=1,
           NOROUTEERRS=999999, NOROUTEMSGS=999999,
           TRANTIME=LW.TRANTIME,
           TRANTIME[21]=LI.M21TIMEPK,
           ;TRANTIME[22]=LI.M22TIMEPK,
           ;TRANTIME[23]=LI.M23TIMEPK,
           ;TRANTIME[24]=LI.M24TIMEPK,
           ;TRANTIME[25]=LI.M25TIMEPK
           ;TRANTIME[26]=LI.M26TIMEPK,
           TRANTIME[27]=LI.M27TIMEPK
           ;TRANTIME[31]=LI.M31TIMEPK,
           ;TRANTIME[32]=LI.M32TIMEPK,
           ;TRANTIME[33]=LI.M33TIMEPK,
           ;TRANTIME[34]=LI.M34TIMEPK,
           ;TRANTIME[35]=LI.M35TIMEPK
           ;TRANTIME[36]=LI.M36TIMEPK,
           ;TRANTIME[37]=LI.M37TIMEPK

;**************************************************************
;END POTENTIAL SCRIPT ADJUSTMENT
;**************************************************************

PROCESS PHASE=LINKREAD
           LW.TRANTIME=LI.M21TIMEPK
           LW.WALKTIME=LI.WALKTIME
           LW.WALKDISTANCE=LI.DISTANCE
           LW.DISTANCE=LI.DISTANCE
ENDPROCESS

PROCESS PHASE=DATAPREP

          ; Generate walk-access links
          GENERATE READNTLEGI=1
          ; Generate station-access links
          READ, FILE = "{SCENARIO_DIR}\OUTPUT\STATIONCONN_{ALT}{YEAR}.DAT"
          ; Generate auto-access links
          GENERATE READNTLEGI=2
          IF({isMicroCode} <> 0)
            ; Generate fixed-guideway to bus links
            GENERATE READNTLEGI=3
          ENDIF
          ; Generate CBD transfer links
          GENERATE READNTLEGI=4
ENDPROCESS
;**************************************************************
;BEGIN POTENTIAL SCRIPT ADJUSTMENT
;**************************************************************

PROCESS PHASE=SKIMIJ
  MW[1]=TIMEA(0,1)                                   ; Walk time
  MW[2]=TIMEA(0,2)                                   ; Auto time
  MW[3]=TIMEA(0,11)+TIMEA(0,12)                      ; Sidewalk time
  MW[4]=TIMEA(0,21)+TIMEA(0,31)                      ; Local bus time
  MW[5]=TIMEA(0,22)+TIMEA(0,32)                      ; Premium bus time
  MW[6]=TIMEA(0,23)+TIMEA(0,33)                      ; Circulator time
  MW[7]=TIMEA(0,24)+TIMEA(0,34)                      ; Light/Heavy Rail time
  MW[8]=TIMEA(0,25)+TIMEA(0,35)                      ; Commuter Rail time
  MW[9]=TIMEA(0,26)+TIMEA(0,36)                      ; Other mode time
  MW[10]=TIMEA(0,27)+TIMEA(0,37)                     ; Project mode time
 IF (BRDINGS(0,TMODES) > 0)
   MW[11]=BRDINGS(0,TMODES)-1                        ; Number of transfers
 ELSE
   MW[11]=0
 ENDIF
  MW[12]=IWAITA(0)                                    ; Initial wait time
  MW[13]=XWAITA(0)                                     ; Transfer wait time
  MW[14]=FAREA(0)                                    ; Fare matrix
  MW[15]=TIMEA(0,ALLMODES)                            ; Time on all modes
ENDPROCESS

;**************************************************************
;END POTENTIAL SCRIPT ADJUSTMENT
;**************************************************************

ENDRUN


; PILOT Script

EndDistributeMultiStep

DistributeMultiStep ProcessID="FSUTMSdist" ProcessNum=2
; End of PILOT Script

; Script for program PUBLIC TRANSPORT in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TRPTR00B.S"

; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=PUBLIC TRANSPORT PRNFILE="X:\Projects\CRTPA\Model\C\APPLICATIONS\TRPTR00D.PRN" MSG='Auto-Access Paths/Skims - peak'
FILEI NTLEGI[2] = "{Scenario_Dir}\Output\NTLEG2PK_{ALT}{Year}.NTL"
FILEI NETI = "{SCENARIO_DIR}\output\HWYLOAD2_{Alt}{Year}.NET"
FILEI NTLEGI[3] = "{SCENARIO_DIR}\output\NTLEG11PK_{alt}{year}.NTL"
FILEI NTLEGI[4] = "{SCENARIO_DIR}\output\NTLEG12PK_{alt}{year}.NTL"
FILEI NTLEGI[1] = "{SCENARIO_DIR}\output\NTLEG1PK_{alt}{year}.NTL"
FILEO MATO[1] = "{SCENARIO_DIR}\output\TSKIMAM3_{alt}{year}.MAT",
  MO=1-15, NAME=WALKTIME,AutoTIME,SidewalkTIME,BUSTIME,PBUSTIME,CIRCTIME,RAILTIME,COMRLTIME,OTHTIME,PRJTIME,XFER,IWAIT,XWAIT,FARE,TOTTIME
FILEO LINEO = "{SCENARIO_DIR}\output\pkwalk.lin"
FILEO NTLEGO = "{SCENARIO_DIR}\output\pkauto.ntl"
FILEO ROUTEO[1] = "{SCENARIO_DIR}\output\TPATHAM3_{alt}{year}.RTE",
  REPORTI={FromNode}, REPORTJ={ToNode}, TRACEI={FromNode}, TRACEJ={ToNode}
FILEO REPORTO = "{SCENARIO_DIR}\output\pkauto.rpt"
FILEO NETO = "{SCENARIO_DIR}\output\PKAuto.NET"
FILEI FACTORI[1] = "{SCENARIO_DIR}\output\AutoTransit.FAC"
FILEI FAREI = "{Scenario_Dir}\Input\TFARES_{Year}{ALT}.FAR"
FILEI SYSTEMI = "{CATALOG_DIR}\parameters\TSYSD.PTS"
FILEI LINEI[1] = "{SCENARIO_DIR}\INPUT\TROUTE_{YEAR}{ALT}.LIN"

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

; OVERALL PARAMETERS
PARAMETERS USERCLASSES=1,FARE=N, MAPSCALE={Units}, HDWAYPERIOD=1,
           NOROUTEERRS=999999, NOROUTEMSGS=999999,
           TRANTIME=LW.TRANTIME,
           TRANTIME[21]=LI.M21TIMEPK,
         ;  TRANTIME[22]=LI.M22TIMEPK,
         ;  TRANTIME[23]=LI.M23TIMEPK,
         ;  TRANTIME[24]=LI.M24TIMEPK,
         ;  TRANTIME[25]=LI.M25TIMEPK
         ;  TRANTIME[26]=LI.M26TIMEPK,
           TRANTIME[27]=LI.M27TIMEPK
         ;  TRANTIME[31]=LI.M31TIMEPK,
         ;  TRANTIME[32]=LI.M32TIMEPK,
         ;  TRANTIME[33]=LI.M33TIMEPK,
         ;  TRANTIME[34]=LI.M34TIMEPK,
         ;  TRANTIME[35]=LI.M35TIMEPK
         ;  TRANTIME[36]=LI.M36TIMEPK,
         ;  TRANTIME[37]=LI.M37TIMEPK

;**************************************************************
;END POTENTIAL SCRIPT ADJUSTMENT
;**************************************************************

PROCESS PHASE=LINKREAD
           LW.TRANTIME=LI.M21TIMEPK
           LW.WALKTIME=LI.WALKTIME
           LW.WALKDISTANCE=LI.DISTANCE
           LW.DISTANCE=LI.DISTANCE
ENDPROCESS

PROCESS PHASE=DATAPREP

           ; Generate walk-access links
           GENERATE READNTLEGI=1
           ; Generate station-access links
           READ, FILE = "{SCENARIO_DIR}\OUTPUT\STATIONCONN_{ALT}{YEAR}.DAT"
           ; Generate auto-access links
           GENERATE READNTLEGI=2
        IF({isMicroCode} <> 0)
           ; Generate fixed-guideway to bus links
           GENERATE READNTLEGI=3
        ENDIF
           ; Generate CBD transfer links
           GENERATE READNTLEGI=4
ENDPROCESS
;**************************************************************
;BEGIN POTENTIAL SCRIPT ADJUSTMENT
;**************************************************************

PROCESS PHASE=SKIMIJ
  MW[1]=TIMEA(0,1)                                                              ; Walk time
  MW[2]=TIMEA(0,2)                                                              ; Auto time
  MW[3]=TIMEA(0,11)+TIMEA(0,12)                                                 ; Sidewalk time
  MW[4]=TIMEA(0,21)+TIMEA(0,31)                                                              ; Local bus time
  MW[5]=TIMEA(0,22)+TIMEA(0,32)                                                             ; Premium bus time
  MW[6]=TIMEA(0,23)+TIMEA(0,33)                                                              ; Circulator time
  MW[7]=TIMEA(0,24)+TIMEA(0,34)                                                             ; Light/Heavy Rail time
  MW[8]=TIMEA(0,25)+TIMEA(0,35)                                                             ; Commuter Rail time
  MW[9]=TIMEA(0,26)+TIMEA(0,36)                                                              ; Other mode time
  MW[10]=TIMEA(0,27)+TIMEA(0,37)                                                            ; Project mode time
 IF(BRDINGS(0,TMODES) > 0)
   MW[11]=BRDINGS(0,TMODES)-1                                                   ; Number of transfers
 ELSE
   MW[11]=0
 ENDIF
  MW[12]=IWAITA(0)                                                              ; Initial wait time
  MW[13]=XWAITA(0)                                                              ; Transfer wait time
  MW[14]=FAREA(0)                                                               ; Fare matrix
  MW[15]=TIMEA(0,ALLMODES)                                                      ; Time on all modes
ENDPROCESS

;**************************************************************
;END POTENTIAL SCRIPT ADJUSTMENT
;**************************************************************

ENDRUN


; PILOT Script
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.

EndDistributeMultiStep

DistributeMultiStep ProcessID="FSUTMSdist" ProcessNum=3
; End of PILOT Script

; Script for program PUBLIC TRANSPORT in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TRPTR00C.S"

; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=PUBLIC TRANSPORT PRNFILE="X:\Projects\CRTPA\Model\C\APPLICATIONS\TRPTR00E.PRN" MSG='Walk-Access Paths/Skims - off-peak'
FILEI NTLEGI[2] = "{Scenario_Dir}\Output\NTLEG2OP_{ALT}{Year}.NTL"
FILEI NTLEGI[1] = "{SCENARIO_DIR}\output\NTLEG1OP_{alt}{year}.NTL"
FILEI NETI = "{SCENARIO_DIR}\output\unloaded2_{alt}{year}.net"
FILEI NTLEGI[4] = "{SCENARIO_DIR}\output\NTLEG12OP_{alt}{year}.NTL"
FILEI NTLEGI[3] = "{SCENARIO_DIR}\output\NTLEG11OP_{alt}{year}.NTL"
FILEO MATO[1] = "{SCENARIO_DIR}\output\TSKIMMD1_{alt}{year}.MAT",
  MO=1-15, NAME=WALKTIME,AutoTIME,SidewalkTIME,BUSTIME,PBUSTIME,CIRCTIME,RAILTIME,COMRLTIME,OTHTIME,PRJTIME,XFER,IWAIT,XWAIT,FARE,TOTTIME
FILEO LINEO = "{SCENARIO_DIR}\output\opwalk.lin"
FILEO NTLEGO = "{SCENARIO_DIR}\output\opwalk.ntl"
FILEO ROUTEO[1] = "{SCENARIO_DIR}\output\TPATHMD1_{alt}{year}.RTE",
  REPORTI={FromNode}, REPORTJ={ToNode}, TRACEI={FromNode}, TRACEJ={ToNode}
FILEO REPORTO = "{SCENARIO_DIR}\output\opwalk.rpt"
FILEO NETO = "{SCENARIO_DIR}\output\OPWalk.NET"
FILEI FACTORI[1] = "{SCENARIO_DIR}\output\WalkTransit.FAC"
FILEI FAREI = "{SCENARIO_DIR}\\Input\TFARES_{Year}{ALT}.FAR"
FILEI SYSTEMI = "{CATALOG_DIR}\parameters\TSYSD.PTS"
FILEI LINEI[1] = "{SCENARIO_DIR}\INPUT\TROUTE_{YEAR}{ALT}.LIN"

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

; OVERALL PARAMETERS
PARAMETERS USERCLASSES=1,FARE=N, MAPSCALE={Units}, HDWAYPERIOD=2,
           NOROUTEERRS=999999, NOROUTEMSGS=999999,
           TRANTIME=LW.TRANTIME,
           TRANTIME[21]=LI.M21TIMEOP,
           ;TRANTIME[22]=LI.M22TIMEOP,
           ;TRANTIME[23]=LI.M23TIMEOP,
           ;TRANTIME[24]=LI.M24TIMEOP,
           ;TRANTIME[25]=LI.M25TIMEOP
           ;TRANTIME[26]=LI.M26TIMEOP,
           TRANTIME[27]=LI.M27TIMEOP
          ; TRANTIME[31]=LI.M31TIMEOP,
          ; TRANTIME[32]=LI.M32TIMEOP,
          ; TRANTIME[33]=LI.M33TIMEOP,
          ; TRANTIME[34]=LI.M34TIMEOP,
          ; TRANTIME[35]=LI.M35TIMEOP
          ; TRANTIME[36]=LI.M36TIMEOP,
          ; TRANTIME[37]=LI.M37TIMEOP
;**************************************************************
;END POTENTIAL SCRIPT ADJUSTMENT
;**************************************************************

PROCESS PHASE=LINKREAD
           LW.TRANTIME=LI.M21TIMEOP
           LW.WALKTIME=LI.WALKTIME
           LW.WALKDISTANCE=LI.DISTANCE
           LW.DISTANCE=LI.DISTANCE
ENDPROCESS

PROCESS PHASE=DATAPREP

           ; Generate walk-access links
           GENERATE READNTLEGI=1
           ; Generate station-access links
           READ, FILE = "{SCENARIO_DIR}\OUTPUT\STATIONCONN_{ALT}{YEAR}.DAT"
           ; Generate auto-access links
          GENERATE READNTLEGI=2
        IF({isMicroCode} <> 0)
           ; Generate fixed-guideway to bus links
           GENERATE READNTLEGI=3
        ENDIF
           ; Generate CBD transfer links
           GENERATE READNTLEGI=4

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

PROCESS PHASE=SKIMIJ
  MW[1]=TIMEA(0,1)                                                              ; Walk time
  MW[2]=TIMEA(0,2)                                                              ; Auto time
  MW[3]=TIMEA(0,11)+TIMEA(0,12)                                                 ; Sidewalk time
  MW[4]=TIMEA(0,21)+TIMEA(0,31)                                                               ; Local bus time
  MW[5]=TIMEA(0,22)+TIMEA(0,32)                                                             ; Premium bus time
  MW[6]=TIMEA(0,23)+TIMEA(0,33)                                                               ; Circulator time
  MW[7]=TIMEA(0,24)+TIMEA(0,34)                                                               ; Light/Heavy Rail time
  MW[8]=TIMEA(0,25)+TIMEA(0,35)                                                               ; Commuter Rail time
  MW[9]=TIMEA(0,26)+TIMEA(0,36)                                                             ; Other mode time
  MW[10]=TIMEA(0,27)+TIMEA(0,37)                                                              ; Project mode time
 IF (BRDINGS(0,TMODES) > 0)
   MW[11]=BRDINGS(0,TMODES)-1                                                   ; Number of transfers
 ELSE
   MW[11]=0
 ENDIF
  MW[12]=IWAITA(0)                                                              ; Initial wait time
  MW[13]=XWAITA(0)                                                              ; Transfer wait time
  MW[14]=FAREA(0)                                                               ; Fare matrix
  MW[15]=TIMEA(0,ALLMODES)                                                      ; Time on all modes
ENDPROCESS

;**************************************************************
;END POTENTIAL SCRIPT ADJUSTMENT
;**************************************************************

ENDRUN


; Script for program PUBLIC TRANSPORT in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TRPTR00D.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=PUBLIC TRANSPORT PRNFILE="X:\Projects\CRTPA\Model\C\APPLICATIONS\TRPTR00G.PRN" MSG='Auto-Access Paths/Skims - off-peak'
FILEI NTLEGI[2] = "{Scenario_Dir}\Output\NTLEG2OP_{ALT}{Year}.NTL"
FILEI NTLEGI[1] = "{SCENARIO_DIR}\output\NTLEG1OP_{alt}{year}.NTL"
FILEI NETI = "{SCENARIO_DIR}\output\unloaded2_{alt}{year}.net"
FILEI NTLEGI[4] = "{SCENARIO_DIR}\output\NTLEG12OP_{alt}{year}.NTL"
FILEI NTLEGI[3] = "{SCENARIO_DIR}\output\NTLEG11OP_{alt}{year}.NTL"
FILEO MATO[1] = "{SCENARIO_DIR}\output\TSKIMMD3_{alt}{year}.MAT",
  MO=1-15, NAME=WALKTIME,AutoTIME,SidewalkTIME,BUSTIME,PBUSTIME,CIRCTIME,RAILTIME,COMRLTIME,OTHTIME,PRJTIME,XFER,IWAIT,XWAIT,FARE,TOTTIME
FILEO LINEO = "{SCENARIO_DIR}\output\OPAuto.lin"
FILEO NTLEGO = "{SCENARIO_DIR}\output\OPAuto.ntl"
FILEO ROUTEO[1] = "{SCENARIO_DIR}\output\TPATHMD3_{alt}{year}.RTE",
  REPORTI={FromNode}, REPORTJ={ToNode}, TRACEI={FromNode}, TRACEJ={ToNode}
FILEO REPORTO = "{SCENARIO_DIR}\output\OPAuto.rpt"
FILEO NETO = "{SCENARIO_DIR}\output\OPAuto.NET"
FILEI FACTORI[1] = "{SCENARIO_DIR}\output\AutoTransit.FAC"
FILEI FAREI = "{Scenario_Dir}\Input\TFARES_{Year}{ALT}.FAR"
FILEI SYSTEMI = "{CATALOG_DIR}\parameters\TSYSD.PTS"
FILEI LINEI[1] = "{SCENARIO_DIR}\INPUT\TROUTE_{YEAR}{ALT}.LIN"

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

; OVERALL PARAMETERS
PARAMETERS USERCLASSES=1,FARE=N, MAPSCALE={Units}, HDWAYPERIOD=2,
           NOROUTEERRS=999999, NOROUTEMSGS=999999,
           TRANTIME=LW.TRANTIME,
           TRANTIME[21]=LI.M21TIMEOP,
        ;   TRANTIME[22]=LI.M22TIMEOP,
        ;   TRANTIME[23]=LI.M23TIMEOP,
        ;   TRANTIME[24]=LI.M24TIMEOP,
        ;   TRANTIME[25]=LI.M25TIMEOP
        ;   TRANTIME[26]=LI.M26TIMEOP,
           TRANTIME[27]=LI.M27TIMEOP
        ;   TRANTIME[31]=LI.M31TIMEOP,
         ;  TRANTIME[32]=LI.M32TIMEOP,
         ;  TRANTIME[33]=LI.M33TIMEOP,
         ;  TRANTIME[34]=LI.M34TIMEOP,
         ;  TRANTIME[35]=LI.M35TIMEOP
         ;  TRANTIME[36]=LI.M36TIMEOP,
         ;  TRANTIME[37]=LI.M37TIMEOP

;**************************************************************
;END POTENTIAL SCRIPT ADJUSTMENT
;**************************************************************

PROCESS PHASE=LINKREAD
           LW.TRANTIME=LI.M21TIMEOP
           LW.WALKTIME=LI.WALKTIME
           LW.WALKDISTANCE=LI.DISTANCE
           LW.DISTANCE=LI.DISTANCE
ENDPROCESS

PROCESS PHASE=DATAPREP

           ; Generate walk-access links
           GENERATE READNTLEGI=1
           ; Generate station-access links
           READ, FILE = "{SCENARIO_DIR}\OUTPUT\STATIONCONN_{ALT}{YEAR}.DAT"
           ; Generate auto-access links
           GENERATE READNTLEGI=2
           IF({isMicroCode} <> 0)
             ; Generate fixed-guideway to bus links
             GENERATE READNTLEGI=3
           ENDIF
           ; Generate CBD transfer links
           GENERATE READNTLEGI=4

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

PROCESS PHASE=SKIMIJ
  MW[1]=TIMEA(0,1)                                                              ; Walk time
  MW[2]=TIMEA(0,2)                                                              ; Auto time
  MW[3]=TIMEA(0,11)+TIMEA(0,12)                                                 ; Sidewalk time
  MW[4]=TIMEA(0,21)+TIMEA(0,31)                                                               ; Local bus time
  MW[5]=TIMEA(0,22)+TIMEA(0,32)                                                                ; Premium bus time
  MW[6]=TIMEA(0,23)+TIMEA(0,33)                                                                ; Circulator time
  MW[7]=TIMEA(0,24)+TIMEA(0,34)                                                               ; Light/Heavy Rail time
  MW[8]=TIMEA(0,25)+TIMEA(0,35)                                                                ; Commuter Rail time
  MW[9]=TIMEA(0,26)+TIMEA(0,36)                                                                ; Other mode time
  MW[10]=TIMEA(0,27)+TIMEA(0,37)                                                              ; Project mode time
 IF (BRDINGS(0,TMODES) > 0)
   MW[11]=BRDINGS(0,TMODES)-1                                                   ; Number of transfers
 ELSE
   MW[11]=0
 ENDIF
  MW[12]=IWAITA(0)                                                              ; Initial wait time
  MW[13]=XWAITA(0)                                                              ; Transfer wait time
  MW[14]=FAREA(0)                                                               ; Fare matrix
  MW[15]=TIMEA(0,ALLMODES)                                                      ; Time on all modes
ENDPROCESS



;**************************************************************
;END POTENTIAL SCRIPT ADJUSTMENT
;**************************************************************

ENDRUN


; PILOT Script
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.

EndDistributeMultiStep

DistributeMultiStep ProcessID="FSUTMSdist" ProcessNum=4
; End of PILOT Script

; Script for program PUBLIC TRANSPORT in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TRPTR00E.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=PUBLIC TRANSPORT PRNFILE="X:\Projects\CRTPA\Model\C\APPLICATIONS\TRPTR00I.PRN" MSG='All-walk paths'
FILEI NETI = "{SCENARIO_DIR}\output\unloaded2_{alt}{year}.net"
FILEI NTLEGI[1] = "{SCENARIO_DIR}\output\NTLEG4PK_{alt}{year}.NTL"
FILEO MATO[1] = "{SCENARIO_DIR}\output\AllWalk_{alt}{year}.MAT",
  MO=1, DEC=D,NAME=ALLWALK
FILEO ROUTEO[1] = "{SCENARIO_DIR}\output\AllWalk_{alt}{year}.RTE",
  REPORTI={FromNode}, REPORTJ={ToNode}, TRACEI={FromNode}, TRACEJ={ToNode}
FILEO REPORTO = "{SCENARIO_DIR}\output\AllWalk.rpt"
FILEO NETO = "{SCENARIO_DIR}\output\AllWalk.net"
FILEI FACTORI[1] = "{CATALOG_DIR}\parameters\AllWalk.FAC"
FILEI FAREI = "{Scenario_Dir}\Input\TFARES_{Year}{ALT}.FAR"
FILEI SYSTEMI = "{CATALOG_DIR}\parameters\TSYSD.PTS"
FILEI LINEI[1] = "{SCENARIO_DIR}\INPUT\TROUTE_{YEAR}{ALT}.LIN"

; OVERALL PARAMETERS OF RUN
PARAMETERS USERCLASSES=1,FARE=N, MAPSCALE={UNITS}, HDWAYPERIOD=2,
           NOROUTEERRS=999999, NOROUTEMSGS=999999, 
           TRANTIME=LW.TRANTIME

PROCESS PHASE=LINKREAD
           LW.TRANTIME=LI.M21TIMEOP
           LW.DISTANCE=LI.DISTANCE
ENDPROCESS

PROCESS PHASE=DATAPREP
           ; Generate all-walk links
           GENERATE READNTLEGI=1
ENDPROCESS

PROCESS PHASE=SKIMIJ
           MW[1]=TIMEA(0,4)                                         ; All Walk time
ENDPROCESS

ENDRUN


; PILOT Script
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.

EndDistributeMultiStep

Wait4Files Files=FSUTMSdist1.script.end, FSUTMSdist2.script.end, FSUTMSdist3.script.end, FSUTMSdist4.script.end, PrintFiles=SAVE
; End of PILOT Script

; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TRMAT00D.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=MATRIX PRNFILE="X:\Projects\CRTPA\Model\C\APPLICATIONS\TRMAT00C.PRN" MSG='Path-Conditioning Walk'
FILEO MATO[3] = "{SCENARIO_DIR}\output\TSKIMOP1.{alt}{year}",
 MO=61-75,  NAME=WalkTime,AutoTime,SideWalkTime,BusTime,PBusTime,CircTime,RailTime,CommRailTime,OthTime,PRJTime,XFERs,IWAIT,XWAIT,FARE,TOTTIME
FILEO MATO[1] = "{SCENARIO_DIR}\output\TSKIMPK1.{alt}{year}",
MO=21-35, NAME=WalkTime,AutoTime,SideWalkTime,BusTime,PBusTime,CircTime,RailTime,CommRailTime,OthTime,PRJTime,XFERs,IWAIT,XWAIT,FARE,TOTTIME
FILEI MATI[4] = "{SCENARIO_DIR}\output\TSKIMMD1_{alt}{year}.MAT"
FILEI MATI[2] = "{SCENARIO_DIR}\output\TSKIMAM1_{alt}{year}.MAT"
FILEI MATI[1] = "{SCENARIO_DIR}\output\AllWalk_{alt}{year}.MAT"
FILEI LOOKUPI[1] = "{CATALOG_DIR}\parameters\TRN_COEFFICIENTS.DBF"

; Check skims to see if they are better than the all-walk path & if they have required IVT

DistributeINTRAStep ProcessID="FSUTMSDist" ProcessList=1-4

ZONEMSG=100

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

_ovtam =COEFF(1,3)/COEFF(1,1)     ; out-of-vehicle time factor (OVT time and Wait factor)
valtime   =0.6*COEFF(1,1)/COEFF(1,4) ; value of time (in $/hr)
aatfactor =COEFF(1,5)/COEFF(1,1)     ; drive access to transit time factor
_xferpen=COEFF(1,6)/COEFF(1,1)     ; transfer penalty
_boardingpen = 2.0

; Apply OVT factor to all-walk skims

FILLMW MW[11]=MI.1.1
FILLMW MW[21]=MI.2.1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
FILLMW MW[61]=MI.4.1,2,3,4,5,6,7,8,9,10,11,12,13,14,15


LOOP x=1,6
  LOOP y=1,15
    _idx=20 + 20*(x-1) + y
    if ((_idx%20)=14)
      COMP total = ROWFAC(_idx,100.0)
    endif
  ENDLOOP
ENDLOOP

; Apply OVT factor to all-walk skims
COMP total = ROWFAC(11,_ovtam)

JLOOP

  IF (I=={FromNode} && J=={ToNode}) LIST="Trace ",I(5.0),"-",J(5.0)
  IF (I=={FromNode} && J=={ToNode}) LIST="            ","       IVT","      Path","      wOVT","      wTOT"
  IF (I=={FromNode} && J=={ToNode}) LIST="All-Walk    ","          ","          ",MW[11](10.2),MW[11](10.2)

; Check skims to see if they are better than the all-walk path & if they have required IVT
  ; Walk-bus - peak (20 series)
    _ivt = MW[24] + MW[25] + MW[26] + MW[27] + MW[28] + MW[29] + MW[30]
    _pth = MW[24] + MW[26]
    _ovt = MW[22] + _ovtam * (MW[21] + MW[23] + MW[32] + MW[33]) + _boardingpen*(mw[31]+1) + _xferpen * MW[31]
    _tot = _ivt + _ovt
  IF (I=={FromNode} && J=={ToNode}) LIST="Walk-Bus  pk",_ivt(10.2),_pth(10.2),_ovt(10.2),_tot(10.2)
  IF (((MW[11]>0) && (MW[11]<_tot))||(_ivt==0))
    MW[21]=0, MW[22]=0, MW[23]=0, MW[24]=0, MW[25]=0
    MW[26]=0, MW[27]=0, MW[28]=0, MW[29]=0, MW[30]=0
    MW[31]=0,  MW[32]=0, MW[33]=0, MW[34]=0, MW[35]=0
  ENDIF
  
    ; Walk-bus - off-peak (60 series)
    _ivt = MW[64] + MW[65] + MW[66] + MW[67] + MW[68] + MW[69] + MW[70]
    _pth = MW[64] + MW[66]
    _ovt = MW[62] + _ovtam * (MW[61] + MW[63] + MW[72] + MW[73])  + _boardingpen*(mw[71]+1) + _xferpen * MW[71]
    _tot = _ivt + _ovt
  IF (I=={FromNode} && J=={ToNode}) LIST="Walk-Bus  op",_ivt(10.2),_pth(10.2),_ovt(10.2),_tot(10.2)
  IF (((MW[11]>0) && (MW[11]<_tot)) || (_ivt==0))
    MW[61]=0, MW[62]=0, MW[63]=0, MW[64]=0, MW[65]=0
    MW[66]=0, MW[67]=0, MW[68]=0, MW[69]=0, MW[70]=0
    MW[71]=0,MW[72]=0, MW[73]=0, MW[74]=0, MW[75]=0
  ENDIF
   
ENDJLOOP
ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TRMAT00G.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=MATRIX PRNFILE="X:\Projects\CRTPA\Model\C\APPLICATIONS\TRMAT00F.PRN" MSG='Path-Conditioning Auto'
FILEO MATO[2] = "{SCENARIO_DIR}\output\TSKIMOP3.{alt}{year}",
MO=61-75
FILEO MATO[1] = "{SCENARIO_DIR}\output\TSKIMPK3.{alt}{year}",
MO=21-35
FILEI LOOKUPI[1] = "{CATALOG_DIR}\parameters\TRN_COEFFICIENTS.DBF"
FILEI MATI[2] = "{SCENARIO_DIR}\output\TSKIMMD3_{alt}{year}.MAT"
FILEI MATI[1] = "{SCENARIO_DIR}\output\TSKIMAM3_{alt}{year}.MAT"
DistributeINTRAStep ProcessID="FSUTMSDist" ProcessList=1-4

 ZONEMSG=100

 ; Check skims to see if they have required IVT

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

 _ovtam =COEFF(1,3)/COEFF(1,1)     ; out-of-vehicle time factor (OVT time and Wait factor)
 valtime   =0.6*COEFF(1,1)/COEFF(1,4) ; value of time (in $/hr)
 aatfactor =COEFF(1,5)/COEFF(1,1)     ; drive access to transit time factor
 _xferpen=COEFF(1,6)/COEFF(1,1)     ; transfer penalty
 _boardingpen = 2.0

 ; Check skims to see if they are better than the all-walk path & if they have required IVT
 FILLMW MW[21]=MI.1.1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
 FILLMW MW[61]=MI.2.1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
 
 LOOP x=1,4
  LOOP y=1,15
      _idx=20 + 20*(x-1) + y
   IF((_idx%20)=14)
      COMP total = ROWFAC(_idx,100.0)
   ENDIF
  ENDLOOP
 ENDLOOP

 JLOOP

  IF (I=={FromNode} && J=={ToNode}) LIST="Trace ",I(5.0),"-",J(5.0)
  IF (I=={FromNode} && J=={ToNode}) LIST="            ","       IVT","      Path","      wOVT","      wTOT"

    ; Auto-bus - peak (20 series)
    _ivt = MW[24] + MW[25] + MW[26] + MW[27] + MW[28] + MW[29] + MW[30]
    _pth = MW[24] + MW[26]
    _ovt = MW[22] + _ovtam * (MW[21] + MW[23] + MW[32] + MW[33])
    _tot = _ivt + _ovt
  IF (I=={FromNode} && J=={ToNode}) LIST="Auto-Bus  pk",_ivt(10.2),_pth(10.2),_ovt(10.2),_tot(10.2)
  IF (_ivt==0)
    MW[21]=0, MW[22]=0, MW[23]=0, MW[24]=0, MW[25]=0
    MW[26]=0, MW[27]=0, MW[28]=0, MW[29]=0, MW[30]=0
    MW[31]=0, MW[32]=0, MW[33]=0, MW[34]=0, MW[35]=0
  ENDIF
    
    _ivt = MW[23] + MW[24] + MW[25] + MW[26] + MW[27]
    _pth = MW[23]
    _ovt = MW[22] + _ovtam * (MW[21] + MW[29] + MW[30])
    _tot = _ivt + _ovt
  IF(I=={FromNode} && J=={ToNode}) LIST="            ",_ivt(10.2),_pth(10.2),_ovt(10.2),_tot(10.2)

   ; Auto-bus - off-peak (60 series)
    _ivt = MW[64] + MW[65] + MW[66] + MW[67] + MW[68] + MW[69] + MW[70]
    _pth = MW[64] + MW[66]
    _ovt = MW[62] + _ovtam * (MW[61] + MW[63] + MW[72] + MW[73])
    _tot = _ivt + _ovt
  IF (I=={FromNode} && J=={ToNode}) LIST="Auto-Bus  op",_ivt(10.2),_pth(10.2),_ovt(10.2),_tot(10.2)
  IF (_ivt==0)
    MW[61]=0, MW[62]=0, MW[63]=0, MW[64]=0, MW[65]=0
    MW[66]=0, MW[67]=0, MW[68]=0, MW[69]=0, MW[70]=0
    MW[71]=0,  MW[72]=0, MW[73]=0, MW[74]=0, MW[75]=0
  ENDIF
   
    _ivt = MW[63] + MW[64] + MW[65] + MW[66] + MW[67]
    _pth = MW[63]
    _ovt = MW[62] + _ovtam * (MW[61] + MW[69] + MW[70])
    _tot = _ivt + _ovt
  IF(I=={FromNode} && J=={ToNode}) LIST="            ",_ivt(10.2),_pth(10.2),_ovt(10.2),_tot(10.2)
   
 ENDJLOOP

ENDRUN


; PILOT Script





*echo Transit Paths/Skims                               = %date%  %time% >>{SCENARIO_DIR}\Output\runtime.prn
; End of PILOT Script

; PILOT Script

DistributeMULTISTEP ProcessID="FSUTMSDist", ProcessNum=1

; End of PILOT Script

; Script for program PUBLIC TRANSPORT in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\STPTR00K.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=PUBLIC TRANSPORT PRNFILE="{SCENARIO_DIR}\output\STPTR00I2.PRN" MSG='pnr-bus stop to stop file'
FILEI ROUTEI[1] = "{SCENARIO_DIR}\output\TPATHAM3_{Alt}{year}.RTE"
FILEI NETI = "{SCENARIO_DIR}\output\PKauto.NET"
FILEO REPORTO = "{SCENARIO_DIR}\output\STPTR00J2.PRN"
FILEO STOP2STOPO = "{SCENARIO_DIR}\output\ST2STPK3_{alt}{year}.DBF",
     ACCUMULATE=firstlast, MODES=21,23, N={NODEMIN}-99999

PARAMETERS NOROUTEERRS=99999999, NOROUTEMSGS=99999999,USERCLASSES=1,HDWAYPERIOD=1,
           TRIPSIJ[1]=10

ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\STMAT00A.S"
; 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\STMAT00A.PRN" MSG='Write out station zone, parking cost and terminal time to matrix'
FILEO MATO[1] = "{SCENARIO_DIR}\output\ST2STPK_bus_{alt}{year}.MAT",
 MO=1,21-24,
 NAME=FromStation_pnrb,StationTAZ_pnrb,PKParkCost_pnrb,termtimpnr,termtimknr
FILEI LOOKUPI[1] = "{SCENARIO_DIR}\output\STATION_{alt}{year}.DAT"
FILEI MATI[1] = "{SCENARIO_DIR}\output\ST2STPK3_{alt}{year}.DBF",
 PATTERN=IJM:V FIELDS=I,J,0,FROMNODE

PAR ZONES={ZONESA} zonemsg=100

;STATION PARKING COST INTO A LOOKUP TABLE - station, statnumber, spaces,pnrterm,knrterm,nearestzone(distance),nearestzone(statdata input),ampnrcost,mdpnrcost

LOOKUP LOOKUPI=1, 
  NAME=STATIONS,
  LOOKUP[1]=2, RESULT=3,; STATION ZONE
  LOOKUP[2]=2, RESULT=6,; Peak Period Pakring Cost
  LOOKUP[3]=2,result=8,
  LOOKUP[4]=2,result=9,
  FAIL=0

  MW[1]=MI.1.1 

JLOOP
 ;FIRST FIGURE OUT THE STATION EQUIVALENT FOR EACH CELL, 0 IF NO MATCH
 ;NEXT, ASSIGN THE STATION EQUIVALENT FOR EACH CELL TO A WORK MATRIX
  STATZONE1=STATIONS(1,MW[1][J],0)
  PARKINGCOST1=STATIONS(2,MW[1][J],0)
  termtimpnr=stations(3,MW[1][j],0)
  termtimknr=stations(4,MW[1][j],0)
  MW[21][J]=STATZONE1
  MW[22][J]=PARKINGCOST1
  MW[23][j]=termtimpnr
  MW[24][j]=termtimknr

; If no station for a zone, write 0 as the station
 IF(MW[21][J] == 0) MW[1][J]=0

ENDJLOOP

ENDRUN


; Script for program PUBLIC TRANSPORT in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\STPTR00O.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=PUBLIC TRANSPORT PRNFILE="{SCENARIO_DIR}\output\STPTR00Q2.PRN" MSG='pnr-bus stop to stop file'
FILEI ROUTEI[1] = "{SCENARIO_DIR}\output\TPATHMD3_{Alt}{year}.RTE"
FILEI NETI = "{SCENARIO_DIR}\output\OPauto.NET"
FILEO REPORTO = "{SCENARIO_DIR}\output\STPTR00R2.PRN"
FILEO STOP2STOPO = "{SCENARIO_DIR}\output\ST2STOP3_{alt}{year}.DBF",
     ACCUMULATE=firstlast, MODES=21,23, N={NODEMIN}-99999

PARAMETERS NOROUTEERRS=99999999, NOROUTEMSGS=99999999,USERCLASSES=1,HDWAYPERIOD=2,
           TRIPSIJ[1]=10

ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\STMAT00D.S"
; 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\STMAT00C.PRN" MSG='Write out station zone, parking cost and terminal time to matrix'
FILEI LOOKUPI[1] = "{SCENARIO_DIR}\output\STATION_{alt}{year}.DAT"
FILEI MATI[1] = "{SCENARIO_DIR}\output\ST2STOP3_{alt}{year}.DBF",
 PATTERN=IJM:V FIELDS=I,J,0,FROMNODE
FILEO MATO[1] = "{SCENARIO_DIR}\output\ST2STOP_bus_{alt}{year}.MAT",
 MO=1,21-24,
 NAME=FromStation_pnrb,StationTAZ_pnrb,OPParkCost_pnrb,termtimpnr,termtimknr
    
PAR ZONES={ZONESA} zonemsg=100

; STATION PARKING COST INTO A LOOKUP TABLE
;station, statnumber, spaces,pnrterm,knrterm,nearestzone(distance),nearestzone(statdata input),ampnrcost,mdpnrcost

LOOKUP LOOKUPI=1, 
  NAME=STATIONS,
  LOOKUP[1]=2, RESULT=3,; STATION ZONE
  LOOKUP[2]=2, RESULT=7,
  LOOKUP[3]=2,result=8,
  LOOKUP[4]=2,result=9,; Off-Peak Period Pakring Cost
  FAIL=0

  MW[1]=MI.1.1

JLOOP
 ;FIRST FIGURE OUT THE STATION EQUIVALENT FOR EACH CELL, 0 IF NO MATCH
 ;NEXT, ASSIGN THE STATION EQUIVALENT FOR EACH CELL TO A WORK MATRIX
  STATZONE1=STATIONS(1,MW[1][J],0)
  PARKINGCOST1=STATIONS(2,MW[1][J],0)
  termtimpnr=stations(3,MW[1][j],0)
  termtimknr=stations(4,MW[1][j],0)

  MW[21][J]=STATZONE1
  MW[22][J]=PARKINGCOST1
  MW[23][j]=termtimpnr
  MW[24][j]=termtimknr

  ; If no station for a zone, write 0 as the station
  IF(MW[21][J] == 0) MW[1][J]=0

ENDJLOOP

ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\STMAT00G.S"
; 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\STMAT00E.PRN" MSG='STATION TO STATION MATRIX'
FILEO MATO[1] = "{SCENARIO_DIR}\output\ST2ST_{alt}{year}.MAT",
 MO=1-8,NAME=PKStationTAZ_pnrb,PKParkCost_pnrb,termtimpnr,termtimknr,             
              OPStationTAZ_pnrb,OPParkCost_pnrb,termtimpnr,termtimknr
              

FILEI MATI[3] = "{SCENARIO_DIR}\output\ST2STOP_bus_{alt}{year}.MAT"
FILEI MATI[1] = "{SCENARIO_DIR}\output\ST2STPK_bus_{alt}{year}.MAT"

zonemsg=100

; pull out only station zone number
FILLMW MW[1] =MI.1.2   ; pk pnr-transit    Station TAZ
FILLMW MW[2] =MI.1.3   ;                   Parking Cost
FILLMW MW[3] =MI.1.4   ;                  PNR Terminal Time
FILLMW MW[4] =MI.1.5   ;                   KNR Terminal Time
FILLMW MW[5] =MI.3.2   ; op pnr-transit
FILLMW MW[6] =MI.3.3
FILLMW MW[7] =MI.3.4
FILLMW MW[8] =MI.3.5

ENDRUN


; PILOT Script



EndDistributeMULTISTEP
; End of PILOT Script

; PILOT Script



*echo Date: %date% >"{SCENARIO_DIR}\output\ModelRun_{alt}{year}.prn"
*echo Time: %time% >>"{SCENARIO_DIR}\output\ModelRun_{alt}{year}.prn"
*echo FSUMTS Model Run - {SCENARIO_FULLNAME}>>"{SCENARIO_DIR}\output\ModelRun_{alt}{year}.prn"
*echo Input Directory {SCENARIO_DIR}\input >>"{SCENARIO_DIR}\output\ModelRun_{alt}{year}.prn"
*echo ======================================================================================>>"{SCENARIO_DIR}\output\ModelRun_{alt}{year}.prn"

*del "{SCENARIO_DIR}\output\ModeDebug.TXT"
*del "{SCENARIO_DIR}\output\ModeSum.TXT"
*del "{SCENARIO_DIR}\output\CalibSum.TXT"
*del "{SCENARIO_DIR}\output\modeshares.csv"
*del "{SCENARIO_DIR}\output\NEW_MCCONSTS.CSV"
*del "{SCENARIO_DIR}\output\CBDSHARES.CSV"
; End of PILOT Script

; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\MCMAT00C.S"

; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=MATRIX MSG='store time and date'
FILEI RECI = "{SCENARIO_DIR}\output\ModelRun_{alt}{year}.prn"

zones={ZONESA}

s1=strpos('Date:',reci)
s2=strpos('Time:',reci)

; get the date and time
if (s1 > 0)
 rundate=substr(reci,s1,80)
 log prefix=date var=rundate
endif
if (s2 > 0) 
 runtime=substr(reci,s2,80)
 log prefix=time var=runtime
endif

ENDRUN


RUN PGM="C:\Program Files\Citilabs\Cube\TRCOPY.bat" PARAMETERS='"{CATALOG_DIR}\parameters\MC_CONSTANTS.DBF" "{SCENARIO_DIR}\output\MC_CONSTANTS.DBF" '
ENDRUN

RUN PGM="C:\Program Files\Citilabs\Cube\TRCOPY.bat" PARAMETERS='"{CATALOG_DIR}\parameters\TRN_COEFFICIENTS.DBF" "{SCENARIO_DIR}\output\TRN_COEFFICIENTS.DBF" '
ENDRUN

; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\MCPREP.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=MATRIX PRNFILE="X:\Projects\CRTPA\Model\C\APPLICATIONS\MCMAT00B.PRN" MSG='Auto ownership %age by TAZ'
;ZONE=1-5,mpo=6-10,county=11-15
FILEI LOOKUPI[2] = "{SCENARIO_DIR}\output\DUWEIGHTS.DBF"
FILEI LOOKUPI[1] = "{SCENARIO_DIR}\output\GRATES_MC.DBF"
FILEO RECO[1] = "{SCENARIO_DIR}\output\A1DECK.dbf",
fields=ZONE(4.0),ltp(4.0),stp(4.0),wksh0(4.0),wksh1(4.0),wksh2(4.0),nwsh0(4.0),nwsh1(4.0),nwsh2(4.0)

FILEI ZDATI[1] = "{SCENARIO_DIR}\input\ZONEDATA_{year}{alt}.DBF"

PARAMETERS ZONEMSG=100 ZONES={ZONESA}

ARRAY DRANGE=16, SFDUM1=5, SFDUM2=5, SFDUM3=5, MFDUM1=5, MFDUM2=5, MFDUM3=5, HMDUM=5, SFTOT=3, MFTOT=3, TERM=5

_seli={SelOrigin}

LOOKUP LOOKUPI=1,
       NAME=RATES1,
         LOOKUP[1]=COUNTER, RESULT=PPDU,
         LOOKUP[2]=COUNTER, RESULT=APDU,
         LOOKUP[3]=COUNTER, RESULT=DUTYPE,
         LOOKUP[4]=COUNTER, RESULT=HBWPR,
         LOOKUP[5]=COUNTER, RESULT=HBSHPR,
         LOOKUP[6]=COUNTER, RESULT=HBSRPR,
         LOOKUP[7]=COUNTER, RESULT=HBOPR,
       FAIL[1]=0,FAIL[2]=0,FAIL[3]=0
; example of use: v=RATES(7,25)
; look for 25 in the COUNTER field and returns the HBOPR value

LOOKUP LOOKUPI=2,
       NAME=DSHARE,
         LOOKUP[1]=SIZERANGE, RESULT=PCT1PER,
         LOOKUP[2]=SIZERANGE, RESULT=PCT2PER,
         LOOKUP[3]=SIZERANGE, RESULT=PCT3PER,
         LOOKUP[4]=SIZERANGE, RESULT=PCT4PER,
         LOOKUP[5]=SIZERANGE, RESULT=PCT5PER,
       FAIL[1]=0,FAIL[2]=0,FAIL[3]=0
; example of use: v=DUWEIGHT(5,25)
; look for 25 in the SIZERANGE field and returns the HH5 value

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


;LOOKUP LOOKUPI=3,
;       NAME=TYPE,
;         LOOKUP[4]=1, RESULT=5,         ; Two-digit area type
;         LOOKUP[5]=1, RESULT=6,         ; County
;         LOOKUP[6]=1, RESULT=7,         ; MPO
;       FAIL[1]=0,FAIL[2]=0,FAIL[3]=0


;LOOKUP LOOKUPI=4,
;       NAME=RATES2,
;         LOOKUP[1]=COUNTER, RESULT=PPDU,
;         LOOKUP[2]=COUNTER, RESULT=APDU,
;         LOOKUP[3]=COUNTER, RESULT=DUTYPE,
;         LOOKUP[4]=COUNTER, RESULT=HBWPR,
;         LOOKUP[5]=COUNTER, RESULT=HBSHPR,
;         LOOKUP[6]=COUNTER, RESULT=HBSRPR,
;         LOOKUP[7]=COUNTER, RESULT=HBOPR,
;       FAIL[1]=0,FAIL[2]=0,FAIL[3]=0

;LOOKUP LOOKUPI=5,
;       NAME=RATES3,
;         LOOKUP[1]=COUNTER, RESULT=PPDU,
;         LOOKUP[2]=COUNTER, RESULT=APDU,
;         LOOKUP[3]=COUNTER, RESULT=DUTYPE,
;         LOOKUP[4]=COUNTER, RESULT=HBWPR,
;         LOOKUP[5]=COUNTER, RESULT=HBSHPR,
;         LOOKUP[6]=COUNTER, RESULT=HBSRPR,
;         LOOKUP[7]=COUNTER, RESULT=HBOPR,
;       FAIL[1]=0,FAIL[2]=0,FAIL[3]=0

; Initialize DRANGE (DUWEIGHT categories) & TERM (terminal times by areatype)
DRANGE[1]=1.125
DRANGE[2]=1.375
DRANGE[3]=1.625
DRANGE[4]=1.875
DRANGE[5]=2.125
DRANGE[6]=2.375
DRANGE[7]=2.625
DRANGE[8]=2.875
DRANGE[9]=3.125
DRANGE[10]=3.375
DRANGE[11]=3.625
DRANGE[12]=3.875
DRANGE[13]=4.125
DRANGE[14]=4.375
DRANGE[15]=4.625
DRANGE[16]=5.995

; Initialize arrays & temporary variables here
LOOP x=1,5
  SFDUM1[x]=0, SFDUM2[x]=0, SFDUM3[x]=0
  MFDUM1[x]=0, MFDUM2[x]=0, MFDUM3[x]=0
ENDLOOP

LOOP x=1,3
  SFTOT[x]=0, MFTOT[x]=0
ENDLOOP

_xdum=0, _SFPPDU=0, _MFPPDU=0, _HMPPDU=0
_tmp=0, _HMTRIP=0, _HMTOT=0
_SFTRIP1=0, _SFTRIP2=0, _SFTRIP3=0
_MFTRIP1=0, _MFTRIP2=0, _MFTRIP3=0
_WKA0=0, _WKA1=0, _WKA2=0, _WKTOT=0
_NWA0=0, _NWA1=0, _NWA2=0, _NWTOT=0
_WKSHA0=0, _WKSHA1=0, _WKSHA2=0, _WKSHT=0
_NWSHA0=0, _NWSHA1=0, _NWSHA2=0, _NWSHT=0
_at=0, _area=0
_SFIDX = 1, _MFIDX=1, _HMIDX=1

; Calculations
_xdum = ZI.1.SFDU * (1.0 - 0.01*ZI.1.SF_PCTVNP)
IF (_xdum > 0) _SFPPDU = 1.0 * ZI.1.SFPOP/_xdum
_xdum = ZI.1.MFDU * (1.0 - 0.01*ZI.1.MF_PCTVNP)
IF (_xdum > 0) _MFPPDU = 1.0 * ZI.1.MFPOP/_xdum
_xdum = ZI.1.HMDU * (0.01*ZI.1.HMOCC)
IF (_xdum > 0) _HMPPDU = 1.0 * ZI.1.HMPOP/_xdum

; Debug
IF (I==_seli) LIST="2077 SFDU  ",ZI.1.SFDU(7.0)," SF_PCTVAC1 ",ZI.1.SF_SEAS(4.0)," SF_PCTVAC2 ",ZI.1.SF_PCTVAC(4.0)," SFPOP ",ZI.1.SFPOP
IF (I==_seli) LIST="2077 MFDU  ",ZI.1.MFDU(7.0)," MF_PCTVAC1 ",ZI.1.MF_SEAS(4.0)," MF_PCTVAC2 ",ZI.1.MF_PCTVAC(4.0)," MFPOP ",ZI.1.MFPOP
IF (I==_seli) LIST="2077 HMDU  ",ZI.1.HMDU(7.0)," HMOCC  ",ZI.1.HMOCC(4.0), " HMPOP  ",ZI.1.HMPOP(4.0)
IF (I==_seli) LIST="2077 SFPPDU",_SFPPDU(7.2)," MFPPDU ",_MFPPDU(7.2)," HMPPDU ",_HMPPDU(7.2)

; Find correct DUWEIGHT SIZERANGE
LOOP x=1,16
  IF (_SFPPDU > DRANGE[x]) _SFIDX=x+1
  IF (_MFPPDU > DRANGE[x]) _MFIDX=x+1
  IF (_HMPPDU > DRANGE[x]) _HMIDX=x+1
ENDLOOP

; Debug
IF (I==_seli) LIST="2077 SFIDX",_SFIDX(3.0)," MFIDX ",_MFIDX(3.0)," HMIDX ",_HMIDX(3.0)

; Main computations
LOOP x=1,5
  HMDUM[x]=1.0*ZI.1.HMDU*0.01*ZI.1.HMOCC*DSHARE(x,_HMIDX)
  SFDUM1[x]=0.01*ZI.1.SFDU*(1.0-0.01*SF_PCTVAC)*ZI.1.SF_0AUTO*DSHARE(x,_SFIDX)
  SFDUM2[x]=0.01*ZI.1.SFDU*(1.0-0.01*SF_PCTVAC)*ZI.1.SF_1AUTO*DSHARE(x,_SFIDX)
  SFDUM3[x]=0.01*ZI.1.SFDU*(1.0-0.01*SF_PCTVAC)*(ZI.1.SF_2AUTO)*DSHARE(x,_SFIDX)
  MFDUM1[x]=0.01*ZI.1.MFDU*(1.0-0.01*MF_PCTVAC)*ZI.1.MF_0AUTO*DSHARE(x,_MFIDX)
  MFDUM2[x]=0.01*ZI.1.MFDU*(1.0-0.01*MF_PCTVAC)*ZI.1.MF_1AUTO*DSHARE(x,_MFIDX)
  MFDUM3[x]=0.01*ZI.1.MFDU*(1.0-0.01*MF_PCTVAC)*(ZI.1.MF_2AUTO)*DSHARE(x,_MFIDX)
ENDLOOP

; Identify Rate District (see page 18 of TM2-CFRPM4.0 Calibration & Validation Report)

;_mpo = TYPE(5,I)
;_gendist = 1
;IF (_mpo==1)          ; Region 1
;  _gendist = 1
;ELSEIF (_mpo==2)      ; Region 2
;  _gendist = 2
;ELSEIF (_mpo==3)   ; Region 3
;  _gendist = 3
;ENDIF

; Debug
IF (I==_seli) LIST="2077 MPO",_MPO(3.0)," GENDIST ",_GENDIST(3.0)

LOOP L=1,4

 _HMTOT=0
 SFTOT[1]=0, SFTOT[2]=0, SFTOT[3]=0
 MFTOT[1]=0, MFTOT[2]=0, MFTOT[3]=0

LOOP x=1,5
 _tmp1 = 9 * (x-1) + 6
 _tmp2 = 9 * (x-1) + 1
 _tmp3 = 9 * (x-1) + 4
 _tmp4 = 9 * (x-1) + 7
 _tmp5 = 9 * (x-1) + 2
 _tmp6 = 9 * (x-1) + 5
 _tmp7 = 9 * (x-1) + 8

 ;  IF (_gendist==1)
 _HMTRIP  = RATES1(L+3,_tmp1)*HMDUM[x]
 _SFTRIP1 = RATES1(L+3,_tmp2)*SFDUM1[x]
 _SFTRIP2 = RATES1(L+3,_tmp3)*SFDUM2[x]
 _SFTRIP3 = RATES1(L+3,_tmp4)*SFDUM3[x]
 _MFTRIP1 = RATES1(L+3,_tmp5)*MFDUM1[x]
 _MFTRIP2 = RATES1(L+3,_tmp6)*MFDUM2[x]
 _MFTRIP3 = RATES1(L+3,_tmp7)*MFDUM3[x]

;    ELSEIF (_gendist==2)
;      _HMTRIP  = RATES2(L+3,_tmp1)*HMDUM[x]
;      _SFTRIP1 = RATES2(L+3,_tmp2)*SFDUM1[x]
;      _SFTRIP2 = RATES2(L+3,_tmp3)*SFDUM2[x]
;      _SFTRIP3 = RATES2(L+3,_tmp4)*SFDUM3[x]
;      _MFTRIP1 = RATES2(L+3,_tmp5)*MFDUM1[x]
;      _MFTRIP2 = RATES2(L+3,_tmp6)*MFDUM2[x]
;      _MFTRIP3 = RATES2(L+3,_tmp7)*MFDUM3[x]
;    ELSEIF (_gendist==3)
;      _HMTRIP  = RATES3(L+3,_tmp1)*HMDUM[x]
;      _SFTRIP1 = RATES3(L+3,_tmp2)*SFDUM1[x]
;      _SFTRIP2 = RATES3(L+3,_tmp3)*SFDUM2[x]
;      _SFTRIP3 = RATES3(L+3,_tmp4)*SFDUM3[x]
;      _MFTRIP1 = RATES3(L+3,_tmp5)*MFDUM1[x]
;      _MFTRIP2 = RATES3(L+3,_tmp6)*MFDUM2[x]
;      _MFTRIP3 = RATES3(L+3,_tmp7)*MFDUM3[x]
; ENDIF

    _HMTOT = _HMTOT + _HMTRIP
    SFTOT[1] = SFTOT[1] + _SFTRIP1
    SFTOT[2] = SFTOT[2] + _SFTRIP2
    SFTOT[3] = SFTOT[3] + _SFTRIP3
    MFTOT[1] = MFTOT[1] + _MFTRIP1
    MFTOT[2] = MFTOT[2] + _MFTRIP2
    MFTOT[3] = MFTOT[3] + _MFTRIP3
  ENDLOOP
  IF (L==1)
    _WKA0 = SFTOT[1] + MFTOT[1]
    _WKA1 = SFTOT[2] + MFTOT[2] + _HMTOT
    _WKA2 = SFTOT[3] + MFTOT[3]
    _WKTOT = _WKA0 + _WKA1 + _WKA2
  ELSE
    _NWA0 = _NWA0 + SFTOT[1] + MFTOT[1]
    _NWA1 = _NWA1 + SFTOT[2] + MFTOT[2] + _HMTOT
    _NWA2 = _NWA2 + SFTOT[3] + MFTOT[3]
    _NWTOT = _NWA0 + _NWA1 + _NWA2
  ENDIF

  IF (I==_seli) LIST="2077 SFTOT L=",L(1.0)," ",SFTOT[1](7.1),SFTOT[2](7.1),SFTOT[3](7.1)
  IF (I==_seli) LIST="2077 MFTOT L=",L(1.0)," ",MFTOT[1](7.1),MFTOT[2](7.1),MFTOT[3](7.1)
  IF (I==_seli) LIST="2077 HMTOT L=",L(1.0)," ",_HMTOT(7.1)

ENDLOOP

; Debug
IF (I==_seli) LIST="2077 WKA0 ",_WKA0(7.1)," WKA1 ",_WKA1(7.1)," WKA2 ",_WKA2(7.2)," WKTOT ",_WKTOT(7.1)
IF (I==_seli) LIST="2077 NWA0 ",_NWA0(7.1)," NWA1 ",_NWA1(7.1)," NWA2 ",_NWA2(7.2)," NWTOT ",_NWTOT(7.1)

IF (_WKTOT > 0)
  _WKSHA0=ROUND(100.0*_WKA0/_WKTOT)
  _WKSHA1=ROUND(100.0*_WKA1/_WKTOT)
  _WKSHA2=ROUND(100.0*_WKA2/_WKTOT)
  _WKSHT=ROUND(_WKSHA0 + _WKSHA1 + _WKSHA2)
  IF (_WKSHT <> 100)
    IF (_WKSHA0 > _WKSHA1)
      IF (_WKSHA0 > _WKSHA2)
        _WKSHA0 = _WKSHA0 + 100 - _WKSHT
      ELSE
        _WKSHA2 = _WKSHA2 + 100 - _WKSHT
      ENDIF
    ELSE
      IF (_WKSHA1 > _WKSHA2)
        _WKSHA1 = _WKSHA1 + 100 - _WKSHT
      ELSE
        _WKSHA2 = _WKSHA2 + 100 - _WKSHT
      ENDIF
    ENDIF
  ENDIF
ENDIF

IF (_NWTOT > 0)
  _NWSHA0=ROUND(100.0*_NWA0/_NWTOT)
  _NWSHA1=ROUND(100.0*_NWA1/_NWTOT)
  _NWSHA2=ROUND(100.0*_NWA2/_NWTOT)
  _NWSHT=ROUND(_NWSHA0 + _NWSHA1 + _NWSHA2)
  IF (_NWSHT <> 100)
    IF (_NWSHA0 > _NWSHA1)
      IF (_NWSHA0 > _NWSHA2)
        _NWSHA0 = _NWSHA0 + 100 - _NWSHT
      ELSE
        _NWSHA2 = _NWSHA2 + 100 - _NWSHT
      ENDIF
    ELSE
      IF (_NWSHA1 > _NWSHA2)
        _NWSHA1 = _NWSHA1 + 100 - _NWSHT
      ELSE
        _NWSHA2 = _NWSHA2 + 100 - _NWSHT
      ENDIF
    ENDIF
  ENDIF
ENDIF

ZONE=i
ltp=zi.1.LONGPARK
stp=zi.1.SHORTPARK
wksh0=_WKSHA0
wksh1=_WKSHA1
wksh2=_WKSHA2
nwsh0=_NWSHA0
nwsh1=_NWSHA1
nwsh2=_NWSHA2
write reco=1

;**************************************************************
;END POTENTIAL SCRIPT ADJUSTMENT
;**************************************************************

ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\MCMAT00B.S"
; 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\MCMAT00A3.PRN" MSG='Preparation for mode choice model'
FILEI ZDATI[2] = "{SCENARIO_DIR}\output\ZONESAT.DAT",
Z=6-10,A1=16-20
FILEI ZDATI[1] = "{SCENARIO_DIR}\input\ZONEDATA_{year}{alt}.DBF"
FILEO RECO[1] = "{SCENARIO_DIR}\output\TAZDATA_{alt}{year}.DBF",
   FIELDS=ZONE,DESCR,SFDU,SF_PCTVNP,SF_PCTVAC,SFPOP,SF_0AUTO,SF_1AUTO,SF_2AUTO,SF3CAR,MFDU,MF_PCTVNP,
           MF_PCTVAC,MFPOP,MF_0AUTO,MF_1AUTO,MF_2AUTO,MF3CAR,HMDU,HMOCC,HMPOP,EMPMFG,EMPIND,EMPCOM,EMPSVC,EMPTOT,SCHENR,SHORTPARK,LONGPARK,
           PCWPRDPK,PCWATTPK,PCWPRDOP,PCWATTOP,AREA_TYPE,CBD_DUMMY,EXU_DUMMY,TERMTIME,PERCAUTO0,PERCAUTO1,PERCAUTO2

PAR ZONES={ZONESI,Spin-INTEGER,"Maximum internal zone number","3700",5,10000} ZONEMSG=100

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

RO.ZONE=ZI.1.ZONE

RO.SFDU=ZI.1.SFDU
RO.SF_PCTVNP=ZI.1.SF_PCTVNP
RO.SF_PCTVAC=ZI.1.SF_PCTVAC
RO.SFPOP=ZI.1.SFPOP
RO.SF_0AUTO=ZI.1.SF_0AUTO
RO.SF_1AUTO=ZI.1.SF_1AUTO
RO.SF_2AUTO=ZI.1.SF_2AUTO

RO.MFDU=ZI.1.MFDU
RO.MF_PCTVNP=ZI.1.MF_PCTVNP
RO.MF_PCTVAC=ZI.1.MF_PCTVAC
RO.MFPOP=ZI.1.MFPOP
RO.MF_0AUTO=ZI.1.MF_0AUTO
RO.MF_1AUTO=ZI.1.MF_1AUTO
RO.MF_2AUTO=ZI.1.MF_2AUTO

RO.HMDU=ZI.1.HMDU
RO.HMOCC=ZI.1.HMOCC
RO.HMPOP=ZI.1.HMPOP

RO.SHORTPARK=ZI.1.SHORTPARK
RO.LONGPARK=ZI.1.LONGPARK

RO.AREA_TYPE=ZI.2.A1
_atype=ROUND(ZI.2.A1/10)
if (_atype=1) RO.TERMTIME={TERM10}
if (_atype=2) RO.TERMTIME={TERM20}
if (_atype=3) RO.TERMTIME={TERM30}
if (_atype=4) RO.TERMTIME={TERM40}
if (_atype=5) RO.TERMTIME={TERM50}

CBD_DUMMY=0
EXU_DUMMY=0
; define CBD zones for mode chocie
if (ZI.2.A1>10 & ZI.2.A1<20) CBD_DUMMY=1
; define EXURBAN zones for mode choice
if (ZI.2.A1>40 & ZI.2.A1<50) EXU_DUMMY=1

WRITE RECO=1

;**************************************************************
;END POTENTIAL SCRIPT ADJUSTMENT
;**************************************************************

ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\MCMAT00P.S"
; 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\MCMAT00A2.PRN" MSG='Calculate HOV time savings (to be used in mode choice model)'
FILEO MATO[3] = "{SCENARIO_DIR}\OUTPUT\RHSKIM.MAT",
mo=41-49,name=STOLL,SDISTANCE,STIME,STIME2,HTOLL,HDISTANCE,HTIME,HTIME2,TERMTIME
FILEO MATO[2] = "{SCENARIO_DIR}\OUTPUT\FFSKIM.MAT",
mo=31-39,name=STOLL,SDISTANCE,STIME,STIME2,HTOLL,HDISTANCE,HTIME,HTIME2,TERMTIME
FILEI MATI[3] = "{SCENARIO_DIR}\Output\FREESKIM_{ALT}{YEAR}.MAT"
FILEI MATI[1] = "{SCENARIO_DIR}\Output\CONGSKIM_{ALT}{YEAR}.MAT"

FILEO MATO[1] = "{SCENARIO_DIR}\output\HOVSavings_{alt}{year}.MAT",
 MO=21-22,DEC=2*2,NAME=HOVsaveOP,HOVsavePK

PAR ZONEMSG=100

;DistributeINTRASTEP ProcessID="FSUTMSDist", ProcessList=1-3
FILLMW MW[1] =MI.1.9   ; note that time2 is used here (time2 contains both time and time-equivalent of toll)
FILLMW MW[2] =MI.1.5
FILLMW MW[11]=MI.3.9
FILLMW MW[12]=MI.3.5
FILLMW MW[31]=MI.3.1,2,3,5,6,7,8,9,4
FILLMW MW[41]=MI.1.1,2,3,5,6,7,8,9,4


MW[22]=MW[1] - MW[2]   ; hov time savings during off-peak hours
MW[21]=MW[11] - MW[12] ; hov time savings during peak hours

JLOOP
 IF (MW[21] > 0) MW[21]=0.0   ; if less than HOVMIN zero out the savings
 IF (MW[22] > 0) MW[22]=0.0
 IF (MW[21] < {HOVMIN}) MW[21]=0.0   ; if less than HOVMIN zero out the savings
 IF (MW[22] < {HOVMIN}) MW[22]=0.0
ENDJLOOP
ENDRUN


; PILOT Script


*del "{SCENARIO_DIR}\output\MODESHARES.CSV"
*del "{SCENARIO_DIR}\output\CBDSHARES.CSV"
; End of PILOT Script

LOOP PURPOSE = 1, 3, 1

; PILOT Script


IF (PURPOSE=1) ; HBW purpose - requres peak skims
PERIOD='PK'
PURP='HBW'
PURPNO=2
SKIMFILE='RHSKIM'
STATPRKCOST='STPKCS1'
OCC3={oc3vhbw}
RUNDATE='@DATE.RUNDATE@'
RUNTIME=@TIME.RUNTIME@
PRK='LONGPARK'
STATION_TABLE='2,3,4'
isNHB=';'
noNHB=' '

copy, FILE = "{SCENARIO_DIR}\OUTPUT\HBWHEAD.VAR"
UBTRNCOEF=-0.0250
UBAUTOCOEF=-0.0250
UBPURPOSE='HBW'
UBTOD='ALL'
UBALTNAME='{SCENARIO_FULLNAME}'
endcopy

ELSEIF (PURPOSE=2) ; HBO purpose - requres off-peak skims
PERIOD='OP'
PURP='HBO'
PURPNO=3
SKIMFILE='FFSKIM'
STATPRKCOST='STPKCS2'
OCC3={oc3vhbnw}
PRK='SHORTPARK'
STATION_TABLE='6,7,8'
isNHB=';'
noNHB=' '

copy, FILE = "{SCENARIO_DIR}\OUTPUT\HBOHEAD.VAR"
UBTRNCOEF=-0.0125
UBAUTOCOEF=-0.0125
UBPURPOSE='HBO'
UBTOD='ALL'
UBALTNAME='{SCENARIO_FULLNAME}'
endcopy

ELSEIF (PURPOSE=3) ; NHB purpose - requres off-peak skims
PERIOD='OP'
PURP='NHB'
PURPNO=4
SKIMFILE='FFSKIM'
STATPRKCOST='STPKCS2'
OCC3={oc3vnhb}
PRK='SHORTPARK'
STATION_TABLE='6,7,8'
isNHB=' '
noNHB=';'

copy, FILE = "{SCENARIO_DIR}\OUTPUT\NHBHEAD.VAR"
UBTRNCOEF=-0.0250
UBAUTOCOEF=-0.0250
UBPURPOSE='NHB'
UBTOD='ALL'
UBALTNAME='{SCENARIO_FULLNAME}'
endcopy

ENDIF
; End of PILOT Script

; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\MCMAT00A.S"
; 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\MCMAT00D.PRN" MSG='Utilities and XCHOICE'
FILEI MATI[13] = "{Scenario_Dir}\OUTPUT\PSNTRIPS_{ALT}{YEAR}.MAT"
FILEO MATO[16] = "{SCENARIO_DIR}\output\@PURP@Utility.mat",
mo=401-406,421-426,441-446
FILEI ZDATI[3] = "{SCENARIO_DIR}\output\A1DECK.dbf"
FILEO MATO[15] = "{SCENARIO_DIR}\output\@PURP@Trip_2CAR.MAT",
mo=541-546
FILEO MATO[14] = "{SCENARIO_DIR}\output\@PURP@Trip_1CAR.MAT",
mo=521-526
FILEO MATO[13] = "{SCENARIO_DIR}\output\@PURP@Trip_0CAR.MAT",
mo=501-506
FILEI MATI[12] = "{SCENARIO_DIR}\output\ST2ST_{alt}{year}.MAT"
FILEI ZDATI[2] = "{SCENARIO_DIR}\output\STATDATA_{alt}{year}.DBF"
FILEO MATO[12] = "{SCENARIO_DIR}\output\farexfer_tmp.mat",
MO=211,213,215,220,222,224,DEC=6*2,NAME=farewb,farepb,farekb,xferwb,xferpb,xferkb
FILEO MATO[11] = "{SCENARIO_DIR}\output\expautoutil_tmp.mat",
MO=56-58,36-38,DEC=6*D,NAME=EXPA_0CAR,EXPA_1CAR,EXPA_2CAR,SPLITCMP_0CAR,SPLITCMP_1CAR,SPLITCMP_2CAR
FILEO MATO[10] = "{SCENARIO_DIR}\output\@PURP@Trip.MAT",
MO=501-506,521-526,541-546,251-254,261-269,DEC=31*S
FILEO PRINTO[2] = "{SCENARIO_DIR}\output\ModeSum.TXT",
append=t
FILEO PRINTO[1] = "{SCENARIO_DIR}\output\ModeDebug.TXT",
append=t

FILEI ZDATI[1] = "{SCENARIO_DIR}\output\TAZDATA_{alt}{year}.DBF"
FILEI LOOKUPI[2] = "{SCENARIO_DIR}\output\TRN_COEFFICIENTS.DBF"
FILEI LOOKUPI[1] = "{SCENARIO_DIR}\output\MC_CONSTANTS.DBF"

FILEI MATI[11] = "{SCENARIO_DIR}\output\HOVSavings_{alt}{year}.MAT"
           ; Table 1 - HOV time savings for peak period
           ; Table 2 - HOV time savings for off-peak period
FILEI MATI[4] = "{SCENARIO_DIR}\output\TSKIM@PERIOD@3.{Alt}{year}"
FILEI MATI[2] = "{SCENARIO_DIR}\output\TSKIM@PERIOD@1.{Alt}{year}"
           ; Tables 1-6: 1-WalkTime, 2-AutoTime, 3-XferTime, 4-BusTime, 5-PRJBusTime, 6-CircTime
           ; Tables 7-10: 7-RailTime, 8-CommuterRailTime, 9-OtherModeTime, 10-ProjectModeTime
           ; Tables 11-15: 11-NumXfers, 12-InitialWaitTime, 13-XferWaitTime, 14-Fare, 15-Total time
FILEI MATI[1] = "{SCENARIO_DIR}\output\@SKIMFILE@.MAT"
           ; Tables 1-4 for SOV: 1-Toll, 2-Distance, 3-Time, 4-Weighted Time
           ; Tables 5-8 for HOV: 5-Toll, 6-Distance, 7-Time, 8-Weighted Time
           ; Table 9 is terminal time

zonemsg=100
ARRAY PARK={ZONESA}

DistributeINTRASTEP ProcessID="FSUTMSDist", ProcessList=1-2

;Constants
LOOKUP, NAME=CONSTANTS, LOOKUP[1]=1, RESULT=@PURPNO@, INTERPOLATE=N, , LIST=Y, LOOKUPI=1
;K=CONSTANT
if (i=FirstZone)
 K_DA_AUTO0=CONSTANTS(1,1),         K_DA_AUTO1=CONSTANTS(1,13),        K_DA_AUTO2=CONSTANTS(1,25)
 K_SR1PASS_AUTO0=CONSTANTS(1,2),    K_SR1PASS_AUTO1=CONSTANTS(1,14),   K_SR1PASS_AUTO2=CONSTANTS(1,26)
 K_SR2PASS_AUTO0=CONSTANTS(1,3),    K_SR2PASS_AUTO1=CONSTANTS(1,15),   K_SR2PASS_AUTO2=CONSTANTS(1,27)
 K_WALKBUS_AUTO0=CONSTANTS(1,4),    K_WALKBUS_AUTO1=CONSTANTS(1,16),   K_WALKBUS_AUTO2=CONSTANTS(1,28)
 K_WALKPRJ_AUTO0=CONSTANTS(1,5),    K_WALKPRJ_AUTO1=CONSTANTS(1,17),   K_WALKPRJ_AUTO2=CONSTANTS(1,29)
 K_PNRBUS_AUTO0=CONSTANTS(1,6),     K_PNRBUS_AUTO1=CONSTANTS(1,18),    K_PNRBUS_AUTO2=CONSTANTS(1,30)
 K_PNRPRJ_AUTO0=CONSTANTS(1,7),     K_PNRPRJ_AUTO1=CONSTANTS(1,19),    K_PNRPRJ_AUTO2=CONSTANTS(1,31)
 K_KNRBUS_AUTO0=CONSTANTS(1,8),     K_KNRBUS_AUTO1=CONSTANTS(1,20),    K_KNRBUS_AUTO2=CONSTANTS(1,32)
 K_KNRPRJ_AUTO0=CONSTANTS(1,9),     K_KNRPRJ_AUTO1=CONSTANTS(1,21),    K_KNRPRJ_AUTO2=CONSTANTS(1,33)

endif

;Coefficients
LOOKUP, NAME=COEFF, LOOKUP[1]=1, RESULT=@PURPNO@, INTERPOLATE=N, LIST=Y, LOOKUPI=2

if (i=FirstZone)
; Transit Coefficients
 COEFF_IVTT   = COEFF(1,1)
 COEFF_OVT    = COEFF(1,3)
 COEFF_COST   = COEFF(1,4)
 COEFF_AAT    = COEFF(1,5)
 COEFF_XFER   = COEFF(1,6)
 COEFF_DCBD   = COEFF(1,7)

 COEFF_DEXUP  = COEFF(1,8)
 COEFF_DEXUA  = COEFF(1,9)
 NC_TRNAC     = COEFF(1,10)
 NC_TRN       = COEFF(1,11)
 NC_AUTO      = COEFF(1,12)
 NC_AUTOSR    = COEFF(1,13)

 COEFF_DCBD_WALK   = COEFF(1,15)
 COEFF_DCBD_PNR    = COEFF(1,16)
 COEFF_DCBD_KNR    = COEFF(1,17)

; Nesting Coefficients
 NC_DriveAlone = NC_AUTO
 NC_SharedRide = NC_AUTO * NC_AUTOSR
 NC_WALKBUS =  NC_TRNAC
 NC_PNRBus =  NC_TRNAC
 NC_KNRBus =  NC_TRNAC
endif


FILLMW MW[1]=MI.1.1,2,3,4,5,6,7,8 ;,9        ; highway skims
FILLMW MW[11]=MI.11.HOVsave@PERIOD@          ; HOVsavePK for peak period (HBW) and HOVsaveOP for off-peak period (HBNW and NHB)
FILLMW MW[291]=MI.12.@STATION_TABLE@         ; 7 tables - stations zones for pnr-bus,knr-bus,cbdknr-bus,fringe,pnr-prj,knr-prj,cbdknr-prj paths
FILLMW MW[21]=MI.2.1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 ;tskim1
FILLMW MW[61]=MI.4.1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 ;tskims3
FILLMW MW[211]=MI.2.14
FILLMW MW[213]=MI.4.14
FILLMW MW[215]=MI.4.14
FILLMW MW[220]=MI.2.11
FILLMW MW[222]=MI.4.11
FILLMW MW[224]=MI.4.11

FILLMW MW[251]=MI.13.@PURP@    ; person trip table

if (I=1)
; DEBUG MODE CHOICE
 IF ({DebugMC}>0)
   print list='MODE CHOICE TRACE @PURP@-@PERIOD@','\n\n',printo=1
   print list='-- @DATE.RUNDATE@     ',printo=1
   print list='-- @TIME.RUNTIME@     ','\n\n',printo=1
   print list='NERPM \n\nSelected Interchange for Tracing:    ',{SelOrigin}(4.0),'-',{SelDest}(4.0),'\n\n',printo=1
   print list='PURPOSE -           @PURP@  ',printo=1
   print list='SKIMS/PERIOD        @PERIOD@',printo=1
   print list='\nCoefficients                ',printo=1
   print list='       IVTT                 ',COEFF_IVTT(7.4),printo=1
   print list='       OVT                  ',COEFF_OVT(7.4),printo=1
   print list='       AAT                  ',COEFF_AAT(7.4),printo=1
   print list='       XFER                 ',COEFF_XFER(7.4),printo=1
   print list='       COST                 ',COEFF_COST(7.4),printo=1
   PRINT LIST='       DUM_CBD_WALK         ',COEFF_DCBD_WALK(7.4),printo=1
   PRINT LIST='       DUM_CBD_PNR          ',COEFF_DCBD_PNR(7.4),printo=1
   PRINT LIST='       DUM_CBD_KNR          ',COEFF_DCBD_KNR(7.4),printo=1
   print list='\n\nNesting Coeffcient      ',printo=1
   print list='        NC_TRNAC            ',NC_TRNAC(7.4),printo=1
   print list='        NC_TRN              ',NC_TRN(7.4),printo=1
   print list='        NC_AUTOSR           ',NC_AUTOSR(7.4),printo=1
   print list='        NC_AUTO             ',NC_AUTO(7.4),printo=1

   print list='\n\nConstants               ',printo=1
   print list='        Drive alone (0 car) ',K_da_auto0(8.4),printo=1
   print list='        HOV2 (0 car)        ',K_sr1pass_auto0(8.4),printo=1
   print list='        HOV2 (1 car)        ',K_sr1pass_auto1(8.4),printo=1
   print list='        HOV2 (2 car)        ',K_sr1pass_auto2(8.4),printo=1
   print list='        HOV3+ (0 car)       ',K_sr2pass_auto0(8.4),printo=1
   print list='        HOV3+ (1 car)       ',K_sr2pass_auto1(8.4),printo=1
   print list='        HOV3+ (2 car)       ',K_sr2pass_auto2(8.4),printo=1
   print list='        Walk Bus (0 car)    ',K_walkbus_auto0(8.4),printo=1
   print list='        Walk Bus (1 car)    ',K_walkbus_auto1(8.4),printo=1
   print list='        Walk Bus (2 car)    ',K_walkbus_auto2(8.4),printo=1
   print list='        PNR Bus (0 car)     ',K_PNRBUS_auto0(8.4),printo=1
   print list='        PNR Bus (1 car)     ',K_PNRBUS_auto1(8.4),printo=1
   print list='        PNR Bus (2 car)     ',K_PNRBUS_auto2(8.4),printo=1
   print list='        KNR Bus (0 car)     ',K_KNRBUS_auto0(8.4),printo=1
   print list='        KNR Bus (1 car)     ',K_KNRBUS_auto1(8.4),printo=1
   print list='        KNR Bus (2 car)     ',K_KNRBUS_auto2(8.4),printo=1

   print list='\n\nParameters used in disutility calculations:', printo=1
   print list='Highway Operating Cost (cents/mi)   ',{hwyopcost}(5.3),printo=1
   print list='CTOLL Multiplier (toll to time)     ',{CTOLL}(5.3),printo=1
   print list='Value of ZAPZERO                    ',{ZAPZERO}(5.3),printo=1
   print list='Auto Occupancy 3+ (HBW)             ',{oc3vhbw}(5.3),printo=1
   print list='Auto Occupancy 3+ (HBNW)            ',{oc3vhbnw}(5.3),printo=1
   print list='Inflation factor - Tolls            ',{InflationToll}(5.3),printo=1
   print list='Inflation factor - Auto Op Cost     ',{InflationAOC}(5.3),printo=1
   print list='Inflation factor - Parking Cost     ',{InflationParkCost}(5.3),printo=1
   print list='Inflation factor - Transit Fare     ',{InflationFare}(5.3),printo=1
   print list='Auto Access Auto Occupancy Factor   ',{OCCPNRAccess}(5.3),printo=1
   print list='Times are in minutes. Costs are in cents.        ',printo=1
 endif

 ; Echo to Mode Choice summary file
 PRINT LIST="\f+++++ MODE XCHOICE SUMMARY +++++\n" PRINTO=2
 PRINT LIST='-- @DATE.RUNDATE@     ','-- @TIME.RUNTIME@     ','\n',PRINTO=2
 PRINT LIST="{SCENARIO_FULLNAME}" PRINTO=2
 PRINT LIST="{SCENARIO_SHORTNAME}\n" PRINTO=2
 PRINT LIST='PURPOSE -           @PURP@  ',printo=2
 PRINT LIST='SKIMS/PERIOD        @PERIOD@',printo=2
 PRINT LIST='\nCoefficients                ',printo=2
 PRINT LIST='       IVTT                 ',COEFF_IVTT(7.4),printo=2
 PRINT LIST='       OVT                  ',COEFF_OVT(7.4),printo=2
 PRINT LIST='       AAT                  ',COEFF_AAT(7.4),printo=2
 PRINT LIST='       XFER                 ',COEFF_XFER(7.4),printo=2
 PRINT LIST='       COST                 ',COEFF_COST(7.4),printo=2
 PRINT LIST='       DUM_CBD_WALK         ',COEFF_DCBD_WALK(7.4),printo=2
 PRINT LIST='       DUM_CBD_PNR          ',COEFF_DCBD_PNR(7.4),printo=2
 PRINT LIST='       DUM_CBD_KNR          ',COEFF_DCBD_KNR(7.4),printo=2
 PRINT LIST='\n\nNesting Coeffcient      ',printo=2
 PRINT LIST='        NC_TRNAC            ',NC_TRNAC(7.4),printo=2
 PRINT LIST='        NC_TRN              ',NC_TRN(7.4),printo=2
 PRINT LIST='        NC_AUTOSR           ',NC_AUTOSR(7.4),printo=2
 PRINT LIST='        NC_AUTO             ',NC_AUTO(7.4),printo=2
 PRINT LIST='\n\nConstants               ',printo=2
 PRINT LIST='        Drive alone (0 car) ',K_da_auto0(8.4),printo=2
 PRINT LIST='        Drive alone (1 car) ',K_da_auto1(8.4),printo=2
 PRINT LIST='        Drive alone (2 car) ',K_da_auto2(8.4),printo=2
 PRINT LIST='        HOV2 (0 car)        ',K_sr1pass_auto0(8.4),printo=2
 PRINT LIST='        HOV2 (1 car)        ',K_sr1pass_auto1(8.4),printo=2
 PRINT LIST='        HOV2 (2 car)        ',K_sr1pass_auto2(8.4),printo=2
 PRINT LIST='        HOV3+ (0 car)       ',K_sr2pass_auto0(8.4),printo=2
 PRINT LIST='        HOV3+ (1 car)       ',K_sr2pass_auto1(8.4),printo=2
 PRINT LIST='        HOV3+ (2 car)       ',K_sr2pass_auto2(8.4),printo=2
 PRINT LIST='        Walk Bus (0 car)    ',K_walkbus_auto0(8.4),printo=2
 PRINT LIST='        Walk Bus (1 car)    ',K_walkbus_auto1(8.4),printo=2
 PRINT LIST='        Walk Bus (2 car)    ',K_walkbus_auto2(8.4),printo=2
 PRINT LIST='        PNR Bus (0 car)     ',K_PNRBUS_auto0(8.4),printo=2
 PRINT LIST='        PNR Bus (1 car)     ',K_PNRBUS_auto1(8.4),printo=2
 PRINT LIST='        PNR Bus (2 car)     ',K_PNRBUS_auto2(8.4),printo=2
 PRINT LIST='        KNR Bus (0 car)     ',K_KNRBUS_auto0(8.4),printo=2
 PRINT LIST='        KNR Bus (1 car)     ',K_KNRBUS_auto1(8.4),printo=2
 PRINT LIST='        KNR Bus (2 car)     ',K_KNRBUS_auto2(8.4),printo=2

 PRINT LIST='\n\nParameters used in disutility calculations:', printo=2
 PRINT LIST='Highway Operating Cost (cents/mi)   ',{hwyopcost}(5.3),printo=2
 PRINT LIST='CTOLL Multiplier (toll to time)     ',{CTOLL}(5.3),printo=2
 PRINT LIST='Value of ZAPZERO                    ',{ZAPZERO}(5.3),printo=2
 PRINT LIST='Auto Occupancy 3+ (HBNW)            ',{oc3vhbnw}(5.3),printo=2
 PRINT LIST='Auto Occupancy 3+ (NHB)             ',{oc3vnhb}(5.3),printo=2
 PRINT LIST='Inflation factor - Tolls            ',{InflationToll}(5.3),printo=2
 PRINT LIST='Inflation factor - Auto Op Cost     ',{InflationAOC}(5.3),printo=2
 PRINT LIST='Inflation factor - Parking Cost     ',{InflationParkCost}(5.3),printo=2
 PRINT LIST='Inflation factor - Transit Fare     ',{InflationFare}(5.3),printo=2
 PRINT LIST='Auto Access Auto Occupancy Factor   ',{OCCPNRAccess}(5.3),printo=2
 PRINT LIST='Times reflected in minutes.         ',printo=2
 PRINT LIST='Costs are in cents.                 ',printo=2

endif

; for debugging
;JLOOP
; if ({DebugMC}=1)
 ;  if (I>{SELORIGIN}) EXIT
  ;  if (I<>{SELDEST}) BREAK
  ;endif
;ENDJLOOP

; Divide person trip table into different markets
; Zero car HHs
; for NHB purpose, there is no market segmentation and hence put all trips into zer-car household trip table
if('@PURP@'='HBW')
 MW[252]=MW[251] * ZI.3.wksh0[I]*0.01
else
 MW[252]=MW[251] * ZI.3.nwsh0[I]*0.01
endif

; One car HHs

IF ('@PURP@'='NHB') MW[252]=MW[251]
IF('@PURP@'='HBW')
 MW[253]=MW[251] * ZI.3.wksh1[I]*0.01
ELSE
 MW[253]=MW[251] * ZI.3.nwsh1[I]*0.01
ENDIF

; Two+ car HHs
IF ('@PURP@'='NHB') MW[253]=0
IF('@PURP@'='HBW')
 MW[254]=MW[251] * ZI.3.wksh2[I]*0.01
ELSE
 MW[254]=MW[251] * ZI.3.nwsh2[I]*0.01
ENDIF

IF ('@PURP@'='NHB') MW[254]=0

; ===================================================================================
; @PURP@ (@PERIOD@) TRIP PURPOSE
; ===================================================================================

; (1) Terminal Time (both at production-end and attraction-end)
; (2) Auto run time
; (3) highway operating cost
; (4) Toll (assumed in $)
; (5) Parking cost
; (6) CBD/EXURBAN dummy variables
; (7) Transit fare
; (8) Out-of vehicle time (walk/transfer time/wait)

; ******************************** UTILITY CALCULATIONS ************************************
  ;   DRIVE ALONE ELEMENTS OF UTILITY ARE:
      MW[301]=COEFF_OVT * (ZI.1.TERMTIME[I] + ZI.1.TERMTIME[J]) +                                       ; Terminal time
              COEFF_IVTT * (MW[4] - ({InflationToll} * (MW[1] * {CTOLL} * 60))) +                       ; IVTT
              COEFF_IVTT * {InflationToll} * (MW[1] * {CTOLL} * 60) +                                   ; Toll converted to equivalent minutes
@noNHB@       COEFF_COST * ((({InflationParkCost} * ZI.1.@PRK@[J]) / 1.0) / 2.0) +                      ; Auto parking cost
@isNHB@       COEFF_COST * ((({InflationParkCost} * ZI.1.@PRK@[J]) / 1.0) / 1.0) +                      ; Auto parking cost (NHB)
              COEFF_COST * (({InflationAOC} * MW[2] * {hwyopcost}) / 1.0) +                             ; Auto operating cost
@isNHB@       COEFF_DCBD * (ZI.1.CBD_DUMMY[I] + ZI.1.CBD_DUMMY[J]) +                                    ; CBD dummy (NHB)
@noNHB@       COEFF_DCBD * ZI.1.CBD_DUMMY[J] +                                                          ; CBD dummy
              COEFF_DEXUP * ZI.1.EXU_DUMMY[I] +                                                         ; Exurban production dummy
              COEFF_DEXUA * ZI.1.EXU_DUMMY[J]                                                           ; Exurban attraction dummy

  ;   SHARED RIDE PERSONS/SHARE RIDE - ONE PASSENGER ELEMENTS OF UTILITY ARE:
      MW[302]=COEFF_OVT * (ZI.1.TERMTIME[I] + ZI.1.TERMTIME[J]) +                                       ; Terminal time
              COEFF_IVTT * (MW[4] - ({InflationToll} * (MW[5] * {CTOLL} * 60))) +                       ; IVTT
              COEFF_IVTT * ({InflationToll} * (MW[5] * {CTOLL} * 60) / 2.0) -                           ; Toll converted to equivalent minutes
              COEFF_IVTT * (MAX (MW[11], 0)) +                                                          ; HOV time savings
@noNHB@       COEFF_COST * ((({InflationParkCost} * ZI.1.@PRK@[J]) / 2.0) / 2.0) +                      ; Auto parking cost
@isNHB@       COEFF_COST * ((({InflationParkCost} * ZI.1.@PRK@[J]) / 2.0) / 1.0) +                      ; Auto parking cost (NHB)
              COEFF_COST * (({InflationAOC} * MW[2] * {hwyopcost}) / 2.0) +                             ; Auto operating cost
@isNHB@       COEFF_DCBD * (ZI.1.CBD_DUMMY[I] + ZI.1.CBD_DUMMY[J]) +                                    ; CBD dummy (NHB)
@noNHB@       COEFF_DCBD * ZI.1.CBD_DUMMY[J] +                                                          ; CBD dummy
              COEFF_DEXUP * ZI.1.EXU_DUMMY[I] +                                                         ; Exurban production dummy
              COEFF_DEXUA * ZI.1.EXU_DUMMY[J]                                                           ; Exurban attraction dummy

  ;   SHARED RIDE - 2+ PASSENGER ELEMENTS OF UTILITY ARE:
      MW[303]=COEFF_OVT * (ZI.1.TERMTIME[I] + ZI.1.TERMTIME[J]) +                                       ; Terminal time
              COEFF_IVTT * (MW[4] - ({InflationToll} * (MW[5] * {CTOLL} * 60))) +                       ; IVTT
              COEFF_IVTT * ({InflationToll} * (MW[5] * {CTOLL} * 60) / @OCC3@) -                        ; Toll converted to equivalent minutes
              COEFF_IVTT * (MAX (MW[11], 0)) +                                                          ; HOV time savings
@noNHB@       COEFF_COST * ((({InflationParkCost} * ZI.1.@PRK@[J]) / @OCC3@) / 2.0) +                   ; Auto parking cost
@isNHB@       COEFF_COST * ((({InflationParkCost} * ZI.1.@PRK@[J]) / @OCC3@) / 1.0) +                   ; Auto parking cost (NHB)
              COEFF_COST * (({InflationAOC} * MW[2] * {hwyopcost}) / @OCC3@) +                          ; Auto operating cost
@isNHB@       COEFF_DCBD * (ZI.1.CBD_DUMMY[I] + ZI.1.CBD_DUMMY[J]) +                                    ; CBD dummy (NHB)
@noNHB@       COEFF_DCBD * ZI.1.CBD_DUMMY[J] +                                                          ; CBD dummy
              COEFF_DEXUP * ZI.1.EXU_DUMMY[I] +                                                         ; Exurban production dummy
              COEFF_DEXUA * ZI.1.EXU_DUMMY[J]                                                           ; Exurban attraction dummy

 ;   WALK ACCESS - BUS ELEMENTS OF UTILITY ARE:
      MW[304]=COEFF_OVT * (MW[21] + MW[23]) +                                                   ; Walk & transfer time
              COEFF_OVT * (MW[32] + MW[33]) +                                                   ; Initial & transfer wait
              COEFF_IVTT * (MW[24] + MW[25] + MW[26] + MW[27] + MW[28] + MW[29] + MW[30]) +     ; IVTT
              COEFF_XFER * (MW[31]) +                                                           ; Number of transfers
              COEFF_COST * {InflationFare} * (MW[34]) +                                         ; Transit fare
@isNHB@       COEFF_DCBD_WALK * (ZI.1.CBD_DUMMY[I] + ZI.1.CBD_DUMMY[J]) +                       ; CBD dummy (NHB)
@noNHB@       COEFF_DCBD_WALK * ZI.1.CBD_DUMMY[J] +                                             ; CBD dummy
              COEFF_DEXUP * ZI.1.EXU_DUMMY[I] +                                                 ; Exurban production dummy
              COEFF_DEXUA * ZI.1.EXU_DUMMY[J]                                                   ; Exurban attraction dummy

 ;   PNR ACCESS - BUS ELEMENTS OF UTILITY ARE:
      MW[305]=COEFF_OVT * (MW[61] + MW[63]) +                                                   ; Walk & transfer time
              COEFF_OVT * (MW[72] + MW[73]) +                                                   ; Initial & transfer wait
              COEFF_IVTT * (MW[62]) +                                                           ; Auto access time
              COEFF_IVTT * (MW[64] + MW[65] + MW[66] + MW[67] + MW[68] + MW[69] + MW[70]) +     ; IVTT
              COEFF_XFER * (MW[71]) +                                                           ; Number of transfers
              COEFF_COST * {InflationFare} * (MW[74]) +                                         ; Transit fare
@isNHB@       COEFF_DCBD_PNR * (ZI.1.CBD_DUMMY[I] + ZI.1.CBD_DUMMY[J]) +                        ; CBD dummy (NHB)
@noNHB@       COEFF_DCBD_PNR * ZI.1.CBD_DUMMY[J] +                                              ; CBD dummy
              COEFF_DEXUP * ZI.1.EXU_DUMMY[I] +                                                 ; Exurban production dummy
              COEFF_DEXUA * ZI.1.EXU_DUMMY[J]                                                   ; Exurban attraction dummy

  ;   KNR ACCESS - BUS ELEMENTS OF UTILITY ARE:
      MW[306]=COEFF_OVT * (MW[61] + MW[63]) +                                                 ; Walk & transfer time
              COEFF_OVT * (MW[72] + MW[73]) +                                                 ; Initial & transfer wait
              COEFF_IVTT * (MW[62]-({InflationFare}*(COEFF(1,4)/COEFF(1,1))*MW[291])+(COEFF(1,3)/COEFF(1,1))*(-mw[292]+mw[293])) +                                 ; Auto access time
              COEFF_IVTT * (MW[64] + MW[65] + MW[66] + MW[67] + MW[68] + MW[69] + MW[70]) +    ; IVTT
              COEFF_XFER * (MW[71]) +                                                          ; Number of transfers
              COEFF_COST * {InflationFare} * (MW[74]) +                                        ; Transit fare
@isNHB@       COEFF_DCBD_KNR * (ZI.1.CBD_DUMMY[I] + ZI.1.CBD_DUMMY[J]) +                        ; CBD dummy (NHB)
@noNHB@       COEFF_DCBD_KNR * ZI.1.CBD_DUMMY[J] +                                              ; CBD dummy
              COEFF_DEXUP * ZI.1.EXU_DUMMY[I] +                                                 ; Exurban production dummy
              COEFF_DEXUA * ZI.1.EXU_DUMMY[J]                                                   ; Exurban attraction dummy

;******************************** END UTILITY CALCULATIONS ************************************

      JLOOP
; For PNR paths, determine the parking zone. This is used to get the station parking cost for NHB paths, as
;               we need to add in the other half of station parking costs.
; Check if the IVT times on the transit path exist (this avoids having a jloop in the utility calculations)
        IF ((MW[24]+MW[25]+MW[26]+MW[27]+MW[28]+MW[29]+MW[30])==0) MW[304]=-9999.99                                                                       ; walk-bus path

        IF ((MW[64] + MW[65] + MW[66] + MW[67] + MW[68] + MW[69] + MW[70])==0| mw[62]==0)                                                                                        ; pnr-bus path
          MW[305]=-9999.99
        ELSE
@isNHB@   MW[305]=MW[305] + COEFF_COST * ((({InflationFare}*mw[292])/{OCCPNRAccess})/2.0)                             ; add in other half of NHB PNR parking cost
        ENDIF

        IF ((MW[64] + MW[65] + MW[66] + MW[67] + MW[68] + MW[69] + MW[70])==0| mw[62]==0) MW[306]=-9999.99                                                                     ; knr bus path

       ; Minimum distance criteria on paths
        IF (MW[2] < {MinDistWalkAcc})
                MW[304]=-9999.99
        ENDIF
        IF (MW[2] < {MinDistAutoAcc})
                MW[305]=-9999.99
                MW[306]=-9999.99
        ENDIF
; NOTE: no min distance criteria for fringe parking
; For PNR paths, determine the parking zone. This is used to get the station parking cost for NHB paths, as
;               we need to add in the other half of station parking costs.
; debug report
       IF(({DebugMC} > 0) && (I={SelOrigin}) && (J={SelDest}))

IF('@PURP@'='HBW')
print list='Percent 0 car household at Production zone    ',ZI.3.wksh0[I],printo=1
print list='Percent 1 car household at Production zone    ',ZI.3.wksh1[I],printo=1
print list='Percent 2 car household at Production zone    ',ZI.3.wksh2[I],printo=1

ELSE
print list='Percent 0 car household at Production zone    ',ZI.3.nwsh0[I],printo=1
print list='Percent 1 car household at Production zone    ',ZI.3.nwsh1[I],printo=1
print list='Percent 2 car household at Production zone    ',ZI.3.nwsh2[I],printo=1
ENDIF


ENDIF
ENDJLOOP

;******************************** FINAL UTILITY CALCULATIONS ************************************
  ;   COMPOSITE UTILITY for drive alone
      MW[401]=(MW[301]+K_DA_AUTO0)/NC_DriveAlone
      MW[421]=(MW[301]+K_DA_AUTO1)/NC_DriveAlone
      MW[441]=(MW[301]+K_DA_AUTO2)/NC_DriveAlone
  ;   COMPOSITE UTILITY for shared ride 2
      MW[402]=(MW[302]+K_SR1PASS_AUTO0)/NC_SharedRide
      MW[422]=(MW[302]+K_SR1PASS_AUTO1)/NC_SharedRide
      MW[442]=(MW[302]+K_SR1PASS_AUTO2)/NC_SharedRide
  ;   COMPOSITE UTILITY for shared ride 2+
      MW[403]=(MW[303]+K_SR2PASS_AUTO0)/NC_SharedRide
      MW[423]=(MW[303]+K_SR2PASS_AUTO1)/NC_SharedRide
      MW[443]=(MW[303]+K_SR2PASS_AUTO2)/NC_SharedRide
  ;   COMPOSITE UTILITY for walk to bus
      MW[404]=((MW[304]+K_WALKBUS_AUTO0)/NC_WALKBUS )
      MW[424]=((MW[304]+K_WALKBUS_AUTO1)/NC_WALKBUS)
      MW[444]=((MW[304]+K_WALKBUS_AUTO2)/NC_WALKBUS)
  ;   COMPOSITE UTILITY for PNR to bus
      MW[405]=((MW[305]+K_PNRBUS_AUTO0)/NC_PNRBus )
      MW[425]=((MW[305]+K_PNRBUS_AUTO1)/NC_PNRBus)
      MW[445]=((MW[305]+K_PNRBUS_AUTO2)/NC_PNRBus )
  ;   COMPOSITE UTILITY for KNR to bus
      MW[406]=((MW[306]+K_KNRBUS_AUTO0)/NC_KNRBus )
      MW[426]=((MW[306]+K_KNRBUS_AUTO1)/NC_KNRBus )
      MW[446]=((MW[306]+K_KNRBUS_AUTO2)/NC_KNRBus )

; use ZAPZERO here to zero out the drive alone and PNR access trips for zero-car households
      if ( ({ZAPZERO} = 1) && (('@PURP@'=='HBW') || ('@PURP@'=='HBNW')) )
        MW[401] = -9999.99     ; drive alone for 0car households
        MW[405] = -9999.99     ; PNR-bus trips for 0car households
     endif

 JLOOP
  if (({DebugMC} > 0) && (I={SelOrigin}) && (J={SelDest}))
   print list='\n\n********************************************************************************************', printo=1
;   print list=' Access Type: ',ACC(1.0),'. ',ACC_NAME, printo=1
   print list='********************************************************************************************','\n' printo=1
   print list='Value of CBD dummy at attraction-end (1 or 0)                     ',ZI.1.CBD_DUMMY[J],printo=1
   print list='Value of EXURBAN dummy at production-end (1 or 0)                 ',ZI.1.EXU_DUMMY[I],printo=1
   print list='Value of EXURBAN dummy at attraction-end (1 or 0)                 ',ZI.1.EXU_DUMMY[J],printo=1

   print list='\n\n\nElements used in Drive Alone disutility calculations: ***************************', printo=1
   print list='In-Vehicle time                                                   ',MW[3][J],printo=1
   print list='Out of Vehicle time (Terminal time at production-end)             ',ZI.1.TERMTIME[I],printo=1
   print list='Out of Vehicle time (Terminal time at attraction-end)             ',ZI.1.TERMTIME[J],printo=1
   print list='Parking Cost                                                      ',ZI.1.@PRK@[J],printo=1
   print list='Highway Distance (in miles)                                       ',MW[2][J],printo=1
   print list='Highway Toll (in $)                                               ',MW[1][J],printo=1
   print list='\nDrive alone disutility                                          ',MW[301][J](12.4),printo=1
   print list='\nDrive alone composite disutility (0 car)                        ',MW[401][J](12.4),printo=1
   print list='Drive alone composite disutility (1 car)                        ',MW[421][J](12.4),printo=1
   print list='Drive alone composite disutility (2 car)                        ',MW[441][J](12.4),printo=1
   print list='\nExponentiated drive alone composite disutility (0 car)        ',exp(MW[401][J])(14.12),printo=1
   print list='Exponentiated drive alone composite disutility (1 car)        ',exp(MW[421][J])(14.12),printo=1
   print list='Exponentiated drive alone composite disutility (2 car)        ',exp(MW[441][J])(14.12),printo=1

   print list='\n\n\nElements used in Shared Ride 2 disutility calculations: ***************************', printo=1
   print list='In-Vehicle time                                                   ',MW[3][J],printo=1
   print list='In-Vehicle time savings by using HOV lanes                        ',MAX((MW[7][J]-MW[3][J]), 0),printo=1
   print list='Out of Vehicle time (Terminal time at production-end)             ',ZI.1.TERMTIME[I],printo=1
   print list='Out of Vehicle time (Terminal time at attraction-end)             ',ZI.1.TERMTIME[J],printo=1
   print list='Parking Cost                                                      ',ZI.1.@PRK@[J],printo=1
   print list='Highway Distance (in miles)                                       ',MW[6][J],printo=1
   print list='Highway Toll (in $)                                               ',MW[1][J],printo=1
   print list='\nShared ride 2 disutility                                        ',MW[302][J](12.4),printo=1
   print list='\nShared ride 2 composite disutility (0 car)                      ',MW[402][J](12.4),printo=1
   print list='Shared ride 2 composite disutility (1 car)                      ',MW[422][J](12.4),printo=1
   print list='Shared ride 2 composite disutility (2 car)                      ',MW[442][J](12.4),printo=1
   print list='\nExponentiated shared ride composite disutility (0 car)        ',exp(MW[402][J])(14.12),printo=1
   print list='Exponentiated shared ride 2 composite disutility (1 car)      ',exp(MW[422][J])(14.12),printo=1
   print list='Exponentiated shared ride 2 composite disutility (2 car)      ',exp(MW[442][J])(14.12),printo=1

   print list='\n\n\nElements used in Shared Ride 2+ disutility calculations: ***************************', printo=1
   print list='In-Vehicle time                                                   ',MW[3][J],printo=1
   print list='In-Vehicle time savings by using HOV lanes                        ',MAX((MW[7][J]-MW[3][J]), 0),printo=1
   print list='Out of Vehicle time (Terminal time at production-end)             ',ZI.1.TERMTIME[I],printo=1
   print list='Out of Vehicle time (Terminal time at attraction-end)             ',ZI.1.TERMTIME[J],printo=1
   print list='Parking Cost                                                      ',ZI.1.@PRK@[J],printo=1
   print list='Highway Distance (in miles)                                       ',MW[6][J],printo=1
   print list='Occupancy rate for 2+ car market                                  ',@OCC3@,printo=1
   print list='Highway Toll (in $)                                               ',MW[1][J],printo=1
   print list='\nShared ride 2+ disutility                                       ',MW[303][J](12.4),printo=1
   print list='\nShared ride 2+ composite disutility (0 car)                     ',MW[403][J](12.4),printo=1
   print list='Shared ride 2+ composite disutility (1 car)                     ',MW[423][J](12.4),printo=1
   print list='Shared ride 2+ composite disutility (2 car)                     ',MW[443][J](12.4),printo=1
   print list='\nExponentiated shared ride 2+ composite disutility (0 car)     ',exp(MW[403][J])(14.12),printo=1
   print list='Exponentiated shared ride 2+ composite disutility (1 car)     ',exp(MW[423][J])(14.12),printo=1
   print list='Exponentiated shared ride 2+ composite disutility (2 car)     ',exp(MW[443][J])(14.12),printo=1

   print list='\n\n\nElements used in Walk Bus disutility calculations: ***************************', printo=1
   print list='In-Vehicle time (Bus)                                             ',MW[24][J],printo=1
   print list='In-Vehicle time (PRJ Bus)                                         ',MW[25][J],printo=1
   print list='In-Vehicle time (Circulator)                                      ',MW[26][J],printo=1
   print list='In-Vehicle time (Rail)                                            ',(MW[27][J]+MW[28][J]),printo=1
   print list='In-Vehicle time (Project Mode)                                    ',MW[30][J],printo=1
   print list='Out of Vehicle time (Walk)                                        ',MW[21][J],printo=1
   print list='Out of Vehicle time (Transfer Walk)                               ',MW[23][J],printo=1
   print list='Out of Vehicle time (IWAIT)                                       ',MW[32][J],printo=1
   print list='Out of Vehicle time (XWAIT)                                       ',MW[33][J],printo=1
   print list='Number of transfers                                               ',MW[31][J],printo=1
   print list='Transit Fare (in cents)                                           ',MW[34][J],printo=1
   print list='\nWalk Bus disutility                                             ',MW[304][J](12.4),printo=1
;   print list='Walk access dummy (added to the utility)                          ',walk_acc_dum,printo=1
   print list='\nWalk Bus composite disutility (0 car)                           ',MW[404][J](12.4),printo=1
   print list='Walk Bus composite disutility (1 car)                           ',MW[424][J](12.4),printo=1
   print list='Walk Bus composite disutility (2+ car)                          ',MW[444][J](12.4),printo=1
   print list='\nExponentiated walk bus composite disutility (0 car)           ',exp(MW[404][J])(14.12),printo=1
   print list='Exponentiated walk bus composite disutility (1 car)           ',exp(MW[424][J])(14.12),printo=1
   print list='Exponentiated walk bus composite disutility (2 car)           ',exp(MW[444][J])(14.12),printo=1

   print list='\n\n\nElements used in PNR Bus disutility calculations: ***************************', printo=1
   print list='In-Vehicle time (Bus)                                             ',MW[64][J],printo=1
   print list='In-Vehicle time (PRJ Bus)                                         ',MW[65][J],printo=1
   print list='In-Vehicle time (Circulator)                                      ',MW[66][J],printo=1
   print list='In-Vehicle time (Rail)                                            ',(MW[67][J]+MW[68][J]),printo=1
   print list='In-Vehicle time (Project Mode)                                    ',MW[70][J],printo=1
   print list='Out of Vehicle time (Walk)                                        ',MW[61][J],printo=1
   print list='Out of Vehicle time (Auto access time in IVT min - weighted)      ',MW[62][J],printo=1
   print list='Out of Vehicle time (Transfer Walk)                               ',MW[63][J],printo=1
   print list='Out of Vehicle time (IWAIT)                                       ',MW[72][J],printo=1
   print list='Out of Vehicle time (XWAIT)                                       ',MW[73][J],printo=1
   print list='Number of transfers                                               ',MW[71][J],printo=1
   print list='Transit Fare (in cents)                                           ',MW[74][J],printo=1
   print list='\nPNR Bus disutility                                              ',MW[305][J](12.4),printo=1
;   print list='Auto access dummy (added to the utility)                          ',auto_acc_dum,printo=1
   print list='\nPNR Bus composite disutility (0 car)                            ',MW[405][J](12.4),printo=1
   print list='PNR Bus composite disutility (1 car)                            ',MW[425][J](12.4),printo=1
   print list='PNR Bus composite disutility (2 car)                            ',MW[445][J](12.4),printo=1
   print list='\nExponentiated PNR Bus composite disutility (0 car)            ',exp(MW[405][J])(14.12),printo=1
   print list='Exponentiated PNR Bus composite disutility (1 car)            ',exp(MW[425][J])(14.12),printo=1
   print list='Exponentiated PNR Bus composite disutility (2 car)            ',exp(MW[445][J])(14.12),printo=1

   print list='\n\n\nElements used in KNR Bus disutility calculations: ***************************', printo=1
   print list='In-Vehicle time (Bus)                                             ',MW[64][J],printo=1
   print list='In-Vehicle time (Circulator)                                      ',MW[66][J],printo=1
   print list='In-Vehicle time (Rail)                                            ',(MW[67][J]+MW[108][J]),printo=1
   print list='In-Vehicle time (Project Mode)                                    ',MW[70][J],printo=1
   print list='Out of Vehicle time (Walk)                                        ',MW[61][J],printo=1
   print list='Out of Vehicle time (Auto access time in IVT min)                 ',MW[62][J],printo=1
   print list='Out of Vehicle time (Transfer Walk)                               ',MW[63][J],printo=1
   print list='Out of Vehicle time (IWAIT)                                       ',MW[62][J],printo=1
   print list='Out of Vehicle time (XWAIT)                                       ',MW[73][J],printo=1
   print list='Transit Fare (in cents)                                           ',MW[74][J],printo=1
   print list='\nKNR Bus disutility                                              ',MW[306][J](12.4),printo=1
;   print list='Auto access dummy (added to the utility)                          ',auto_acc_dum,printo=1
   print list='\nKNR Bus composite disutility (0 car)                            ',MW[406][J](12.4),printo=1
   print list='KNR Bus composite disutility (1 car)                            ',MW[426][J](12.4),printo=1
   print list='KNR Bus composite disutility (2 car)                            ',MW[446][J](12.4),printo=1
   print list='\nExponentiated KNR Bus composite disutility (0 car)            ',exp(MW[406][J])(14.12),printo=1
   print list='Exponentiated KNR Bus composite disutility (1 car)            ',exp(MW[426][J])(14.12),printo=1
   print list='Exponentiated KNR Bus composite disutility (2 car)            ',exp(MW[446][J])(14.12),printo=1
   print list="PNR parkcost                                                  ",(COEFF(1,4)/COEFF(1,1))*MW[292]
   print list="termtime difference betn PNR and KNR                          ",(COEFF(1,3)/COEFF(1,1))*(-mw[293]+mw[294])
   print list="see this",(MW[62]-({InflationFare}*(COEFF(1,4)/COEFF(1,1))*MW[292])+(COEFF(1,3)/COEFF(1,1))*(-mw[293]+mw[294]))

  endif

 ENDJLOOP

; ############################# XCHOICE SETUP ###################################

; AUTO0
      DMD=252
      XCHOICE ALTERNATIVES=da,hov2,hov3,walkbus,pnrbus,knrbus,
      UTILITIESMW=401,402,403,404,405,406,
      DEMANDMW=DMD,
      ODEMANDMW=501,502,503,504,505,506,
      STARTMW=900,
;     Model Structure
;     Top level nest
      SPLIT=Total NC_AUTO Auto NC_TRN Transit,
;     Auto nest
      SPLIT=Auto 1.0 da NC_AUTOSR hov, SPLITCOMP=36,
;     HOV nest
      SPLIT=hov 1.0 hov2 1.0 hov3,
;     Transit nest
      SPLIT= Transit 1.0 Walkbus 1.0 PNRbus 1.0 KNRbus

; AUTO1
      DMD=253
      XCHOICE ALTERNATIVES=da,hov2,hov3,walkbus,pnrbus,knrbus,
      UTILITIESMW=421,422,423,424,425,426,
      DEMANDMW=DMD,
      ODEMANDMW=521,522,523,524,525,526,
      STARTMW=900,
;     Model Structure
;     Top level nest
      SPLIT=Total NC_AUTO Auto NC_TRN Transit,
;     Auto nest
      SPLIT=Auto 1.0 da NC_AUTOSR hov, SPLITCOMP=37,
;     HOV nest
      SPLIT=hov 1.0 hov2 1.0 hov3,
;     Transit nest
      SPLIT= Transit 1.0 Walkbus 1.0 PNRbus 1.0 KNRbus


; AUTO2
      DMD=254
      XCHOICE ALTERNATIVES=da,hov2,hov3,walkbus,pnrbus,knrbus,
      UTILITIESMW=441,442,443,444,445,446,
      DEMANDMW=DMD,
      ODEMANDMW=541,542,543,544,545,546,
      STARTMW=900,
;     Model Structure
;     Top level nest
      SPLIT=Total NC_AUTO Auto NC_TRN Transit,
;     Auto nest
      SPLIT=Auto 1.0 da NC_AUTOSR hov, SPLITCOMP=38,
;     HOV nest
      SPLIT=hov 1.0 hov2 1.0 hov3,
;     Transit nest
      SPLIT= Transit 1.0 Walkbus 1.0 PNRbus 1.0 KNRbus

; user benefit table - exponentiated auto utility
      MW[56]=exp(NC_AUTOSR * MW[36])
      MW[57]=exp(NC_AUTOSR * MW[37])
      MW[58]=exp(NC_AUTOSR * MW[38])

; ############################################ END XCHOICE #################################

 ; now some debuging
   LOOP MARKET=1,3
    if (MARKET=1) MARKET_NAME='Zero Car HHs     '
    if (MARKET=2) MARKET_NAME='One Car HHs      '
    if (MARKET=3) MARKET_NAME='Two+ Car HHs     '

    _cnt=(MARKET-1)*20
    _cnt1=260+(MARKET-1)*3
    M1=501+_cnt,M2=502+_cnt,M3=503+_cnt,M4=504+_cnt,M5=505+_cnt,M6=506+_cnt;,M7=507+_cnt,M8=508+_cnt,M9=509+_cnt;,M12=512+_cnt

    IF ({DebugMC}>0)
     JLOOP
      if ((I={SelOrigin}) && (J={SelDest}))

; ################### SHARES (HAND CALCULATION - check it against XCHOICE RESULTS) ###########################################
       _konn = 0.0000000000000001

       print list='\n\nMARKET:           ',MARKET_NAME,printo=1
       print list='***************************************************',printo=1

       ; transit nest

       if ((exp(MW[404+_cnt][J])+exp(MW[405+_cnt][J])+exp(MW[406+_cnt][J]))>_konn)
         shrwkb=exp(MW[404+_cnt][J])/(exp(MW[404+_cnt][J])+exp(MW[405+_cnt][J])+exp(MW[406+_cnt][J]))
         shrpnrb=exp(MW[405+_cnt][J])/(exp(MW[404+_cnt][J])+exp(MW[405+_cnt][J])+exp(MW[406+_cnt][J]))
         shrknrb=exp(MW[406+_cnt][J])/(exp(MW[404+_cnt][J])+exp(MW[405+_cnt][J])+exp(MW[406+_cnt][J]))
         eutilt=exp(NC_TRNAC*ln(exp(MW[404+_cnt][J])+exp(MW[405+_cnt][J])+exp(MW[406+_cnt][J])))
       else
         shrwkb=0
         shrpnrb=0
         shrknrb=0
         eutilt=0
       endif
       print list='\nExponentiated transit nest disutility       ',eutilt(14.12),printo=1

       ; hov nest
       if ((exp(MW[402+_cnt][J])+exp(MW[403+_cnt][J]))>_konn)
         shrhov2sr=exp(MW[402+_cnt][J])/(exp(MW[402+_cnt][J])+exp(MW[403+_cnt][J]))
         shrhov3sr=exp(MW[403+_cnt][J])/(exp(MW[402+_cnt][J])+exp(MW[403+_cnt][J]))
         eutilsr=exp(NC_AUTOSR*ln(exp(MW[402+_cnt][J])+exp(MW[403+_cnt][J])))
       else
         shrhov2sr=0
         shrhov3sr=0
         eutilsr=0
       endif
       ; auto nest
       if ((exp(MW[401+_cnt][J])+eutilsr)>_konn)
         shrdaa=exp(MW[401+_cnt][J])/(exp(MW[401+_cnt][J])+eutilsr)
         shrsra=eutilsr/(exp(MW[401+_cnt][J])+eutilsr)
         eutila=exp(NC_AUTO*ln(exp(MW[401+_cnt][J])+eutilsr))
       else
         shrdaa=0
         shrsra=0
         eutila=0
       endif
       print list='\nExponentiated Auto disutility                 ',eutila(14.12),printo=1
       ; top nest
       if ((eutila+eutilt)>_konn)
         shra=eutila/(eutila+eutilt)
         shrt=eutilt/(eutila+eutilt)
         eutil=(eutila+eutilt)
       else
         shra=0
         shrt=0

         eutil=0
       endif
       print list='\nExponentiated total disutility                ',eutil(14.12),printo=1

       ; individual shares
       shrda=shrdaa*shra
       shrhov2=shrhov2sr*shrsra*shra
       shrhov3=shrhov3sr*shrsra*shra
       shrwalkbus=shrwkb*shrt

       shrpnrbus=shrpnrb*shrt

       shrknrbus=shrknrb*shrt

       ; print shares
       print list='\n\nTrips by mode:                       Share',printo=1
       print list='    Drive Alone                    ',shrda(7.8),printo=1
       print list='    HOV2                           ',shrhov2(7.8),printo=1
       print list='    HOV3                           ',shrhov3(7.8),printo=1
       print list='    Walk Bus                       ',shrwalkbus(7.8),printo=1

       print list='    PNR Bus                        ',shrpnrbus(7.8),printo=1

       print list='    KNR Bus                        ',shrknrbus(7.8),printo=1

       print list='\n\nCalculated shares using the utility equations:       ', printo=1
       print list='   Top Nest:                                         ', printo=1
       print list='        Auto Share               ',shra(6.4), printo=1
       print list='        Transit Share            ',shrt(6.4), printo=1

       print list='\n\n   Auto Nest:                                    ', printo=1
       print list='        Drive Alone Share        ',shrdaa(6.4), printo=1
       print list='        Shared Ride Share        ',shrsra(6.4), printo=1
       print list='\n\n   Shared Ride Nest:                             ', printo=1
       print list='        HOV2 Share               ',shrhov2sr(6.4), printo=1
       print list='        HOV3 Share               ',shrhov3sr(6.4), printo=1
       print list='\n\n   Transit Nest:                                 ', printo=1
       print list='        Walk Transit Share       ',shrwalkbus(6.4), printo=1
       print list='        PNR Transit Share        ',shrpnrbus(6.4), printo=1
       print list='        KNR Transit Share        ',shrknrbus(6.4), printo=1

; ######################### END HAND CALCULATIONS ########################################
; ##################### XCHOICE RESULTS###############################

       print list='\n\n\nCUBE UTILITY BASED XCHOICE MODEL\n',printo=1
       print list='*******************************************************************',printo=1
       print list='\nTotal demand between the interchange:  ',MW[251][J](10.2),printo=1
       print list='Demand from 0-car households           ',MW[_cnt1][J](10.2),printo=1
     IF ((MW[M1][J]+MW[M2][J]+MW[M3][J]+MW[M4][J]+MW[M5][J]+MW[M6][J])>0)
       xcshrda  =(MW[M1][J]/(MW[M1][J]+MW[M2][J]+MW[M3][J]+MW[M4][J]+MW[M5][J]+MW[M6][J]))
       xcshrhov2=(MW[M2][J]/(MW[M1][J]+MW[M2][J]+MW[M3][J]+MW[M4][J]+MW[M5][J]+MW[M6][J]))
       xcshrhov3=(MW[M3][J]/(MW[M1][J]+MW[M2][J]+MW[M3][J]+MW[M4][J]+MW[M5][J]+MW[M6][J]))
       xcshrwkb =(MW[M4][J]/(MW[M1][J]+MW[M2][J]+MW[M3][J]+MW[M4][J]+MW[M5][J]+MW[M6][J]))
       xcshrpnrb=(MW[M5][J]/(MW[M1][J]+MW[M2][J]+MW[M3][J]+MW[M4][J]+MW[M5][J]+MW[M6][J]))
       xcshrknrb=(MW[M6][J]/(MW[M1][J]+MW[M2][J]+MW[M3][J]+MW[M4][J]+MW[M5][J]+MW[M6][J]))

       xcshrtot=xcshrda+xcshrhov2+xcshrhov3+xcshrwkb+xcshrpnrb+xcshrknrb
       print list='\n\nTrips by mode:                          Trips      Share',printo=1
       print list='    Drive Alone                    ',MW[M1][J](10.2),'    ',xcshrda(7.4),printo=1
       print list='    HOV2                           ',MW[M2][J](10.2),'    ',xcshrhov2(7.4),printo=1
       print list='    HOV3                           ',MW[M3][J](10.2),'    ',xcshrhov3(7.4),printo=1
       print list='    Walk Bus                       ',MW[M4][J](10.2),'    ',xcshrwkb(7.4),printo=1

       print list='    PNR Bus                        ',MW[M5][J](10.2),'    ',xcshrpnrb(7.4),printo=1
       print list='    KNR Bus                        ',MW[M6][J](10.2),'    ',xcshrknrb(7.4),printo=1

       print list='\n\n\nOutput shares by XCHOICE:                             ', printo=1
       print list='   Top Nest:                                         ', printo=1
       print list='        Auto Share               ',(xcshrda+xcshrhov2+xcshrhov3)(7.4), printo=1
       print list='        Transit Share            ',(xcshrwkb+xcshrpnrb+xcshrknrb)(7.4), printo=1

       print list='\n\n   Auto Nest:                                    ', printo=1
       print list='        Drive Alone Share        ',(xcshrda/(xcshrda+xcshrhov2+xcshrhov3))(7.4), printo=1
       print list='        Shared Ride Share        ',((xcshrhov2+xcshrhov3)/(xcshrda+xcshrhov2+xcshrhov3))(7.4), printo=1
       print list='\n\n   Shared Ride Nest:                             ', printo=1
       print list='        HOV2 Share               ',(xcshrhov2/(xcshrhov2+xcshrhov3))(7.4), printo=1
       print list='        HOV3 Share               ',(xcshrhov3/(xcshrhov2+xcshrhov3))(7.4), printo=1
       print list='\n\n   Transit Nest:                                 ', printo=1
       print list='        Walk Transit Share       ',((xcshrwkb)/(xcshrwkb+xcshrpnrb+xcshrknrb))(7.4), printo=1

       print list='        PNR Transit Share        ',((xcshrpnrb)/(xcshrwkb+xcshrpnrb+xcshrknrb))(7.4), printo=1
       print list='        KNR Transit Share        ',((xcshrknrb)/(xcshrwkb+xcshrpnrb+xcshrknrb))(7.4), printo=1

       print list='\n\n',printo=1

       IF (MARKET=3)
        print list='\n\n\n','END TRACE @PURP@-@PERIOD@','\n',printo=1
        print list='========================================================================================',printo=1
       ENDIF

      ELSE
       print list='No demand (input trips) from this access type and market segment............... ',printo=1
       print list='\n\n',printo=1

      ENDIF

      ENDIF
     ENDJLOOP
    ENDIF

   ENDLOOP ; end market loop created for reporting purposes

; ###############################################################################

ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\MCMAT00Z.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=MATRIX PRNFILE="X:\Projects\CRTPA\Model\C\APPLICATIONS\MCMAT00A.PRN" MSG='Mode Choice Reporting'
FILEI MATI[7] = "{SCENARIO_DIR}\output\@PURP@Utility.mat"
FILEO MATO[1] = "{SCENARIO_DIR}\output\@PURP@_{alt}{year}.MAT",
MO=501-509,DEC=12*s,NAME=DA,SR2,SR3,WALKBUS,WALKPRJ,PNRBUS,PNRPRJ,KNRBUS,KNRPRJ;

FILEO MATO[2] = "{SCENARIO_DIR}\output\@PURP@UTIL_{alt}{year}.MAT",
MO=401-407,421-427,441-447, DEC=21*D,
NAME=PerTrip1,AutoTrnTrip1,AutoPrice1,WalkFrac1,WalkShare1,DriveFrac1,DriveShare1,
     PerTrip2,AutoTrnTrip2,AutoPrice2,WalkFrac2,WalkShare2,DriveFrac2,DriveShare2,
     PerTrip3,AutoTrnTrip3,AutoPrice3,WalkFrac3,WalkShare3,DriveFrac3,DriveShare3
FILEO PRINTO[4] = "{SCENARIO_DIR}\output\CBDSHARES.CSV",
append=t
FILEO PRINTO[3] = "{SCENARIO_DIR}\output\MODESHARES.CSV",
append=t
FILEO PRINTO[2] = "{SCENARIO_DIR}\output\ModeSum.TXT",
append=t
FILEO PRINTO[1] = "{SCENARIO_DIR}\output\ModeDebug.TXT",
append=t
FILEI LOOKUPI[1] = "{SCENARIO_DIR}\output\TRN_COEFFICIENTS.DBF"
FILEI ZDATI[1] = "{SCENARIO_DIR}\output\TAZDATA_{alt}{year}.DBF"
FILEI MATI[6] = "{SCENARIO_DIR}\output\expautoutil_tmp.mat"
FILEI MATI[5] = "{SCENARIO_DIR}\output\farexfer_tmp.mat"
FILEI MATI[4] = "{SCENARIO_DIR}\output\@PURP@Trip.MAT"
FILEI MATI[3] = "{SCENARIO_DIR}\output\@PURP@Trip_2CAR.MAT"
FILEI MATI[2] = "{SCENARIO_DIR}\output\@PURP@Trip_1CAR.MAT"
FILEI MATI[1] = "{SCENARIO_DIR}\output\@PURP@Trip_0CAR.MAT"

zonemsg=100

FILLMW MW[1]  =MI.1.1,2,3,4,5,6     ;  0 car
FILLMW MW[21] =MI.2.1,2,3,4,5,6     ;  1 car
FILLMW MW[41] =MI.3.1,2,3,4,5,6     ;  2 car
FILLMW MW[201]=MI.4.1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31   ; 0 car, 1 car, 2 car households
FILLMW MW[251]=MI.6.1,2,3
FILLMW MW[261]=MI.5.1,2,3,4,5,6                        ; fare and xfer matrix for the nine paths
fillmw mw[701]=mi.7.1,2,3,4,5,6                        ; 0 car utils
fillmw mw[721]=mi.7.7,8,9,10,11,12                     ; 1 car utils
fillmw mw[741]=mi.7.13,14,15,16,17,18                  ; 2 car utils

array _tripsDA=3, _tripsHOV2=3, _tripsHOV3=3, _tripsWalkbus=3, _tripsWalkprj=3, _tripsPNRbus=3,
      _tripsPNRprj=3, _tripsKNRbus=3, _tripsKNRprj=3, _SUMtrips=3,
      CBDA=4,TOTACC=4

if (i=FirstZone)
  loop xx=1,3
    _tripsDA[xx]=0
    _tripsHOV2[xx]=0
    _tripsHOV3[xx]=0
    _tripsWalkBus[xx]=0
    _tripsWalkPrj[xx]=0
    _tripsPNRBus[xx]=0
    _tripsPNRPrj[xx]=0
    _tripsKNRBus[xx]=0
    _tripsKNRPrj[xx]=0
    _SUMtrips[xx]=0
  endloop
endif

 ; Total person trips for each market segment
 COMP total = ROWADD(301,201,202,203,204,205,206)    ; Person trips Market Segment 1
 COMP total = ROWADD(302,207,208,209,210,211,212)   ; Person trips Market Segment 2
 COMP total = ROWADD(303,213,214,215,216,217,218)   ; Person trips Market Segment 3

 ; Person trip for assignment
 COMP total = ROWADD(501,1,21,41)             ; DA Person trips
 COMP total = ROWADD(502,2,22,42)             ; HOV2 Person trips
 COMP total = ROWADD(503,3,23,43)             ; HOV3 Person trips
 COMP total = ROWADD(504,4,24,44)             ; walk-bus Person trips
 COMP total = ROWADD(505,5,25,45)             ; walk-prj Person trips
 COMP total = ROWADD(506,6,26,46)             ; pnr-bus Person trips

; ********************************* BEGIN USER BENEFIT (UB) AND MODE CHOICE SUMMARY ********************************************
LOOP MARKET=1,3                    ; UB data generated for each market segment separately

 if (MARKET=1) MARKET_NAME='Zero Car HHs       '
 if (MARKET=2) MARKET_NAME='One Car HHs        '
 if (MARKET=3) MARKET_NAME='Two+ Car HHs       '

 _idx1 = (200 + 6*(MARKET-1))
 _idx2 = 20*(MARKET-1)

 JLOOP
  _tripsDA[MARKET] = _tripsDA[MARKET] + MW[_idx1+1]
  _tripsHOV2[MARKET] = _tripsHOV2[MARKET] + MW[_idx1+2]
  _tripsHOV3[MARKET] = _tripsHOV3[MARKET] + MW[_idx1+3]
  _tripsWalkBus[MARKET] = _tripsWalkBus[MARKET] + MW[_idx1+4]
  _tripsPNRBus[MARKET] = _tripsPNRBus[MARKET] + MW[_idx1+5]
  _tripsKNRBus[MARKET] = _tripsKNRBus[MARKET] + MW[_idx1+6]

  ; For reporting prods/attrs
  if (ZI.1.CBD_DUMMY[i]==1)
    _cbdp1 = _cbdp1 + MW[_idx1+1]
    _cbdp2 = _cbdp2 + MW[_idx1+2]
    _cbdp3 = _cbdp3 + MW[_idx1+3]
    _cbdp4 = _cbdp1 + _cbdp2 + _cbdp3
    _cbdp5 = _cbdp5 + MW[_idx1+4]
    _cbdp6 = _cbdp6 + MW[_idx1+5]
    _cbdp7 = _cbdp7 + MW[_idx1+6]
    _cbdp8= _cbdp5 + _cbdp6 + _cbdp7
    _cbdp9= _cbdp4 + _cbdp8
  elseif (ZI.1.EXU_DUMMY[i]==1)
    _exup1 = _exup1 + MW[_idx1+1]
    _exup2 = _exup2 + MW[_idx1+2]
    _exup3 = _exup3 + MW[_idx1+3]
    _exup4 = _exup1 + _exup2 + _exup3
    _exup5 = _exup5 + MW[_idx1+4]
    _exup6 = _exup6 + MW[_idx1+5]
    _exup7 = _exup7 + MW[_idx1+6]
    _exup8= _exup5 + _exup6 + _exup7
    _exup9= _exup4 + _exup8
  else
    _othp1 = _othp1 + MW[_idx1+1]
    _othp2 = _othp2 + MW[_idx1+2]
    _othp3 = _othp3 + MW[_idx1+3]
    _othp4 = _othp1 + _othp2 + _othp3
    _othp5 = _othp5 + MW[_idx1+4]
    _othp6 = _othp6 + MW[_idx1+5]
    _othp7 = _othp7 + MW[_idx1+6]
    _othp8= _othp5 + _othp6 + _othp7
    _othp9= _othp4 + _othp8
  endif
  if (ZI.1.CBD_DUMMY[j]==1)
    _cbda1 = _cbda1 + MW[_idx1+1]
    _cbda2 = _cbda2 + MW[_idx1+2]
    _cbda3 = _cbda3 + MW[_idx1+3]
    _cbda4 = _cbda1 + _cbda2 + _cbda3
    _cbda5 = _cbda5 + MW[_idx1+4]
    _cbda6 = _cbda6 + MW[_idx1+5]
    _cbda7 = _cbda7 + MW[_idx1+6]
    _cbda8= _cbda5 + _cbda6 + _cbda7
    _cbda9= _cbda4 + _cbda8
  elseif (ZI.1.EXU_DUMMY[j]==1)
    _exua1 = _exua1 + MW[_idx1+1]
    _exua2 = _exua2 + MW[_idx1+2]
    _exua3 = _exua3 + MW[_idx1+3]
    _exua4 = _exua1 + _exua2 + _exua3
    _exua5 = _exua5 + MW[_idx1+4]
    _exua6 = _exua6 + MW[_idx1+5]
    _exua7 = _exua7 + MW[_idx1+6]
    _exua8= _exua5 + _exua6 + _exua7
    _exua9= _exua4 + _exua8
  else
    _otha1 = _otha1 + MW[_idx1+1]
    _otha2 = _otha2 + MW[_idx1+2]
    _otha3 = _otha3 + MW[_idx1+3]
    _otha4 = _otha1 + _otha2 + _otha3
    _otha5 = _otha5 + MW[_idx1+4]
    _otha6 = _otha6 + MW[_idx1+5]
    _otha7 = _otha7 + MW[_idx1+6]
    _otha8= _otha5 + _otha6 + _otha7
    _otha9= _otha4 + _otha8
  endif
/*
  ; For reporting fare revenue
  _frev1 = _frev1 + ((MI.5.FareWB * MW[_idx1+4]) / 100.0)
  _frev2 = _frev2 + ((MI.5.FarepB * MW[_idx1+5]) / 100.0)
  _frev3 = _frev3 + ((MI.5.FarekB * MW[_idx1+6]) / 100.0)
  _frev7 = _frev1 + _frev2 + _frev3
  _avef1 = 0

*/
 if (MARKET=3)
  ; For reporting transfers
  if (MW[264]==0)                          ;walk bus
    _xfer0_1 = _xfer0_1 + MW[504]
  elseif (MW[267]==1)
    _xfer1_1 = _xfer1_1 + MW[504]
  elseif (MW[267]==2)
    _xfer2_1 = _xfer2_1 + MW[504]
  else
    _xfer3_1 = _xfer3_1+ MW[504]
  endif

  if (MW[265]==0)                          ;pnr bus
    _xfer0_3 = _xfer0_3 + MW[505]
  elseif (MW[269]==1)
    _xfer1_3 = _xfer1_3 + MW[505]
  elseif (MW[269]==2)
    _xfer2_3 = _xfer2_3 + MW[505]
  else
    _xfer3_3 = _xfer3_3 + MW[505]
  endif

  if (MW[266]==0)                          ;knr bus
    _xfer0_5 = _xfer0_5 + MW[506]
  elseif (MW[271]==1)
    _xfer1_5 = _xfer1_5 + MW[506]
  elseif (MW[271]==2)
    _xfer2_5 = _xfer2_5 + MW[506]
  else
    _xfer3_5 = _xfer3_5 + MW[506]
  endif

  _xfer0_10 = _xfer0_1 + _xfer0_3 + _xfer0_5
  _xfer1_10 = _xfer1_1 + _xfer1_3 + _xfer1_5
  _xfer2_10 = _xfer2_1 + _xfer2_3 + _xfer2_5
  _xfer3_10 = _xfer3_1 + _xfer3_3 + _xfer3_5

 endif

  ; User benefit calculations are done for each market segment
  ; Determine can walk & must drive percentages for matrix for Summit for each market segment (1 for auto0, 2 for auto1 and 3 for auto2)
  ; person trips
  IF ({RunUB}==1)

  T1=401+_idx2, T2=402+_idx2, T3=403+_idx2, T4=404+_idx2, T5=405+_idx2, T6=406+_idx2, T7=407+_idx2

  if (MW[300+MARKET]>0)
    MW[T1] = MW[300+MARKET]                                                                     ; person trips in market segment
    MW[T2] = MW[T1]                                                                             ; motorized trips in market segment
    MW[T3] = MW[250+MARKET]

if(mw[704+_idx2]>-9999.99)
    mw[t4]=0.99
    mw[t5]= (MW[204+(market-1)*6] + MW[205+(market-1)*6] +MW[206+(market-1)*6]) /mw[t1]
    mw[t6]=0.00
    mw[t7]=0.00
elseif((mw[705+_idx2]>-9999.99)||(mw[706+_idx2]>-9999.99))
    mw[t4]=0.00
    mw[t5]=0.00
    mw[t6]=0.99
    mw[t7]=(MW[205+(market-1)*6] +MW[206+(market-1)*6]) /mw[t1]
else
    mw[t4]=0.00
    mw[t5]=0.00
    mw[t6]=0.00
    mw[t7]=0.00
endif

  else
    MW[T1] = 0.00
    MW[T2] = 0.00
    MW[T3] = 0.00
    MW[T4] = 0.00
    MW[T5] = 0.00
    MW[T6] = 0.00
    MW[T7] = 0.00
  endif

 if (I={SelOrigin} && J={SelDest})
    print list="*UB Rec* ",i(5.0),j(5.0),MARKET(5.0),mw[T1](10.1),mw[T2](10.1),mw[T3](10.7),mw[T4](10.5),mw[T5](10.5),mw[T6](10.5),mw[T7](10.5)
  endif

  ENDIF

  ; MODE CHOICE SUMMARY
  IF (i=_zones & j=_zones)

   _SUMtrips[MARKET] = _tripsDA[MARKET] + _tripsHOV2[MARKET] + _tripsHOV3[MARKET] +
                       _tripsWalkBus[MARKET] +
                       _tripsPNRBus[MARKET] +
                       _tripsKNRBus[MARKET]
   ; Total trips by purpose
   if (_SUMtrips[MARKET]=0) _SUMtrips[MARKET]=1

   if (MARKET==1)
     PRINT FORM=8.OC, LIST='\f\n\n@PURP@ - @PERIOD@ MODE XCHOICE RESULTS',
     '\n**************************************************************',
     '\n','                 ','     Total','     Drive','       One','      Two+','     Total','      Walk','       PNR','       KNR','     Total',
     '\n','MARKET SEGMENT   ','    Person','     Alone','       Pax','       Pax','      Auto','       Bus','       Bus','       Bus','   Transit',
     '\n','--------------   ','   -------','    ------','    ------','    ------','    ------','    ------','   -------','    ------','   -------',PRINTO=2
   endif

   _aocp = _aocp + (_tripsDA[MARKET]+_tripsHOV2[MARKET]+_tripsHOV3[MARKET])
   _aocv = _aocv + (_tripsDA[MARKET]+_tripsHOV2[MARKET]/2.0+_tripsHOV3[MARKET]/@OCC3@)
   _trntemp = (_tripsWalkBus[MARKET]+_tripsPNRBus[MARKET]+_tripsKNRBus[MARKET])

   PRINT LIST='\n',MARKET_NAME(17),_SUMtrips[MARKET](10.1),
                   _tripsDA[MARKET](10.1),_tripsHOV2[MARKET](10.1),_tripsHOV3[MARKET](10.1),_tripsDA[MARKET]+_tripsHOV2[MARKET]+_tripsHOV3[MARKET](10.1),
                   _tripsWalkBus[MARKET](10.1),
                   _tripsPNRBus[MARKET](10.1),
                   _tripsKNRBus[MARKET](10.1),_trntemp(10.1),PRINTO=2

   if (MARKET==3)
 _tripsDAtot = _tripsDA[1] +_tripsDA[2]+_tripsDA[3]
 _tripsHOV2tot = _tripsHOV2[1] + _tripsHOV2[2]+_tripsHOV2[3]
 _tripsHOV3tot = _tripsHOV3[1] + _tripsHOV3[2]+_tripsHOV3[3]
 _tripsWalkBustot = _tripsWalkBus[1] + _tripsWalkBus[2]+_tripsWalkBus[3]
 _tripsPNRBustot = _tripsPNRBus[1] + _tripsPNRBus[2]+_tripsPNRBus[3]
 _tripsKNRBustot = _tripsKNRBus[1] + _tripsKNRBus[2]+_tripsKNRBus[3]
_total=_tripsDAtot + _tripsHOV2tot+ _tripsHOV3tot + _tripsWalkBustot +_tripsPNRBustot+ _tripsKNRBustot
_autototal=_tripsDAtot + _tripsHOV2tot+ _tripsHOV3tot
_transittotal=_tripsWalkBustot +_tripsPNRBustot+ _tripsKNRBustot

     PRINT LIST =  '\n\n',
                   'TOTAL            ',_total(10.1),_tripsDAtot(10.1),_tripsHOV2tot(10.1), _tripsHOV3tot(10.1),_autototal(10.1),
                     _tripsWalkBustot(10.1),_tripsPNRBustot(10.1),_tripsKNRBustot(10.1),_transittotal(10.1),'\n\n',PRINTO=2

     PRINT LIST =  '\n\n',
                   'Productions:     ','\n',
                   'CBD              ',_cbdp9(10.1),_cbdp1(10.1),_cbdp2(10.1),_cbdp3(10.1),_cbdp4(10.1),_cbdp5(10.1),_cbdp6(10.1),
                   _cbdp7(10.1),_cbdp8(10.1),'\n',
                   'Exurban          ',_exup9(10.1),_exup1(10.1),_exup2(10.1),_exup3(10.1),_exup4(10.1),_exup5(10.1),_exup6(10.1),
                   _exup7(10.1),_exup8(10.1),'\n',
                   'Other            ',_othp9(10.1),_othp1(10.1),_othp2(10.1),_othp3(10.1),_othp4(10.1),_othp5(10.1),_othp6(10.1),
                   _othp7(10.1),_othp8(10.1),PRINTO=2
     PRINT LIST =  '\n\n',
                   'Attractions:     ','\n',
                   'CBD              ',_cbda9(10.1),_cbda1(10.1),_cbda2(10.1),_cbda3(10.1),_cbda4(10.1),_cbda5(10.1),_cbda6(10.1),
                   _cbda7(10.1),_cbda8(10.1),'\n',
                   'Exurban          ',_exua9(10.1),_exua1(10.1),_exua2(10.1),_exua3(10.1),_exua4(10.1),_exua5(10.1),_exua6(10.1),
                   _exua7(10.1),_exua8(10.1),'\n',
                   'Other            ',_otha9(10.1),_otha1(10.1),_otha2(10.1),_otha3(10.1),_otha4(10.1),_otha5(10.1),_otha6(10.1),
                   _otha7(10.1),_otha8(10.1),PRINTO=2

     CBDA[1] = CBDA[1] + _cbda5
     CBDA[2] = CBDA[2] + _cbda6
     CBDA[3] = CBDA[3] + _cbda7

     TOTACC[1] = TOTACC[1] + _tripsWalkBustot
     TOTACC[2] = TOTACC[2] + _tripsPNRBustot
     TOTACC[3] = TOTACC[3] + _tripsKNRBustot

/*
     PRINT LIST =  '\n\n',
                   'Fare Revenue ($) '," "(50),_frev1(10.2),_frev2(10.2),_frev3(10.2),_frev4(10.2),_frev5(10.2),
                                               _frev6(10.2),_frev7(10.2)," "(10),'\n',
                   'Average Fare ($) '," "(50),_avef1(10.2),_avef2(10.2),_avef3(10.2),_avef4(10.2),_avef5(10.2),
                                               _avef6(10.2),_avef7(10.2)," "(10),PRINTO=2

     PRINT LIST =  '\n\n',
                   'Transfers:       ','\n',
                   'NONE             '," "(50),_xfer0_1(10.1),_xfer0_3(10.1),_xfer0_5(10.1),_xfer0_10(10.1),'\n',
                   'ONE              '," "(50),_xfer1_1(10.1),_xfer1_3(10.1),_xfer1_5(10.1),_xfer1_10(10.1),'\n',
                   'TWO              '," "(50),_xfer2_1(10.1),_xfer2_3(10.1),_xfer2_5(10.2),_xfer2_10(10.1),'\n',
                   'THREE +          '," "(50),_xfer3_1(10.1),_xfer3_3(10.1),_xfer3_5(10.1),_xfer3_10(10.1),PRINTO=2
*/
     PRINT LIST =  '\n\n',
                   'Average Auto Occupancy      =',_aocp/_aocv(8.3),
                   '\n\n**************************************************************',PRINTO=2
   endif
abcd1=0
abcd2=0
   ; OUTPUT MODEL SHARES TO A CSV FILE FOR CALIBRATION

    PRINT CSV=T, LIST= (18*(@PURPNO@-2)+6*(MARKET-1)+1),@PURPOSE@,MARKET,_tripsDA[MARKET]/_SUMtrips[MARKET](12.6), PRINTO=3
    PRINT CSV=T, LIST= (18*(@PURPNO@-2)+6*(MARKET-1)+2),@PURPOSE@,MARKET,_tripsHOV2[MARKET]/_SUMtrips[MARKET](12.6), PRINTO=3
    PRINT CSV=T, LIST= (18*(@PURPNO@-2)+6*(MARKET-1)+3),@PURPOSE@,MARKET,_tripsHOV3[MARKET]/_SUMtrips[MARKET](12.6), PRINTO=3
    PRINT CSV=T, LIST= (18*(@PURPNO@-2)+6*(MARKET-1)+4),@PURPOSE@,MARKET,_tripsWalkBus[MARKET]/_SUMtrips[MARKET](12.6), PRINTO=3
    PRINT CSV=T, LIST= (18*(@PURPNO@-2)+6*(MARKET-1)+5),@PURPOSE@,MARKET,_tripsPNRBus[MARKET]/_SUMtrips[MARKET](12.6), PRINTO=3
    PRINT CSV=T, LIST= (18*(@PURPNO@-2)+6*(MARKET-1)+6),@PURPOSE@,MARKET,_tripsKNRBus[MARKET]/_SUMtrips[MARKET](12.6), PRINTO=3

  ENDIF

 ENDJLOOP

ENDLOOP

IF (I == _ZONES)

if(totacc[1]=0)
  PRINT CSV=T, LIST=((@PURPNO@-2)*3+1),(@PURPNO@-1),abcd1(10.6), printo=4
else
  PRINT CSV=T, LIST=((@PURPNO@-2)*3+1),(@PURPNO@-1),(cbda[1]/totacc[1])(10.6), printo=4
endif

if(totacc[2]=0)
  PRINT CSV=T, LIST=((@PURPNO@-2)*3+2),(@PURPNO@-1),abcd1(10.6), printo=4
else
  PRINT CSV=T, LIST=((@PURPNO@-2)*3+2),(@PURPNO@-1),(cbda[2]/totacc[2])(10.6), printo=4
endif

if(totacc[3]=0)
  PRINT CSV=T, LIST=((@PURPNO@-2)*3+3),(@PURPNO@-1),abcd1(10.6), printo=4
else
  PRINT CSV=T, LIST=((@PURPNO@-2)*3+3),(@PURPNO@-1),(cbda[3]/totacc[3])(10.6), printo=4
endif

ENDIF
; ********************************* END USER BENEFIT AND MODE CHOICE SUMMARY ********************************************
ENDRUN


; PILOT Script


if ({RunUB,CheckBox,"Dummy variable to run (=1) or not run (=0) user benefits & generate user benefit files",0}==1)

; End of PILOT Script

; Script for program TPP2UB in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\MCTUB00B.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=TPP2UB PRNFILE="{SCENARIO_DIR}\output\MCMAT00F.PRN" MSG='Convert Voyager matrices to Summit Datafile'
FILEI MATI = "{SCENARIO_DIR}\output\@PURP@UTIL_{alt}{year}.MAT"
FILEI VARI = "{SCENARIO_DIR}\output\@PURP@HEAD.VAR"
FILEO MATO = "{SCENARIO_DIR}\output\@PURP@UTIL.UB"


ENDRUN


; PILOT Script



else
endif          ; RunUB flag
; End of PILOT Script

ENDLOOP

; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\MCMAT00G.S"
; 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


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\MCMAT00D.S"
; 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\MCMAT00H.PRN" MSG='Combine trip tables for assignment'
FILEO MATO[2] = "{SCENARIO_DIR}\output\TRANSITTAB_{alt}{year}.MAT",
 MO=131-133,141-143, DEC=18*s,
 NAME=PKWlkBus,PKWlkPrj,PKPNRBus,PKPNRPrj,PKKNRBus,PKKNRPrj,
      OPWlkBus,OPWlkPrj,OPPNRBus,OPPNRPrj,OPKNRBus,OPKNRPrj
FILEO MATO[1] = "X:\Projects\CRTPA\Model\C\BASE\OUTPUT\HWYTTAB_TEMP_{ALT}{YEAR}.MAT",
MO=121-124,NAME=HBW,HBO,NHB,TOTAL,DEC=6*S 
;MO=121-126, NAME=TRKIEII,SOVIEII,HOVIEII,TRKEE,SOVEE,HOVEE, DEC=6*s

FILEI MATI[3] = "{SCENARIO_DIR}\output\NHB_{alt}{year}.MAT"
FILEI MATI[2] = "{SCENARIO_DIR}\output\HBO_{alt}{year}.MAT"
FILEI MATI[1] = "{SCENARIO_DIR}\output\HBW_{alt}{year}.MAT"

PAR ZONEMSG=100
DistributeINTRASTEP ProcessID="FSUTMSDist", ProcessList=1-3

;DA
MW[50]=MI.1.1+MI.2.1+MI.3.1

;CARPOOL
MW[60]=(MI.1.2+MI.2.2+MI.3.2)*0.5+
        MI.1.3/{oc3vhbw}+
        MI.2.3/{oc3vhbnw}+
        MI.3.3/{oc3vnhb}

MW[124]=MW[50]+MW[60]
MW[121]=MI.1.1+MI.1.2*0.5+MI.1.3/{oc3vhbw}
MW[122]=MI.2.1+MI.2.2*0.5+MI.2.3/{oc3vhbnw}
MW[123]=MI.3.1+MI.3.2*0.5+MI.3.3/{oc3vnhb}


;FILLMW MW[1]  = MI.1.1,2,3,4,5,6   ; - HBW trips
;FILLMW MW[21] = MI.2.1,2,3,4,5,6  ; - HBNW trips
;FILLMW MW[41] = MI.3.1,2,3,4,5,6   ; - NHB trips

; PEAK TRANSIT
MW[131]=MI.1.4
MW[132]=MI.1.6
MW[133]=MI.1.8

; OFF-PEAK TRANSIT
MW[141]=MI.2.4 + MI.3.4
MW[142]=MI.2.6 + MI.3.6
MW[143]=MI.2.8 + MI.3.8

;MW[121]=MW[1]+MW[2]+MW[3]
;MW[122]=MW[21]+MW[22]+MW[23]
;MW[123]=MW[41]+MW[42]+MW[43]
;MW[124]=MW[121]+MW[122]+MW[123]


ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\MCMAT00E.S"
; 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\MCMAT00A.PRN"
FILEI MATI[3] = "{Scenario_Dir}\OUTPUT\PSNTRIPS_{ALT}{YEAR}.MAT"
FILEO MATO[1] = "X:\Projects\CRTPA\Model\C\BASE\OUTPUT\TEMP_HWYTTAB_{ALT}{YEAR}.MAT",
MO=1-7, NAME=HBW,HBO,NHB,TAX,IE,EE,TOTAL
FILEI MATI[2] = "{Scenario_Dir}\OUTPUT\EETRIPS_{ALT}{Year}.MAT"
FILEI MATI[1] = "X:\Projects\CRTPA\Model\C\BASE\OUTPUT\HWYTTAB_TEMP_{ALT}{YEAR}.MAT"

;MW[11]=MI.1.4+MI.2.1+MI.3.4+MI.3.5
;mw[22]=MI.1.1.T+MI.1.2.t+MI.1.3.t+MI.2.1.t*0.5+mi.3.4.t+mi.3.5.t
MW[1]=MI.1.1*0.5
MW[2]=MI.1.2*0.5
MW[3]=MI.1.3*0.5
MW[4]=MI.3.4*0.5
;MW[5]=(MI.3.5+MI.3.5.T)*0.5*0.5
;MW[6]=MI.2.1*0.5
;MW[7]=MW[1]+MW[2]+MW[3]+MW[4]+MW[5]+MW[6]
;mw[1]=MW[11]*0.5

;if (i=2207) || (I=2208)
;mw[5]=(mi.3.1+mi.3.2)*0.5
;elseIF(I=2208)
;mw[5]=(mi.3.1+mi.3.2)*0.5
;ELSE
MW[5]=(MI.3.5+MI.3.5.T)*0.5*0.5
;endif

MW[6]=MI.2.1*0.5
MW[7]=MW[1]+MW[2]+MW[3]+MW[4]+MW[5]+MW[6]

;FILLMW MW[11]=MI.1.1,2,3,4,5             ;11/12/13/14/15: DA,SR2,SR3P,TRKS,SR2P   
;FILLMW MW[21]=MI.1.1.T,2.T,3.T,4.T,5.T   ;21/22/23/24/25: DA,SR2,SR3P,TRKS,SR2P-Transposed   


;Balanced Vehicle trips & Trucks are in PCE
;MW[1]= (MW[11]+MW[21])*0.5         ;24H - DA
;MW[2]= (MW[12]+MW[22])*0.5         ;24H - SR2
;MW[3]= (MW[13]+MW[23])*0.5         ;24H - SR3P
;MW[4]= (MW[14]+MW[24])*0.5         ;24H - TRKS
;MW[5]= (MW[15]+MW[25])*0.5         ;24H - SR2P




ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\MCMAT00K.S"
; 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\MCMAT00B.PRN"
FILEO MATO[1] = "{Scenario_Dir}\OUTPUT\HWYTTAB_{ALT}{Year}.MAT",
MO=1, NAME=TRIPS
FILEI MATI[1] = "X:\Projects\CRTPA\Model\C\BASE\OUTPUT\TEMP_HWYTTAB_{ALT}{YEAR}.MAT"


PAR ZONEMSG=100

MW[1]=MI.1.7+MI.1.7.T



; The MATRIX module does not have any explicit phases.  The module does run within an implied ILOOP
; where I is the origin zones.  All user statements in the module are processed once for each origin.
; Matrix computation (MW[#]=) are solved for all values of J for each I.  Thus for a given origin zone I
; the values for all destination zones J are automatically computed.  The user can control the computations
; at each J by using a JLOOP.

ENDRUN


; PILOT Script
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.


*if exist {SCENARIO_DIR}\output\new_trncoeff.csv del {SCENARIO_DIR}\output\new_trncoeff.csv
*if exist {SCENARIO_DIR}\output\new_mcconsts.csv del {SCENARIO_DIR}\output\new_mcconsts.csv.csv
; End of PILOT Script

; Script for program HIGHWAY in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TAHWY00C.S"
; 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\TAHWY00A.PRN"
FILEI MATI[1] = "{Scenario_Dir}\OUTPUT\HWYTTAB_{ALT}{Year}.MAT"
FILEO PRINTO[1] = "{Scenario_Dir}\OUTPUT\HASSIGN.PRN"
FILEO TURNVOLO[1] = "{Scenario_Dir}\OUTPUT\TURNS_{ALT}{Year}.TRN"
FILEO NETO = "{Scenario_Dir}\OUTPUT\HWYLOAD_{ALT}{Year}.NET"
FILEI TURNPENI = "{Scenario_Dir}\Input\TURN_{Year}{ALT}.PEN"
FILEI NETI = "{Scenario_Dir}\OUTPUT\UNLOADED_{ALT}{Year}.NET"

DistributeINTRASTEP ProcessID="FSUTMSDist", ProcessList=1-4
PAR ZONEMSG=100 MAXITERS={AssignIters} ;GAP=0.05  LAMBDA=0.01 
TURNS N=1-999999
Zones={ZONESA}
; look up deceleration rate based on approach speed
LOOKUP,
 INTERPOLATE=Y, LIST=Y, NAME=DECEL,
        LOOKUP[1]=1,RESULT=2,
R = '30 4',
    '70 6.2'

PROCESS PHASE=LINKREAD
  T0=li.TIME
  LW.FFTIME=LI.TIME ; USE FOR PRELOAD PURPOSES (FFTIME)
  C=LI.CAPACITY*LI.NUM_LANES*LI.UROADFACTOR/LI.CONFAC
  IF (LI.{PATHGROUP}) ADDTOGROUP=7 ; DEFINE A SUBSET FOR PATHFILE
; classify links based on presence/absence of conventional tolls
      LINKCLASS=1 ; no toll
      if (li.tolltype=1) 
       LINKCLASS=2 ; with toll
       T0=({CTOLL}*LI.CARTOLL)*60 + LI.SVCMINUTES + LI.SVCSECONDS/60
       if (iteration=0)
          LW.ARRIVR=(V/LI.UROADFACTOR)*LI.CONFAC/LI.PLZALNSMAX  ; hourly volume per toll lane ie. arrival rate in vehicles per hour
        LW.SERVT=LI.SVCMINUTES+(LI.SVCSECONDS/60)           ; Plaza lane service time in minutes per vehicle
        LW.SERVR=(1/LW.SERVT)*60                            ; Plaza lane service rate in vehicle per hour
        PRINT LIST='ARRIVR= ',LW.ARRIVR
        PRINT LIST='SERVT= ',LW.SERVT
        PRINT LIST='SERVR= ',LW.SERVR
        if (LW.ARRIVR>=LW.SERVR) LW.ARRIVR=0.99*LW.SERVR    ; prevent infinite or negative queue 
       endif
      endif
; classify links based on presence/absence of Open Road Toll
      if (li.tolltype=2) 
       LINKCLASS=3 ; with ORT
       T0=({CTOLL}*LI.CARTOLL)*60
       endif
       if (li.TOLL_ACC>0) 
       LINKCLASS=4 ; Toll Plaza Acceleration link
       T0= T0 + (LI.SPEED/2.5)/60
      endif
      if (li.TOLL_DEC>0) 
       LINKCLASS=5 ; Toll Plaza Deceleration link
       T0 = T0 + (LI.SPEED/DECEL(1,LI.SPEED))/60
      endif


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
if ({pathfile}=1)
  PATHLOAD PATH=TIME, VOL[1]=MI.1.1, PENI=1;, NAME=TRIPS,ALLJ=T,INCLUDECOSTS=F, PATHOGROUP=7
else
  PATHLOAD PATH=TIME, VOL[1]=MI.1.1, PENI=1
endif
IF (I=ZONES)
  LINKLOOP
    LW.PREVTIME=TIME
  ENDLINKLOOP
ENDIF

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.
if (time>0) LW.CGSTSPEED=(LW.DISTANCE/TIME)*60
if (li.tolltype=1) 
 LW.ARRIVR=(V/LI.UROADFACTOR)*LI.CONFAC/LI.PLZALNSMAX  ; hourly volume per toll lane ie. arrival rate in vehicles per hour
 LW.SERVT=LI.SVCMINUTES+(LI.SVCSECONDS/60)           ; Plaza lane service time in minutes per vehicle
 LW.SERVR=(1/LW.SERVT)*60                            ; Plaza lane service rate in vehicle per hour
 if (LW.ARRIVR>=LW.SERVR) LW.ARRIVR=0.99*LW.SERVR    ; prevent infinite or negative queue 
PRINT LIST='ARRIVR= ',LW.ARRIVR
PRINT LIST='SERVT= ',LW.SERVT
PRINT LIST='SERVR= ',LW.SERVR
PRINT LIST='TOLLTIME= ',TIME
endif
 ;FUNCTION   TC[1]=LI.TIME*(1+LI.BPRCOEFFICIENT*MIN((V/C),{vcmax})^LI.BPREXPONENT) ; congested time for non-toll links
 FUNCTION   TC[1]={DAMPINGFACTOR}*LW.PREVTIME+(1.0-{DAMPINGFACTOR})*LI.TIME*(1+LI.BPRCOEFFICIENT*MIN((V/C),{vcmax})^LI.BPREXPONENT) ; congested time for non-toll links
 FUNCTION   TC[2]=MIN((1/(LW.SERVR-LW.ARRIVR))*60,20)+{CTOLL}*LI.CARTOLL*60 ; congested time for toll links
 FUNCTION   TC[3]={CTOLL}*LI.CARTOLL*60 ; congested time for ORT toll links
 FUNCTION   TC[4]=LI.TIME*(1+LI.BPRCOEFFICIENT*MIN((V/C),{vcmax})^LI.BPREXPONENT) + (LW.CGSTSPEED/2.5)/60; congested time toll acceleration links
 FUNCTION   TC[5]=LI.TIME*(1+LI.BPRCOEFFICIENT*MIN((V/C),{vcmax})^LI.BPREXPONENT) + (LW.CGSTSPEED/DECEL(1,LW.CGSTSPEED))/60; congested time toll deceleration links

if (li.cartoll>0) print list="Iter:",iteration(2.0)," TOLLFM Summary, A=",A(6.0)," B=",B(6.0)," PLAZAID=",li.TOLL(3.0)," NAME=",li.PLAZADESC(24)," MAX LNS=",li.PLZALNSMAX," GCOST=",TIME(6.2),
        printo=1

ENDPROCESS

ENDRUN


LOOP LegLink = 1, 2, 1

; PILOT Script



if (LegLink=1)
ReadLoop1=' '
ReadLoop2=';' 
else
ReadLoop1=';'
ReadLoop2=' '
endif
; End of PILOT Script

; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TSMAT00A.S"

; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=MATRIX PRNFILE="X:\Projects\CRTPA\Model\C\APPLICATIONS\TSMAT00A.PRN" MSG='Combine trips'
FILEI MATI[1] = "{SCENARIO_DIR}\output\TRANSITTAB_{alt}{year}.MAT"
FILEO MATO[1] = "{SCENARIO_DIR}\output\tloadam_{alt}{year}.mat",
  MO=1-2,NAME=WalkTran,AutoTran

ZONEMSG=100

FILLMW MW[11]=MI.1.1,2,3

COMP total = ROWADD(1,11)
COMP total = ROWADD(2,12,13)

ENDRUN


; Script for program PUBLIC TRANSPORT in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TSPTR00A.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=PUBLIC TRANSPORT PRNFILE="X:\Projects\CRTPA\Model\C\APPLICATIONS\TSPTR00A.PRN" MSG='Assignment - WalkBus'
FILEO NETO = "{SCENARIO_DIR}\output\TLOADPK1_{alt}{year}.NET"
FILEO LINKO = "{SCENARIO_DIR}\output\TLINKPK1_{alt}{year}.DBF",
@ReadLoop2@       NTLEGS=T,ONOFFS=T
@ReadLoop1@       ONELINKREC=T,NTBYLINK=T

FILEI NETI = "{SCENARIO_DIR}\output\PKWalk.NET"
FILEI ROUTEI[1] = "{SCENARIO_DIR}\Output\TPATHAM1_{alt}{year}.RTE"
FILEI MATI[1] = "{SCENARIO_DIR}\output\tloadam_{alt}{year}.mat"
FILEO REPORTO = "{SCENARIO_DIR}\output\TLOADPK1_{alt}{year}.RPT"

; OVERALL PARAMETERS
PARAMETERS USERCLASSES=1, NOROUTEERRS=999999, NOROUTEMSGS=999999,
                HDWAYPERIOD=1,
                TRIPSIJ[1]=MI.1.WalkTran
                            
REPORT LINES=T, LINEVOLS=T, STOPSONLY=T

ENDRUN


; Script for program PUBLIC TRANSPORT in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TSPTR00I.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=PUBLIC TRANSPORT PRNFILE="X:\Projects\CRTPA\Model\C\APPLICATIONS\TSPTR00F.PRN" MSG='Assignment - AutoBus'
FILEI ROUTEI[1] = "{SCENARIO_DIR}\Output\TPATHAM3_{alt}{year}.RTE"
FILEI MATI[1] = "{SCENARIO_DIR}\output\tloadam_{alt}{year}.mat"
FILEO NETO = "{SCENARIO_DIR}\output\TLOADPK3_{alt}{year}.NET"
FILEO LINKO = "{SCENARIO_DIR}\output\TLINKPK3_{alt}{year}.DBF",
 @ReadLoop2@       NTLEGS=T,ONOFFS=T
   @ReadLoop1@       ONELINKREC=T,NTBYLINK=T

FILEI NETI = "{SCENARIO_DIR}\output\PKAuto.NET"
FILEO REPORTO = "{SCENARIO_DIR}\output\TLOADPK3_{alt}{year}.RPT"
FILEO STOP2STOPO = "{SCENARIO_DIR}\output\STATIONPK2_{alt}{year}.DBF",
  ACCUMULATE=FIRSTLAST, NODES=1-99999
; OVERALL PARAMETERS
PARAMETERS USERCLASSES=1, NOROUTEERRS=999999, NOROUTEMSGS=999999,
                HDWAYPERIOD=1,
              
                TRIPSIJ[1]=MI.1.AutoTran
           
REPORT LINES=T, LINEVOLS=T, STOPSONLY=T

ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TSMAT00C.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=MATRIX PRNFILE="X:\Projects\CRTPA\Model\C\APPLICATIONS\TSMAT00C.PRN" MSG='Combine trips'
FILEI MATI[1] = "{SCENARIO_DIR}\output\TRANSITTAB_{alt}{year}.MAT"
FILEO MATO[1] = "{SCENARIO_DIR}\output\tloadmd_{alt}{year}.mat",
  MO=1-2,NAME=WalkTran,AutoTran

DistributeINTRAStep ProcessID="FSUTMSDist" ProcessList=1-4

ZONEMSG=100

FILLMW MW[21] =MI.1.4,5,6
COMP total = ROWADD(1,21)
COMP total = ROWADD(2,22,23)

ENDRUN


; Script for program PUBLIC TRANSPORT in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TSPTR00C.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=PUBLIC TRANSPORT PRNFILE="X:\Projects\CRTPA\Model\C\APPLICATIONS\TSPTR00E.PRN" MSG='Assignment - WalkBus'
FILEI MATI[1] = "{SCENARIO_DIR}\output\tloadmd_{alt}{year}.mat"
FILEO NETO = "{SCENARIO_DIR}\output\TLOADOP1_{alt}{year}.NET"
FILEO LINKO = "{SCENARIO_DIR}\output\TLINKOP1_{alt}{year}.DBF",
 @ReadLoop2@       NTLEGS=T,ONOFFS=T
   @ReadLoop1@       ONELINKREC=T,NTBYLINK=T


FILEI NETI = "{SCENARIO_DIR}\output\OPWalk.NET"
FILEI ROUTEI[1] = "{SCENARIO_DIR}\Output\TPATHMD1_{alt}{year}.RTE"
FILEO REPORTO = "{SCENARIO_DIR}\output\TLOADOP1_{alt}{year}.RPT"

; OVERALL PARAMETERS
PARAMETERS USERCLASSES=1, NOROUTEERRS=999999, NOROUTEMSGS=999999,
                HDWAYPERIOD=2,
                TRIPSIJ[1]=MI.1.WalkTran
                             
REPORT LINES=T, LINEVOLS=T, STOPSONLY=T

ENDRUN


; Script for program PUBLIC TRANSPORT in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TSPTR00K.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=PUBLIC TRANSPORT PRNFILE="X:\Projects\CRTPA\Model\C\APPLICATIONS\TSPTR00N.PRN" MSG='Assignment - AutoBus'
FILEI ROUTEI[1] = "{SCENARIO_DIR}\Output\TPATHMD3_{alt}{year}.RTE"
FILEI MATI[1] = "{SCENARIO_DIR}\output\tloadmd_{alt}{year}.mat"
FILEO NETO = "{SCENARIO_DIR}\output\TLOADOP3_{alt}{year}.NET"
FILEO LINKO = "{SCENARIO_DIR}\output\TLINKOP3_{alt}{year}.DBF",
 @ReadLoop2@       NTLEGS=T,ONOFFS=T
   @ReadLoop1@       ONELINKREC=T,NTBYLINK=T

FILEI NETI = "{SCENARIO_DIR}\output\OPAuto.NET"
FILEO REPORTO = "{SCENARIO_DIR}\output\TLOADOP3_{alt}{year}.RPT"
FILEO STOP2STOPO = "{SCENARIO_DIR}\output\STATIONOP2_{alt}{year}.DBF",
  ACCUMULATE=FIRSTLAST, NODES=1-99999
; OVERALL PARAMETERS
PARAMETERS USERCLASSES=1, NOROUTEERRS=999999, NOROUTEMSGS=999999,
                HDWAYPERIOD=2,

                TRIPSIJ[1]=MI.1.AutoTran

REPORT LINES=T, LINEVOLS=T, STOPSONLY=T

ENDRUN


ENDLOOP

; Script for program NETWORK in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\RPNET00A.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=NETWORK PRNFILE="{Scenario_Dir}\BASE\OUTPUT\RPNET00A.PRN"
FILEI LINKI[1] = "{SCENARIO_DIR}\Output\HWYLOAD_{ALT}{Year}.NET"
FILEO PRINTO[1] = "{Scenario_Dir}\OUTPUT\PPNET00B.PRN"
FILEO LINKO = "{Catalog_Dir}\APPLICATIONS\LDLINKS.DBF"

; =========================================================
; LINKMERGE PHASE
; =========================================================
PROCESS  PHASE=LINKMERGE  
; Use this phase to make computations and selections of any data on the LINKI files.
ZONE       =1
USECODE    =1
LOCATION   =LOCATION
LANDUSE    =1
CCODE      =1

 CAPACITY=(LI.1.NUM_LANES*LI.1.CAPACITY/LI.1.CONFAC)
   ft=FACILITY_TYPE;FTYPE1
   at=AREA_TYPE;ATYPE1
   LNS=LI.1.NUM_LANES
   TOTAL_VOL=ROUND(LI.1.V_1);ROUND(motorizedvol)
   count=LI.1.COUNT;PSAWDT
   ATYPE=AREA_TYPE
   FTYPE=FACILITY_TYPE
   LANES=NUM_LANES
   if(dircode=0) Twoway=1
   if(dircode=1) Twoway=0

; initialize arrays and variables
ARRAY _err=13, _cns=13, _cnt=13, _RGP=13, _volbyft=100, _cntbyft=100
   ARRAY _volbyat=100, _cntbyat=100, _lnkbyft=100, _lnkbyat=100
 _group=(0.0*FACILITY_TYPE)
   _RGP[1]=1, _RGP[2]=5000, _RGP[3]=10000, _RGP[4]=20000, _RGP[5]=30000, _RGP[6]=40000, _RGP[7]=50000,
   _RGP[8]=60000, _RGP[9]=70000, _RGP[10]=80000, _RGP[11]=90000, _RGP[12]=100000, _RGP[13]=500000
   IF (A=1)
     LOOP _iter=1,13
           _err[_iter]=0,_cnt[_iter]=0,_cns[_iter]=0
     ENDLOOP
     LOOP _iter=1,99
           _volbyft[_iter]=0, _cntbyft[_iter]=0, _lnkbyft[_iter]=0
           _volbyat[_iter]=0, _cntbyat[_iter]=0, _lnkbyat[_iter]=0
     ENDLOOP
ENDIF
   links=1
   lanemiles=lns*distance
; calculate and compartmentalize 
   IF(COUNT>0) VOLCNT=TOTAL_VOL/COUNT, NETDIFF=TOTAL_VOL-COUNT, ABSDIFF=ABS(NETDIFF), ERRORSQ=NETDIFF^2, PCTDIFF=100*NETDIFF/COUNT _group=1
   IF (COUNT>5000) _group=2
   IF (COUNT>10000) _group=3
   IF (COUNT>20000) _group=4
   IF (COUNT>30000) _group=5
   IF (COUNT>40000) _group=6
   IF (COUNT>50000) _group=7
   IF (COUNT>60000) _group=8
   IF (COUNT>70000) _group=9
   IF (COUNT>80000) _group=10
   IF (COUNT>90000) _group=11
   IF (COUNT>100000) _group=12
   IF (COUNT>0)
   _ERR[_group]=ERRORSQ+_ERR[_group], _CNS[_group]=COUNT+_CNS[_group], _CNT[_group]=_CNT[_group]+1
   _ERR[13]=ERRORSQ+_ERR[13], _CNS[13]=COUNT+_CNS[13], _CNT[13]=_CNT[13]+1
   ENDIF
IF (COUNT>0)  
   _volbyft[ft]=_volbyft[ft]+TOTAL_VOL
   _cntbyft[ft]=_cntbyft[ft]+count
   _lnkbyft[ft]=_lnkbyft[ft]+1
   _volbyat[at]=_volbyat[at]+TOTAL_VOL
   _cntbyat[at]=_cntbyat[at]+count
   _lnkbyat[at]=_lnkbyat[at]+1
   _volbyft[100]=_volbyft[100]+TOTAL_VOL
   _cntbyft[100]=_cntbyft[100]+count
   _lnkbyft[100]=_lnkbyft[100]+1
   _volbyat[100]=_volbyat[100]+TOTAL_VOL
   _cntbyat[100]=_cntbyat[100]+count
   _lnkbyat[100]=_lnkbyat[100]+1
endif

CROSSTAB  VAR= LINKS LANEMILES, form=12.0c,
    row=FT, range=10-99-10,
    col=LNS, range=1-5-1,6-9
IF (COUNT>0)
CROSSTAB  VAR= TOTAL_VOL,COUNT, form=12.0c,
    row=FT, range=10-99-10,
    col=AT, range=10-59-10
ENDIF







ENDPROCESS
; =========================================================
; SUMMARY REPORTING
; =========================================================

PROCESS  PHASE=SUMMARY   
; a little loop to write out the Percent Root Mean Square Error
LOOP _iter=1,12  
  if (_iter=1) print list="*************************** ROOT MEAN SQUARE ERROR SUMMARY *****************************", printo=1
  if (_cnt[_iter]>0) print,        
 list="  Percent RMSE for Volume Group ",_iter(2.0c)," ",_RGP[_iter](7.0c),"-",_RGP[_iter+1](7.0c),": ",sqrt(_err[_iter]/_cnt[_iter])/(_cns[_iter]/_cnt[_iter])*100(5.1),"%,                      N=",_cnt[_iter](5.0CL), PRINTO=1
ENDLOOP
_iter=13
 list="  Percent RMSE for Volume Group ",_iter(2.0c)," ",_RGP[1](7.0c),"-",_RGP[_iter](7.0c),": ",sqrt(_err[_iter]/_cnt[_iter])/(_cns[_iter]/_cnt[_iter])*100(5.1),"%,                      N=",_cnt[_iter](5.0CL), PRINTO=1

; one for Vol/Cnt by FT 
_iter=0
LOOP _iter=1,100
  if (_iter=1) print list="\n","\n ********************** VOLUME AND COUNT SUMMARY BY FACILITY TYPE **********************", PRINTO=1
if (_cntbyft[_iter]>0) print,
 list="Facility Type Summary for FT=",_iter(3.0c),
 " VOL=",_volbyft[_iter](11.0c),
 " CNT=",_cntbyft[_iter](11.0c),
 " VOL/CNT=",(_volbyft[_iter]/_cntbyft[_iter])(5.2c),
 "   N=",_lnkbyft[_iter](5.0c), PRINTO=1
ENDLOOP


; one for Vol/Cnt by AT
_iter=0
LOOP _iter=1,100
  if (_iter=1) print list="\n","\n ************************* VOLUME AND COUNT SUMMARY BY AREA TYPE ************************", PRINTO=1
if (_cntbyat[_iter]>0) print,
 list="    Area Type Summary for AT=",_iter(3.0c),
 " VOL=",_volbyat[_iter](11.0c),
 " CNT=",_cntbyat[_iter](11.0c),
 " VOL/CNT=",(_volbyat[_iter]/_cntbyat[_iter])(5.2c),
 "   N=",_lnkbyat[_iter](5.0c), PRINTO=1
ENDLOOP


ENDPROCESS

ENDRUN


; PILOT Script
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.

*Del {CATALOG_DIR}\Applications\profile.mas
*copy {CATALOG_DIR}\Parameters\proV.mas {CATALOG_DIR}\Applications\profile.mas
*{CATALOG_DIR}\Applications\hevaldbf.exe
; End of PILOT Script

; PILOT Script
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.


*copy {CATALOG_DIR}\Applications\HEVAL.OUT {scenario_dir}\output\HEVAL.OUT
*if exist {CATALOG_DIR}\Applications\HEVAL.OUT del {CATALOG_DIR}\Applications\HEVAL.OUT
; End of PILOT Script

; Script for program NETWORK in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\RPNET00D.S"
; 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\RPNET00C.PRN" MSG='RMSE'
FILEI LINKI[1] = "{SCENARIO_DIR}\Output\HWYLOAD_{ALT}{Year}.NET"
FILEO PRINTO[1] = "{Scenario_Dir}\OUTPUT\RMSE_{Year}{ALT}.PRN",
 APPEND=T 

; =========================================================
; LINKMERGE PHASE
; =========================================================
PHASE=LINKMERGE

   ft=int((LI.1.FACILITY_TYPE)/10)
  ; at=INT((LI.1.ATYPE)/10)
   ;at=AREA_TYPE
   ;AREA_TYPE=AREA_TYPE*10
   at=int((li.1.area_type)/10)
   LNS=LI.1.NUM_LANES
   
   TOTAL_VOL=ROUND(v1_1) ; directional volume
   COUNT_07 = COUNT   
  ; count=COMB_CNT
  ; IF (FT=7 ) COUNT=0

; initialize arrays and variables
   ARRAY _err=13, _cns=13, _cnt=13, _RGP=13, _volbyft=100, _cntbyft=100
   ARRAY _volbyat=100, _cntbyat=100, _lnkbyft=100, _lnkbyat=100
   _group=(0.0*FACILITY_TYPE)
   _RGP[1]=1, _RGP[2]=5000, _RGP[3]=10000, _RGP[4]=20000, _RGP[5]=30000, _RGP[6]=40000, _RGP[7]=50000,
   _RGP[8]=60000, _RGP[9]=70000, _RGP[10]=80000, _RGP[11]=90000, _RGP[12]=100000, _RGP[13]=500000
   IF (A=1)
     LOOP _iter=1,13
           _err[_iter]=0,_cnt[_iter]=0,_cns[_iter]=0
     ENDLOOP
     LOOP _iter=1,99
           _volbyft[_iter]=0, _cntbyft[_iter]=0, _lnkbyft[_iter]=0
           _volbyat[_iter]=0, _cntbyat[_iter]=0, _lnkbyat[_iter]=0
     ENDLOOP
   ENDIF
;   FNAME='ROADNAME'
; establish some English sounding variables for the output network
   links=1
   lanemiles=lns*distance
; calculate and compartmentalize 
   IF(COUNT>0) VOLCNT=TOTAL_VOL/COUNT, NETDIFF=TOTAL_VOL-COUNT, ABSDIFF=ABS(NETDIFF), ERRORSQ=NETDIFF^2, PCTDIFF=100*NETDIFF/COUNT _group=1
   IF (COUNT>5000) _group=2
   IF (COUNT>10000) _group=3
   IF (COUNT>20000) _group=4
   IF (COUNT>30000) _group=5
   IF (COUNT>40000) _group=6
   IF (COUNT>50000) _group=7
   IF (COUNT>60000) _group=8
   IF (COUNT>70000) _group=9
   IF (COUNT>80000) _group=10
   IF (COUNT>90000) _group=11
   IF (COUNT>100000) _group=12
   IF (COUNT>0) 
   _ERR[_group]=ERRORSQ+_ERR[_group], _CNS[_group]=COUNT+_CNS[_group], _CNT[_group]=_CNT[_group]+1
   _ERR[13]=ERRORSQ+_ERR[13], _CNS[13]=COUNT+_CNS[13], _CNT[13]=_CNT[13]+1
   ENDIF
IF (COUNT>0)  
   _volbyft[ft]=_volbyft[ft]+TOTAL_VOL
   _cntbyft[ft]=_cntbyft[ft]+count
   _lnkbyft[ft]=_lnkbyft[ft]+1
   _volbyat[at]=_volbyat[at]+TOTAL_VOL
   _cntbyat[at]=_cntbyat[at]+count
   _lnkbyat[at]=_lnkbyat[at]+1
   _volbyft[100]=_volbyft[100]+TOTAL_VOL
   _cntbyft[100]=_cntbyft[100]+count
   _lnkbyft[100]=_lnkbyft[100]+1
   _volbyat[100]=_volbyat[100]+TOTAL_VOL
   _cntbyat[100]=_cntbyat[100]+count
   _lnkbyat[100]=_lnkbyat[100]+1
endif
CROSSTAB  VAR= LINKS LANEMILES, form=12.0c,
    row=FT, range=10-99-10,
    col=LNS, range=1-5-1,6-9
IF (COUNT>0)
CROSSTAB  VAR= TOTAL_VOL,COUNT, form=12.0c,
    row=FT, range=10-99-10,
    col=AT, range=10-59-10
ENDIF
;if (count=0) delete

ENDPHASE

; =========================================================
; SUMMARY REPORTING
; =========================================================


PHASE=SUMMARY
; a little loop to write out the Percent Root Mean Square Error

LOOP _iter=1,12
if (_iter=1) _limit='45 - 55'
if (_iter=2) _limit='35 - 45'
if (_iter=3) _limit='27 - 35'
if (_iter=4) _limit='24 - 27'
if (_iter=5) _limit='22 - 24'
if (_iter=6) _limit='20 - 22'
if (_iter=7) _limit='18 - 20'
if (_iter=8) _limit='17 - 18'
if (_iter=9) _limit='16 - 17'
if (_iter=10) _limit='15 - 16'
if (_iter=11) _limit='14 - 15'
if (_iter=12) _limit='LT 14  '

  if (_iter=1) print list="*************************** ROOT MEAN SQUARE ERROR SUMMARY *****************************", printo=1
  if (_cnt[_iter]>0) print,
 list="  Percent RMSE for Volume Group ",_iter(2.0c)," ",_RGP[_iter](7.0c),"-",_RGP[_iter+1](7.0c),": ",sqrt(_err[_iter]/(_cnt[_iter]-1))/(_cns[_iter]/_cnt[_iter])*100(5.1),"%", " Allowable RMSE = ", _limit,"%    N=",_cnt[_iter](5.0CL), PRINTO=1



;ASR
;LOOP _iter=1,12
;  if (_iter=1) print list="*************************** ROOT MEAN SQUARE ERROR SUMMARY *****************************", printo=1
;  if (_cnt[_iter]>0) print,
; list="  Percent RMSE for Volume Group ",_iter(2.0c)," ",_RGP[_iter](7.0c),"-",_RGP[_iter+1](7.0c),": ",sqrt(_err[_iter]/_cnt[_iter])/(_cns[_iter]/_cnt[_iter])*100(5.1),"%,                      N=",_cnt[_iter](5.0CL), PRINTO=1

ENDLOOP
;
;*echo Mode Choice Done = %date%   %time%   >>{SCENARIO_DIR}\output\runtime.prn

;print list="Scenario  ",{ALT},"   Done by   ",%date%,%time%,printo=1 

if (_iter=13) _limit='32 - 39'
 list="  Percent RMSE for Volume Group ",_iter(2.0c)," ",_RGP[1](7.0c),"-",_RGP[_iter](7.0c),": ",sqrt(_err[_iter]/(_cnt[_iter]-1))/(_cns[_iter]/_cnt[_iter])*100(5.1),"%", " Allowable RMSE = ", _limit,"%    N=",,_cnt[_iter](5.0CL), PRINTO=1

;_iter=13
; list="  Percent RMSE for Volume Group ",_iter(2.0c)," ",_RGP[1](7.0c),"-",_RGP[_iter](7.0c),": ",sqrt(_err[_iter]/_cnt[_iter])/(_cns[_iter]/_cnt[_iter])*100(5.1),"%,                      N=",_cnt[_iter](5.0CL), PRINTO=1

; one for Vol/Cnt by FT 
_iter=0
LOOP _iter=1,100
  if (_iter=1) print list="\n","\n ********************** VOLUME AND COUNT SUMMARY BY FACILITY TYPE **********************", PRINTO=1
if (_cntbyft[_iter]>0) print,
 list="Facility Type Summary for FT=",_iter(3.0c),
 " VOL=",_volbyft[_iter](11.0c),
 " CNT=",_cntbyft[_iter](11.0c),
 " VOL/CNT=",(_volbyft[_iter]/_cntbyft[_iter])(5.2c),
 "   N=",_lnkbyft[_iter](5.0c), PRINTO=1
ENDLOOP




; one for Vol/Cnt by AT
_iter=0
LOOP _iter=1,100
  if (_iter=1) print list="\n","\n ************************* VOLUME AND COUNT SUMMARY BY AREA TYPE ************************", PRINTO=1
if (_cntbyat[_iter]>0) print,
 list="    Area Type Summary for AT=",_iter(3.0c),
 " VOL=",_volbyat[_iter](11.0c),
 " CNT=",_cntbyat[_iter](11.0c),
 " VOL/CNT=",(_volbyat[_iter]/_cntbyat[_iter])(5.2c),
 "   N=",_lnkbyat[_iter](5.0c), PRINTO=1
ENDLOOP


ENDPHASE

ENDRUN


; PILOT Script
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.



*echo Date: %date% >"{SCENARIO_DIR}\output\ModelRun_{alt}{year}.prnModelRun_{alt}{year}.prn"
*echo Time: %time% >>"{SCENARIO_DIR}\output\ModelRun_{alt}{year}.prn"
*echo NERPM Model Run - >>"{SCENARIO_DIR}\output\ModelRun_{alt}{year}.prn"
*echo Input Directory {SCENARIO_DIR}\input\ >>"{SCENARIO_DIR}\output\ModelRun_{alt}{year}.prn"
*echo ======================================================================================>>"{SCENARIO_DIR}\output\ModelRun_{alt}{year}.prn"

if ({IsAutoAccess}=1)
readotherpeaks=' '
else
readotherpeaks=';'
endif

if ({IsProjectMode}=1)
 ReadProjLoadedFile=' '
else
 ReadProjLoadedFile=';'
endif

if(({IsAutoAccess}=1) & ({IsProjectMode}=1))
DividyBy4=' '
else
DivideBy4=';'
endif

if(({IsAutoAccess}=0) & ({IsProjectMode}=0))
DividyBy1=' '
else
DivideBy1=';'
endif

if((({IsAutoAccess}=0) & ({IsProjectMode}=1)) | (({IsAutoAccess}=1) & ({IsProjectMode}=0)))
DividyBy2=' '
else
DivideBy2=';'
endif



; End of PILOT Script

; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TAMAT01C.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=MATRIX PRNFILE="X:\Projects\CRTPA\Model\C\APPLICATIONS\TAMAT00B.PRN" MSG='2) Read Date and Time'
FILEI RECI = "{SCENARIO_DIR}\output\ModelRun_{alt}{year}.prn"

; The MATRIX module does not have any explicit phases.  The module does run within an implied ILOOP
; where I is the origin zones.  All user statements in the module are processed once for each origin.
; Matrix computation (MW[#]=) are solved for all values of J for each I.  Thus for a given origin zone I
; the values for all destination zones J are automatically computed.  The user can control the computations
; at each J by using a JLOOP.

zones=1

s1=strpos('Date:',reci)
s2=strpos('Time:',reci)

; get the date and time
if (s1 > 0)
 rundate=substr(reci,s1,80)
 log prefix=date var=rundate
endif
if (s2 > 0) 
 runtime=substr(reci,s2,80)
 log prefix=time var=runtime
endif

;x=@matrix.rundate@
;print list=x

ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TAMAT01A.S"
; 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\TAMAT00A.PRN" MSG='3) Combine Peak and Off-Peak files'
FILEI DBI[1] = "{SCENARIO_DIR}\output\TLINKPK1_{alt}{year}.DBF"
FILEI DBI[6] = "{SCENARIO_DIR}\output\TLINKOP3_{alt}{year}.DBF"
FILEI DBI[5] = "{SCENARIO_DIR}\output\TLINKOP1_{alt}{year}.DBF"
FILEI DBI[2] = "{SCENARIO_DIR}\output\TLINKPK3_{alt}{year}.DBF"

; ***************************************************************************************************
; SCRIPT TO COMBINE THE PEAK FILES TO ONE PEAK FILE AND OFF-PEAK FILES TO ONE OFF-PEAK FILE
;****************************************************************************************************


;***************************************************************************************************
;DEFINE PEAK AND OFF-PEAK FILES AS INPUT AND COMBINED PEAK AND OFF-PEAK FILES AS OUTPUT FILES
;***************************************************************************************************



FILEO RECO[2] = "{SCENARIO_DIR}\OUTPUT\TLINKOP_{ALT}{YEAR}.DBF",
fields =   A , B, MODE,  OPERATOR , NAME , DIST,  TIME  ,   LINKSEQ   , HEADWAY ,   VOL1 ,VOL2 ,VOL3, VOL4,  STOPA ,  ONA1 ,ONA2 ,ONA3 , ONA4, OFFA1, OFFA2, OFFA3 , OFFA4, STOPB,   ONB1, ONB2, ONB3 , ONB4, OFFB1 ,OFFB2 ,OFFB3, OFFB4, REV_VOL1, REV_VOL2, REV_VOL3, REV_VOL4, REV_ONA1 ,REV_ONA2, REV_ONA3, REV_ONA4, REV_OFFA1, REV_OFFA2 ,REV_OFFA3 , REV_OFFA4, REV_ONB1, REV_ONB2, REV_ONB3 , REV_ONB4, REV_OFFB1 ,REV_OFFB2, REV_OFFB3, REV_OFFB4, index, 
cform=40.0 fields=longname
FILEO RECO[1] = "{SCENARIO_DIR}\OUTPUT\TLINKPK_{ALT}{YEAR}.DBF",
fields =   A , B, MODE,  OPERATOR , NAME , DIST,  TIME  ,   LINKSEQ   , HEADWAY ,   VOL1 ,VOL2 ,VOL3, VOL4,  STOPA ,  ONA1 ,ONA2 ,ONA3 , ONA4, OFFA1, OFFA2, OFFA3 , OFFA4, STOPB,   ONB1, ONB2, ONB3 , ONB4, OFFB1 ,OFFB2 ,OFFB3, OFFB4, REV_VOL1, REV_VOL2, REV_VOL3, REV_VOL4, REV_ONA1 ,REV_ONA2, REV_ONA3, REV_ONA4, REV_OFFA1, REV_OFFA2 ,REV_OFFA3 , REV_OFFA4, REV_ONB1, REV_ONB2, REV_ONB3 , REV_ONB4, REV_OFFB1 ,REV_OFFB2, REV_OFFB3, REV_OFFB4, index,
cform=40.0 fields=longname








;************************************
; MAIN SCRIPT AREA
;************************************


zones=1

;***********************************************
;READ IN DATA FROM PK1 FILE AND WRITE TO PK FILE
;***********************************************

loop k=1,DBI.1.NUMRECORDS
 x=DBIReadRecord(1,k)
if(di.1.mode >20)
 RO.A = DI.1.A
 RO.B=DI.1.B
 RO.MODE=DI.1.MODE
 RO.OPERATOR=DI.1.OPERATOR
 RO.NAME=DI.1.NAME
 RO.LONGNAME=DI.1.LONGNAME
 RO.DIST=DI.1.DIST
 RO.LINKSEQ=DI.1.LINKSEQ
 RO.STOPA=DI.1.STOPA
 RO.STOPB=DI.1.STOPB
 RO.TIME=DI.1.TIME

 RO.HEADWAY=DBI.1.NFIELD[10]
 RO.VOL1=DI.1.VOL
 RO.ONA1=DI.1.ONA
 RO.OFFA1=DI.1.OFFA
 RO.ONB1=DI.1.ONB
 RO.OFFB1=DI.1.OFFB
 RO.REV_VOL1=DI.1.REV_VOL
 RO.REV_ONA1=DI.1.REV_ONA
 RO.REV_ONB1=DI.1.REV_ONB
 RO.REV_OFFA1=DI.1.REV_OFFA
 RO.REV_OFFB1=DI.1.REV_OFFB
 ro.index=k
 write reco=1
endif
endloop


;***********************************************
;READ IN DATA FROM PK2 FILE AND WRITE TO PK FILE
;***********************************************



loop k=1,DBI.2.NUMRECORDS
 x=DBIReadRecord(2,k)
 if(di.2.mode >20)
  RO.A = DI.2.A
  RO.B=DI.2.B
  RO.MODE=DI.2.MODE
  RO.OPERATOR=DI.2.OPERATOR
  RO.NAME=DI.2.NAME
  RO.LONGNAME=DI.2.LONGNAME
  RO.DIST=DI.2.DIST
  RO.LINKSEQ=DI.2.LINKSEQ
  RO.STOPA=DI.2.STOPA
  RO.STOPB=DI.2.STOPB
  RO.TIME=DI.2.TIME

  RO.HEADWAY=DBI.2.NFIELD[10]
  RO.VOL2=DI.2.VOL
  RO.ONA2=DI.2.ONA
  RO.OFFA2=DI.2.OFFA
  RO.ONB2=DI.2.ONB
  RO.OFFB2=DI.2.OFFB
  RO.REV_VOL2=DI.2.REV_VOL
  RO.REV_ONA2=DI.2.REV_ONA
  RO.REV_ONB2=DI.2.REV_ONB
  RO.REV_OFFA2=DI.2.REV_OFFA
  RO.REV_OFFB2=DI.2.REV_OFFB
  RO.VOL1=0
  RO.ONA1=0
  RO.OFFA1=0

  RO.ONB1=0
  RO.OFFB1=0
  RO.REV_VOL1=0
  RO.REV_ONA1=0

  RO.REV_ONB1=0
  RO.REV_OFFA1=0
  RO.REV_OFFB1=0
  ro.index=k

  write reco =1
 endif
endloop



;***********************************************
;READ IN DATA FROM OP1 FILE AND WRITE TO OP FILE
;***********************************************

loop k=1,DBI.5.NUMRECORDS
 x=DBIReadRecord(5,k)
 if(di.5.mode >20)
 RO.A=DBI.5.NFIELD[1]
 RO.B=DBI.5.NFIELD[2]
 RO.MODE=DBI.5.NFIELD[3]
 RO.OPERATOR=DBI.5.NFIELD[4]
 RO.NAME=DBI.5.CFIELD[5]
 RO.LONGNAME=DBI.5.CFIELD[6]
 RO.DIST=DBI.5.NFIELD[7]
 RO.LINKSEQ=DBI.5.NFIELD[9]
 RO.STOPA=DI.5.STOPA
 RO.STOPB=DI.5.STOPB
 RO.TIME=DBI.5.NFIELD[8]
 
 RO.HEADWAY=DBI.5.NFIELD[10] 

 RO.VOL1=DI.5.VOL
 RO.ONA1=DI.5.ONA
 RO.OFFA1=DI.5.OFFA
 RO.ONB1=DI.5.ONB
 RO.OFFB1=DI.5.OFFB
 RO.REV_VOL1=DI.5.REV_VOL
 RO.REV_ONA1=DI.5.REV_ONA
 RO.REV_ONB1=DI.5.REV_ONB
 RO.REV_OFFA1=DI.5.REV_OFFA
 RO.REV_OFFB1=DI.5.REV_OFFB
 ro.index=k


RO.VOL2=0
RO.ONA2=0
RO.OFFA2=0
RO.ONB2=0
RO.OFFB2=0
RO.REV_VOL2=0
RO.REV_ONA2=0
RO.REV_ONB2=0
RO.REV_OFFA2=0
RO.REV_OFFB2=0

 write reco=2
endif
endloop



;***********************************************
;READ IN DATA FROM OP2 FILE AND WRITE TO OP FILE
;***********************************************



loop k=1,DBI.6.NUMRECORDS
x=DBIReadRecord(6,k)
if(di.6.mode >20)
RO.A=DBI.6.NFIELD[1]
RO.B=DBI.6.NFIELD[2]
RO.MODE=DBI.6.NFIELD[3]
RO.OPERATOR=DBI.6.NFIELD[4]
RO.NAME=DBI.6.CFIELD[5]
RO.LONGNAME=DBI.6.CFIELD[6]
RO.DIST=DBI.6.NFIELD[7]
RO.LINKSEQ=DBI.6.NFIELD[9]
RO.STOPA=DI.6.STOPA
RO.STOPB=DI.6.STOPB
RO.TIME=DBI.6.NFIELD[8]
 
RO.HEADWAY=DBI.6.NFIELD[10] 
RO.VOL2=DI.6.VOL
RO.ONA2=DI.6.ONA
RO.OFFA2=DI.6.OFFA
RO.ONB2=DI.6.ONB
RO.OFFB2=DI.6.OFFB
RO.REV_VOL2=DI.6.REV_VOL
RO.REV_ONA2=DI.6.REV_ONA
RO.REV_ONB2=DI.6.REV_ONB
RO.REV_OFFA2=DI.6.REV_OFFA
RO.REV_OFFB2=DI.6.REV_OFFB

RO.VOL1=0
RO.ONA1=0
RO.OFFA1=0
RO.ONB1=0
RO.OFFB1=0
RO.REV_VOL1=0
RO.REV_ONA1=0
RO.REV_ONB1=0
RO.REV_OFFA1=0
RO.REV_OFFB1=0
ro.index=k
write reco=2
endif
endloop



;endif
;*******************************************************************************************
; REACHED END OF SCRIPT
;*******************************************************************************************



ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TAMAT01B.S"
; 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\TAMAT00C.PRN" MSG='4) Print transit assignment summary files'

; ***************************************************************************************************
; SCRIPT TO SUMMARIZE THE PEAK OFF-PEAK TRANSIT ASSIGNMENT BY ROUTE, MODE, OPERATOR, AND STOPS
;****************************************************************************************************


;****************************************************************************************************
; INPUT FILES: PEAK FILE              TLINKPK_{ALT}{YEAR}.PRN
;              OFF-PEAK FILE          TLINKOP_{ALT}{YEAR}.PRN

;OUTPUT FILES: ROUTE LEVEL SUMMARY   tasroute_{alt}{year}.prn
;              STOP LEVEL SUMMARY    tasum_{alt}{year}.prn
;****************************************************************************************************


FILEO PRINTO[2] = "{SCENARIO_DIR}\OUTPUT\TASUM_{ALT}{YEAR}.PRN"
FILEO PRINTO[1] = "{SCENARIO_DIR}\OUTPUT\TASROUTE_{ALT}{YEAR}.PRN"
FILEI DBI[2] = "{SCENARIO_DIR}\OUTPUT\TLINKOP_{ALT}{YEAR}.DBF",
sort=NAME,index 
FILEI DBI[1] = "{SCENARIO_DIR}\OUTPUT\TLINKPK_{ALT}{YEAR}.DBF",
sort=NAME,index 

;********************************************************
; DEFINE ALL ROUTE-LEVEL ARRAYS WITH SIZE AS MAX. NO. OF ROUTES (500)
;********************************************************

array routename= 500-16
array routelname=500-40
array dist  = 500
array time = 500
array mode = 500
array operator = 500
array freq=500
array pax=500
array paxmi=500
array paxhr=500
array timeO = 500
array modeo = 500
array operatoro = 500
array freqo=500
array paxO=500
array paxmiO=500
array paxhrO=500
ARRAY MAXLD=dbi.1.numrecords
ARRAY MAXLDO=500
array routestart=500
array routeend=500

;********************************************************
; DEFINE ALL MODE-LEVEL ARRAYS WITH SIZE AS MAX. NO. OF MODES (200)
;********************************************************
array modelist1=200
array operlist1=200
ARRAY MODELIST=200
ARRAY MDIST=200
ARRAY MTIME=200
ARRAY MPAX=200
ARRAY MPAXMI=200
ARRAY MPAXHR=200
ARRAY MTIMEO=200
ARRAY MPAXO=200
ARRAY MPAXMIO=200
ARRAY MPAXHRO=200


;********************************************************
; DEFINE ALL OPERATOR-LEVEL ARRAYS WITH SIZE AS MAX. NO. OF OPERATORS (200)
;********************************************************

ARRAY OPERLIST=200
ARRAY ODIST=200
ARRAY OTIME=200
ARRAY OPAX=200
ARRAY OPAXMI=200
ARRAY OPAXHR=200
ARRAY OTIMEO=200
ARRAY OPAXO=200
ARRAY OPAXMIO=200
ARRAY OPAXHRO=200


;********************************************************
; DEFINE ALL STOP-LEVEL ARRAYS WITH SIZE AS NO. OF DATAPOINTS (dbi.(1 OR 2).numrecords
;********************************************************

array rtnumber=dbi.1.numrecords
array node=dbi.1.numrecords
array cumdist=dbi.1.numrecords
array tempdist=dbi.1.numrecords
array temptime=dbi.1.numrecords
array onasum=dbi.1.numrecords
array onarecord=dbi.1.numrecords
array offasum=dbi.1.numrecords
array offarecord=dbi.1.numrecords
array load=dbi.1.numrecords
array distan=dbi.1.numrecords
array timean=dbi.1.numrecords
array volrecord=dbi.1.numrecords

array rtnumbero=dbi.2.numrecords
array nodeo=dbi.2.numrecords
array cumdisto=dbi.2.numrecords
array tempdisto=dbi.2.numrecords
array temptimeo=dbi.2.numrecords
array onasumo=dbi.2.numrecords
array onarecordo=dbi.2.numrecords
array offasumo=dbi.2.numrecords
array offarecordo=dbi.2.numrecords
array loado=dbi.2.numrecords
array distano=dbi.2.numrecords
array timeano=dbi.2.numrecords
array volrecordo=dbi.2.numrecords

array offbspl=dbi.1.numrecords
array offbsplo=dbi.2.numrecords
array loadspl=dbi.1.numrecords
array loadsplo=dbi.2.numrecords
array offBrecord=dbi.1.numrecords
array offBrecordo=dbi.2.numrecords
array bnode=dbi.1.numrecords
;************************************
; MAIN SCRIPT AREA
;************************************
zones=1
numroute = 1 
ROUTENUM=1
ROUTENUMO=1
NUMROUTEO=1
zero=0
;**********************************************
; BEGIN LOOP TO DETERMINE THE NUMBER OF ROUTES IN PEAK PERIOD
;**********************************************

LOOP k=1,DBI.1.NUMRECORDS
    x=DBIReadRecord(1,k)
;if(di.1.mode >20)
   
  if ( k =1 ) 
     prevroute=di.1.name
 endif

   IF  (prevroute = di.1.name)
        NUMROUTE=NUMROUTE
   ELSE
      
        NUMROUTE=NUMROUTE+1
        prevroute = di.1.name
   ENDIF
;endif
ENDLOOP

PRINT LIST=NUMROUTE
;********************************************
; END LOOP TO DETERMINE THE NUMBER OF ROUTES
;********************************************

;**********************************************
; BEGIN LOOP TO DETERMINE THE NUMBER OF ROUTES IN OFF-PEAK PERIOD
;**********************************************

LOOP k=1,DBI.2.NUMRECORDS

    x=DBIReadRecord(2,k)
;if(di.2.mode >20)   
  if ( k =1 ) 
     prevroute=di.2.name
 endif

   IF  (prevroute = di.2.name)
        NUMROUTEO=NUMROUTEO
   ELSE
      
        NUMROUTEO=NUMROUTEO+1
        prevroute = di.2.name
   ENDIF
;endif
ENDLOOP

;PRINT LIST=NUMROUTEO, "NUMROUTEO"
;********************************************
; END LOOP TO DETERMINE THE NUMBER OF ROUTES
;********************************************

;******************************************************************************************************
; BEGIN LOOP TO CALCULATE DIST, TIME, VOL, FREQUENCY, PAX, PAXMI, PAXHR, MAXLD FOR PEAK PERIOD BY ROUTE
;******************************************************************************************************

loop k=1,DBI.1.NUMRECORDS
     x=DBIReadRecord(1,k)

;if(di.1.mode >20)  
  _modenumber=di.1.mode
 
     if ( k =1 ) 
       prevroute=di.1.name
       routestart[k]=di.1.a      
     endif

     if ( prevroute = di.1.name)
       rtnumber[k]=routenum
       node[k]=di.1.a
       routename[ROUTENUM]=di.1.name
       routelname[ROUTENUM]=di.1.longname  
       mode[ROUTENUM]=di.1.mode
       operator[ROUTENUM]=di.1.operator
       freq[ROUTENUM]= di.1.headway
       dist[ROUTENUM]=dist[ROUTENUM]+di.1.dist       
       time[ROUTENUM]=time[ROUTENUM]+di.1.time
       pax[ROUTENUM]=pax[ROUTENUM]+di.1.ona1+di.1.ona2+di.1.ona3+di.1.ona4
       paxmi[ROUTENUM]=paxmi[ROUTENUM]+di.1.vol1*di.1.dist+di.1.vol2*di.1.dist+di.1.vol3*di.1.dist+di.1.vol4*di.1.dist
       paxhr[ROUTENUM]=paxhr[ROUTENUM]+(di.1.vol1*di.1.time+di.1.vol2*di.1.time+di.1.vol3*di.1.time+di.1.vol4*di.1.time)/60
         ; IF(MAXLD[ROUTENUM] < DI.1.VOL1+DI.1.VOL2+DI.1.VOL3) 
         ;        MAXLD[ROUTENUM]=DI.1.VOL1+DI.1.VOL2+DI.1.VOL3
         ; ENDIF
       routeend[routenum]=di.1.b
    else 
       ROUTENUM = ROUTENUM + 1
       routestart[routenum]=di.1.a       
       routename[ROUTENUM]=di.1.name 
       routelname[ROUTENUM]=di.1.longname
       node[k]=di.1.a
       rtnumber[k]=routenum
       prevroute = di.1.name
       dist[ROUTENUM]=di.1.dist      
       time[ROUTENUM]=di.1.time
       pax[ROUTENUM]=di.1.ona1+di.1.ona2+di.1.ona3+di.1.ona4
       paxmi[ROUTENUM]=di.1.vol1*di.1.dist+di.1.vol2*di.1.dist+di.1.vol3*di.1.dist+di.1.vol4*di.1.dist
       paxhr[ROUTENUM]=(di.1.vol1*di.1.time+di.1.vol2*di.1.time+di.1.vol3*di.1.timE+di.1.vol4*di.1.time)/60  
      ; MAXLD[ROUTENUM]=DI.1.VOL1+DI.1.VOL2+DI.1.VOL3  
    endif

;  MDIST[_modenumber]=MDIST[_modenumber]+di.1.DIST

  onarecord[k]=di.1.ona1+di.1.ona2+di.1.ona3+di.1.ona4
  offarecord[k]=di.1.offa1+di.1.offa2+di.1.offa3 +di.1.offa4
  volrecord[k]=di.1.vol1+di.1.vol2+di.1.vol3+di.1.vol4
OFFBRECORD[K]=DI.1.OFFB1+DI.1.OFFB2+DI.1.OFFB3+DI.1.OFFB4

  ;endif
endloop


;******************************************************************************************************
; END LOOP TO CALCULATE DIST, TIME, VOL, FREQUENCY, PAX, PAXMI, PAXHR, MAXLD FOR PEAK PERIOD BY ROUTE
;******************************************************************************************************

;******************************************************************************************************
; BEGIN LOOP TO CALCULATE DIST, TIME, VOL, FREQUENCY, PAX, PAXMI, PAXHR, MAXLD FOR OFF-PEAK PERIOD BY ROUTE
;******************************************************************************************************

loop k=1,DBI.2.NUMRECORDS
     x=DBIReadRecord(2,k)
 ;if(di.2.mode >20)    
     if ( k =1 ) 
       prevrouteO=di.2.name
      ; prevmode
     endif

     if ( prevrouteO = di.2.name)
      ; routename[ROUTENUM]=di.2.name 
      ; mode[ROUTENUM]=di.2.mode
      ; operator[ROUTENUM]=di.2.operator
       freqO[ROUTENUMO]= di.2.headway
     ;  dist[ROUTENUM]=dist[ROUTENUM]+di.2.dist
       timeO[ROUTENUMO]=timeO[ROUTENUMO]+di.2.time
       paxO[ROUTENUMO]=paxO[ROUTENUMO]+di.2.ona1+di.2.ona2+di.2.ona3+di.2.ona4
       paxmiO[ROUTENUMO]=paxmiO[ROUTENUMO]+di.2.vol1*di.2.dist+di.2.vol2*di.2.dist+di.2.vol3*di.2.dist+di.2.vol4*di.2.dist
       paxhrO[ROUTENUMO]=paxhrO[ROUTENUMO]+(di.2.vol1*di.2.time+di.2.vol2*di.2.time+di.2.vol3*di.2.time+di.2.vol4*di.2.time)/60
           ; IF(MAXLDO[ROUTENUMO] < DI.2.VOL1+DI.2.VOL2+DI.2.VOL3) 
           ;      MAXLDO[ROUTENUMO]=DI.2.VOL1+DI.2.VOL2+DI.2.VOL3
         ; ENDIF

    else 
       ROUTENUMO = ROUTENUMO + 1
       prevrouteO = di.2.name
       ;dist[ROUTENUM]=di.2.dist
       timeO[ROUTENUMO]=di.2.time
       paxO[ROUTENUMO]=di.2.ona1+di.2.ona2+di.2.ona3+di.2.ona4
       paxmiO[ROUTENUMO]=di.2.vol1*di.2.dist+di.2.vol2*di.2.dist+di.2.vol3*di.2.dist+di.2.vol4*di.2.dist
       paxhrO[ROUTENUMO]=(di.2.vol1*di.2.time+di.2.vol2*di.2.time+di.2.vol3*di.2.time+di.2.vol4*di.2.time)/60  
     ; MAXLDO[ROUTENUMO]=DI.2.VOL1+DI.2.VOL2+DI.2.VOL3  
    endif

  onarecordo[k]=di.2.ona1+di.2.ona2+di.2.ona3+di.2.ona4
  offarecordo[k]=di.2.offa1+di.2.offa2+di.2.offa3+di.2.offa4 
  volrecordo[k]=di.2.vol1+di.2.vol2+di.2.vol3+di.2.vol4
 OFFBRECORDO[K]=DI.2.OFFB1+DI.2.OFFB2+DI.2.OFFB3+DI.2.OFFB4

;endif
endloop

;********************************************************************************************************
; END LOOP TO CALCULATE DIST, TIME, VOL, FREQUENCY, PAX, PAXMI, PAXHR, MAXLD FOR OFF-PEAK PERIOD BY ROUTE
;********************************************************************************************************

;*********************************************************************************************************
; BEGIN LOOP TO CALCULATE DIST,TIME,PAX,PAXMI,PAXHR FOR PEAK PERIOD BY MODE
;*********************************************************************************************************

NUMMODE=1

LOOP k=1,NUMROUTE
 ;print list=k,routestart[k],routeend[k]  
;if( mode[k]>20) 
 if ( k =1 ) 
     MODELIST[NUMMODE]=MODE[K]
 endif

     FLAG=0

 LOOP Y=1,NUMMODE
     IF(MODELIST[Y] = MODE[K])
         FLAG=FLAG+1
         MDIST[Y]=MDIST[Y]+DIST[K]
         MTIME[Y]=MTIME[Y]+TIME[K]
         MPAX[Y]=MPAX[Y]+PAX[K]
         MPAXMI[Y]=MPAXMI[Y]+PAXMI[K]
         MPAXHR[Y]=MPAXHR[Y]+PAXHR[K]
         MTIMEO[Y]=MTIMEO[Y]+TIMEO[K]
         MPAXO[Y]=MPAXO[Y]+PAXO[K]
         MPAXMIO[Y]=MPAXMIO[Y]+PAXMIO[K]
         MPAXHRO[Y]=MPAXHRO[Y]+PAXHRO[K]

     ENDIF
 ENDLOOP


 IF (FLAG == 0) 
     NUMMODE=NUMMODE+1
     MODELIST[NUMMODE]=MODE[K]
     MDIST[NUMMODE]=DIST[K]
     MTIME[NUMMODE]=TIME[K]
     MPAX[NUMMODE]=PAX[K]
     MPAXMI[NUMMODE]=PAXMI[K]
     MPAXHR[NUMMODE]=PAXHR[K]
     MTIMEO[NUMMODE]=TIMEO[K]
     MPAXO[NUMMODE]=PAXO[K]
     MPAXMIO[NUMMODE]=PAXMIO[K]
     MPAXHRO[NUMMODE]=PAXHRO[K]

 ENDIF
;endif
 ENDLOOP

loop ind=1,nummode
    mdistsum=mdistsum+mdist[ind]
    mtimesum=mtimesum+mtime[ind]
    mpaxsum=mpaxsum+mpax[ind]
    mpaxmisum=mpaxmisum+mpaxmi[ind]
    mpaxhrsum=mpaxhrsum+mpaxhr[ind]
    mtimeosum=mtimeosum+mtimeo[ind]
    mpaxosum=mpaxosum+mpaxo[ind]
    mpaxmiosum=mpaxmiosum+mpaxmio[ind]
    mpaxhrosum=mpaxhrosum+mpaxhro[ind]

  endloop

loop k=1,nummode
modelist1[k]=modelist[k]
endloop 


IF (NUMMODE=1)
MODELIST1[1]=MODELIST[1]
ELSE
loop l=1,nummode
loop m=1,nummode-1
if(modelist1[m+1]<=modelist1[m])
tempe=modelist1[m]
modelist1[m]=modelist1[m+1]
exec=m+1
modelist1[exec]=tempe
endif
endloop
endloop
ENDIF

;*********************************************************************************************************
; END LOOP TO CALCULATE DIST,TIME,PAX,PAXMI,PAXHR FOR PEAK PERIOD BY MODE
;*********************************************************************************************************

;*********************************************************************************************************
; BEGIN LOOP TO CALCULATE DIST,TIME,PAX,PAXMI,PAXHR FOR PEAK PERIOD BY OPERATOR
;*********************************************************************************************************

NUMOPER=1

LOOP k=1,NUMROUTE
  ; if(mode[k]>20)  
 if ( k =1 ) 
     OPERLIST[NUMoper]=OPERATOR[K]
 endif

     FLAG=0

 LOOP Y=1,NUMOPER
     IF(OPERLIST[Y] = OPERATOR[K])
         FLAG=FLAG+1
         ODIST[Y]=ODIST[Y]+DIST[K]
         OTIME[Y]=OTIME[Y]+TIME[K]
         OPAX[Y]=OPAX[Y]+PAX[K]
         OPAXMI[Y]=OPAXMI[Y]+PAXMI[K]
         OPAXHR[Y]=OPAXHR[Y]+PAXHR[K]
         OTIMEO[Y]=OTIMEO[Y]+TIMEO[K]
         OPAXO[Y]=OPAXO[Y]+PAXO[K]
         OPAXMIO[Y]=OPAXMIO[Y]+PAXMIO[K]
         OPAXHRO[Y]=OPAXHRO[Y]+PAXHRO[K]

     ENDIF
 ENDLOOP


 IF (FLAG == 0) 
     NUMOPER=NUMOPER+1
     OPERLIST[NUMOPER]=OPERATOR[K]    
     ODIST[NUMOPER]=DIST[K]
     OTIME[NUMOPER]=TIME[K]
     OPAX[NUMOPER]=PAX[K]
     OPAXMI[NUMOPER]=PAXMI[K]
     OPAXHR[NUMOPER]=PAXHR[K]
     OTIMEO[NUMOPER]=TIMEO[K]
     OPAXO[NUMOPER]=PAXO[K]
     OPAXMIO[NUMOPER]=PAXMIO[K]
     OPAXHRO[NUMOPER]=PAXHRO[K]


 ENDIF
;endif
ENDLOOP

loop ind=1,numoper
    odistsum=odistsum+odist[ind]
    otimesum=otimesum+otime[ind]
    opaxsum=opaxsum+opax[ind]
    opaxmisum=opaxmisum+opaxmi[ind]
    opaxhrsum=opaxhrsum+opaxhr[ind]
    otimeosum=otimeosum+otimeo[ind]
    opaxosum=opaxosum+opaxo[ind]
    opaxmiosum=opaxmiosum+opaxmio[ind]
    opaxhrosum=opaxhrosum+opaxhro[ind]

  endloop

loop k=1,numoper
operlist1[k]=operlist[k]
endloop 

IF(NUMOPER=1)
OPERLIST1[1]=OPERLIST[1]
ELSE
loop l=1,numoper
loop m=1,numoper-1
if(operlist1[m+1]<operlist1[m])
tempe=operlist1[m]
operlist1[m]=operlist1[m+1]
exec=m+1
operlist1[exec]=tempe
endif
endloop
endloop
ENDIF
;*********************************************************************************************************
; END LOOP TO CALCULATE DIST,TIME,PAX,PAXMI,PAXHR FOR PEAK PERIOD BY OPERATOR
;*********************************************************************************************************

;*********************************************************************************************************
; BEGIN LOOP TO CALCULATE CUMDIST,CUMTIME,ON,OFF,LOAD FOR PEAK PERIOD BY STOP
;*********************************************************************************************************
temproute=1



loop k=1,DBI.1.NUMRECORDS/2
 x=DBIReadRecord(1,(2*k-1))


;if(di.1.mode >20)  

              if ( (2*k-1) =1 )


               prevroute=di.1.name
               prevnode=0
               tempdist[k]=di.1.dist
               temptime[k]=di.1.time
               onasum[k]=di.1.ona1+di.1.ona2+di.1.ona3+di.1.ona4+onarecord[2*k]

               offasum[k]=di.1.offa1+di.1.offa2+di.1.offa3+di.1.offa4+offarecord[2*k]



    load[k]=volrecord[2*k-1]+volrecord[2*k]
 
           
               rtnumber[k]=temproute
               MAXLD[1]=load[k]
              endif 


  if (prevroute = di.1.name) 

      if(k != 1)
             rtnumber[k]=temproute
             tempdist[k]=tempdist[k-1]+di.1.dist 
             temptime[k]=temptime[k-1]+di.1.time 


             onasum[k]=di.1.ona1+di.1.ona2+di.1.ona3+di.1.ona4+onarecord[2*k]
             offasum[k]=di.1.offa1+di.1.offa2+di.1.offa3+di.1.offa4+offarecord[2*k]

    
         
             load[k]=volrecord[2*k-1]+volrecord[2*k]
             node[k]=di.1.a
      endif
     
      IF(maxld[temproute] < load[k]) 
             maxld[temproute]=load[k]
          ENDIF

       ; if(routestart[rtnumber[k]]==routeend[rtnumber[k]])
            loadspl[k]=load[k]-OFFBRECORD[2*K-1]-OFFBRECORD[2*K]
            offbspl[k]=OFFBRECORD[2*K-1]+OFFBRECORD[2*K]

      ; else
           ; loadspl[k]=0
          ;  offbspl[k]=load[k]
      ; endif


    else
       temproute = temproute + 1
       node[k]=di.1.a
       prevnode=node[k]
       rtnumber[k]=temproute
       prevroute = di.1.name
       tempdist[k]=di.1.dist
       temptime[k]=di.1.time       

 
       onasum[k]=di.1.ona1+di.1.ona2+di.1.ona3+di.1.ona4+onarecord[2*k]
       offasum[k]=di.1.offa1+di.1.offa2+di.1.offa3+di.1.offa4+offarecord[2*k]
 

    
      ;print list=rtnumber[k],routestart[rtnumber[k]],routeend[rtnumber[k]]
       if(routestart[rtnumber[k]]==routeend[rtnumber[k]])
      ; print list="in",rtnumber[k],volrecord[3*k-2],onasum[3*k-2],offasum[3*k-2]

       load[k]=volrecord[2*k-1]+volrecord[2*k]
      
       else

       load[k]=volrecord[2*k-1]+volrecord[2*k]
      

       endif
       loadspl[k]=load[k]-OFFBRECORD[K]
       offbspl[k]=OFFBRECORD[K]
       MAXLD[temproute]=load[k]  
  endif
bnode[k]=di.1.b
 distan[k]=di.1.dist
 timean[k]=di.1.time
 ;print list=k,rtnumber[k],load[k],maxld[k]

;endif
endloop


;*********************************************************************************************************
; END LOOP TO CALCULATE CUMDIST,CUMTIME,ON,OFF,LOAD FOR PEAK PERIOD BY STOP
;*********************************************************************************************************

;*********************************************************************************************************
; BEGIN LOOP TO CALCULATE CUMDIST,CUMTIME,ON,OFF,LOAD FOR OFF-PEAK PERIOD BY STOP
;*********************************************************************************************************
temprouteo=1



 loop k=1,DBI.2.NUMRECORDS/2
 x=DBIReadRecord(2,(2*k-1))

;if(di.2.mode >20)  

     if ( (2*k-1) =1 ) 


       prevrouteo=di.2.name
       prevnodeo=0
       tempdisto[k]=di.2.dist
       temptimeo[k]=di.2.time
       onasumo[k]=di.2.ona1+di.2.ona2+di.2.ona3+di.2.ona4+onarecordo[2*k]

       offasumo[k]=di.2.offa1+di.2.offa2+di.2.offa3+di.2.offa4+offarecordo[2*k]



      loado[k]=volrecordo[2*k-1]+volrecordo[2*k]



       rtnumbero[k]=temprouteo
       MAXLDo[1]=loado[k]
     endif 




  if (prevrouteo = di.2.name) 

      if(k != 1)
             rtnumbero[k]=temprouteo
             tempdisto[k]=tempdisto[k-1]+di.2.dist 
             temptimeo[k]=temptimeo[k-1]+di.2.time 


            onasumo[k]=di.2.ona1+di.2.ona2+di.2.ona3+di.2.ona4+onarecordo[2*k]
            offasumo[k]=di.2.offa1+di.2.offa2+di.2.offa3+di.2.offa4+offarecordo[2*k]


             loado[k]=volrecordo[2*k-1]+volrecordo[2*k]
             nodeo[k]=di.2.a
             
      endif

      IF(maxldo[temprouteo] < loado[k]) 
             maxldo[temprouteo]=loado[k]
      ENDIF

     ; if(routestart[rtnumbero[k]]==routeend[rtnumbero[k]])
            loadsplo[k]=loado[k]-OFFBRECORDO[2*K]-OFFBRECORDO[2*K-1]
            offbsplo[k]=OFFBRECORDO[2*K]+OFFBRECORDO[2*K-1]
      ; else
       ;     loadsplo[k]=0
        ;    offbsplo[k]=loado[k]
       ;endif


  else
       temprouteo = temprouteo + 1
       nodeo[k]=di.2.a
       prevnodeo=nodeo[k]
       rtnumbero[k]=temprouteo
       prevrouteo = di.2.name
       tempdisto[k]=di.2.dist
       temptimeo[k]=di.2.time
       

 
      onasumo[k]=di.2.ona1+di.2.ona2+di.2.ona3+di.2.ona4+onarecordo[2*k]
       offasumo[k]=di.2.offa1+di.2.offa2+di.2.offa3+di.2.offa4+offarecordo[2*k]



      loado[k]=volrecordo[2*k-1]+volrecordo[2*k]

       if(routestart[rtnumbero[k]]==routeend[rtnumbero[k]])
      ; print list="in",rtnumber[k],volrecord[3*k-2],onasum[3*k-2],offasum[3*k-2]

       loado[k]=volrecordo[2*k-1]+volrecordo[2*k]
            

      else
       loado[k]=volrecordo[2*k-1]+volrecordo[2*k]
      ;  loadsplo[k]=0
       ; offbsplo[k]=loado[k]
      endif
            loadsplo[k]=loado[k]-OFFBRECORDO[K]
            offbsplo[k]=OFFBRECORDO[K]
       MAXLDo[temprouteo]=loado[k]  

  endif

 distano[k]=di.2.dist
 timeano[k]=di.2.time
;endif
endloop

;loop k=1,numroute

;*********************************************************************************************************
; END LOOP TO CALCULATE CUMDIST,CUMTIME,ON,OFF,LOAD FOR OFF-PEAK PERIOD BY STOP
;*********************************************************************************************************


;*********************************************************************************************************
;*********************************************************************************************************
; ALL CALCULATIONS COMPLETE. PRINT OUT ALL RESULTS
;*********************************************************************************************************
;*********************************************************************************************************


;*******************************************************************************************
; BEGIN PRINTING ROUTE LEVEL OUTPUT FILE 
;*******************************************************************************************
PRINT LIST= "Transit Assignment Summary Report", printo=2
print list="\n\n",printo=2
print list="Title : ",'{SCENARIO_FULLNAME}',printo=2
print list="Alternative : ",'{alt}',printo=2
print list="Year : ",'{year}',printo=2
print list="\n",printo=2
print list='@date.rundate@', printo=2
print list='@time.runtime@',printo=2
;print list="\n",printo=2
;PRINT LIST= "Transit Assignment Summary Report", printo=2
;print list="Route Level Summary",printo=2
print list="\n\n",printo=2
print list="                                        ",
      list="------------------------ Peak ------------------------"(60.0R),
      list="---------------------- Off-peak ----------------------"(60.2R),
      list="-------------- Daily --------------"(40.0R),printo=2

print list="Route Name "(16.0R),"    ","Mode"(5.0R),"Optr"(5.0R),"Dist"(10.0R),
           "Time"(10.0R),"Freq"(10.0R),"Pax"(10.0R),"MaxLd"(10.0R),"PaxMi"(10.0R),"PaxHr"(10.0R),
           "Time"(10.0R),"Freq"(10.0R),"Pax"(10.0R),"MaxLd"(10.0R),"PaxMi"(10.0R),"PaxHr"(10.0R),
           "Pax"(10.0R),"MaxLd"(10.0R),"PaxMi"(10.0R),"PaxHr"(10.0R),
           "Route LongName                        "(40.0R),
           printo=2
print list="                              ",
           "(mi)"(10.0R),
           "(min)"(10.0R),"(min)"(10.0R)," "(10.0R)," "(10.0R)," "(10.0R)," "(10.0R),
           "(min)"(10.0R),"(min)"(10.0R)," "(10.0R)," "(10.0R)," "(10.0R)," "(10.0R),
           printo=2
           

loop k=1,NUMROUTE
print cform=16.0 list=routename[k],"    ",
      form=5.0 list=mode[k],operator[k],

     form=10.2 list=dist[k]/2,time[k]/2,

      form=10.1 list=freq[k],pax[k],maxld[k],paxmi[k],paxhr[k], 

      form=10.2 list=timeo[k]/2,

      form=10.1 list=freqo[k],paxo[k],maxldo[k],paxmio[k],paxhro[k],pax[k]+paxo[k],max(maxld[k],maxldo[k]),
                     paxmi[k]+paxmio[k],paxhr[k]+paxhro[k],
      "  ",
      cform=40.0R list=routelname[k],
      printo=2
endloop
  
print list="\n\n\n\n",printo=2

print list="\f",printo=2
print list="Title : ",'{SCENARIO_FULLNAME}',printo=2
print list="Alternative : ",'{alt}',printo=2
print list="Year : ",'{year}',printo=2
print list="\n",printo=2
print list='@date.rundate@', printo=2
print list='@time.runtime@',printo=2
print list="\n",printo=2
;PRINT LIST= "Transit Assignment Summary Report", printo=2
print list="Mode-Level summary"(40.0R),
      printo=2


print list="                                        ",
      list="------------------------ Peak ------------------------"(60.0R),
      list="---------------------- Off-peak ----------------------"(60.2R),
      list="-------------- Daily --------------"(40.0R),printo=2

print list="Route Name "(16.0R),"    ","Mode"(5.0R),"     ","Dist"(10.0R),
           "Time"(10.0R),"Freq"(10.0R),"Pax"(10.0R),"MaxLd"(10.0R),"PaxMi"(10.0R),"PaxHr"(10.0R),
           "Time"(10.0R),"Freq"(10.0R),"Pax"(10.0R),"MaxLd"(10.0R),"PaxMi"(10.0R),"PaxHr"(10.0R),
           "Pax"(10.0R),"MaxLd"(10.0R),"PaxMi"(10.0R),"PaxHr"(10.0R),
           ;"Route LongName                        "(40.0R),
           printo=2
print list="                              ",
           "(mi)"(10.0R),
           "(min)"(10.0R),"(min)"(10.0R)," "(10.0R)," "(10.0R)," "(10.0R)," "(10.0R),
           "(min)"(10.0R),"(min)"(10.0R)," "(10.0R)," "(10.0R)," "(10.0R)," "(10.0R),
           printo=2
 

 
LOOP yY=1,NUMMODE
;if( modelist[y] != 0)
loop y=1,nummode
if(modelist[y]=modelist1[yy])
           PRINT list="Mode"(20.0R),
           form=5.0 list=MODELIST[Y],
           "     ",

        FORM=10.2 LIST=MDIST[Y]/2,
        FORM=10.2 LIST=MTIME[Y]/2, 
 


           "          ",
           fORM=10.1 LIST=MPAX[Y],
           "          ",
           FORM=10.1 LIST=MPAXMI[Y],MPAXHR[Y],
 
       FORM=10.2 LIST=MTIMEO[Y]/2,

           "          ",
           fORM=10.1 LIST=MPAXO[Y],
           "          ",
           FORM=10.1 LIST=MPAXMIO[Y],MPAXHRO[Y],MPAX[Y]+MPAXO[Y],
           "          ",
           FORM=10.1 LIST=MPAXMI[Y]+MPAXMIO[Y],MPAXHR[Y]+MPAXHRO[Y],           
           printo=2
endif
ENDLOOP
endloop
 
      PRINT list="All Modes"(20.0R),
           "     ",
           "     ",

      FORM=10.2 LIST=mdistsum/2,
      FORM=10.2 LIST=MTIMEsum/2,


           "          ",
           fORM=10.1 LIST=MPAXsum,
           "          ",
           FORM=10.1 LIST=MPAXMIsum,MPAXHRsum,

           FORM=10.2 LIST=MTIMEOsum/2,

           "          ",
           fORM=10.1 LIST=MPAXOsum,
           "          ",
           FORM=10.1 LIST=MPAXMIOsum,MPAXHROsum,MPAXsum+MPAXOsum,
           "          ",
           FORM=10.1 LIST=MPAXMIsum+MPAXMIOsum,MPAXHRsum+MPAXHROsum,           
           printo=2


print list="\n\n\n\n",printo=2


print list="\f",printo=2
print list="Title : ",'{SCENARIO_FULLNAME}',printo=2
print list="Alternative : ",'{alt}',printo=2
print list="Year : ",'{year}',printo=2
print list="\n",printo=2
print list='@date.rundate@', printo=2
print list='@time.runtime@',printo=2
print list="\n",printo=2
print list="Operator-Level summary"(40.0R),
      printo=2

print list="                                        ",
      list="------------------------ Peak ------------------------"(60.0R),
      list="---------------------- Off-peak ----------------------"(60.2R),
      list="-------------- Daily --------------"(40.0R),printo=2

print list="Route Name "(16.0R),"    ","Optr"(5.0R),"     ","Dist"(10.0R),
           "Time"(10.0R),"Freq"(10.0R),"Pax"(10.0R),"MaxLd"(10.0R),"PaxMi"(10.0R),"PaxHr"(10.0R),
           "Time"(10.0R),"Freq"(10.0R),"Pax"(10.0R),"MaxLd"(10.0R),"PaxMi"(10.0R),"PaxHr"(10.0R),
           "Pax"(10.0R),"MaxLd"(10.0R),"PaxMi"(10.0R),"PaxHr"(10.0R),
           ;"Route LongName                        "(40.0R),
           printo=2
print list="                              ",
           "(mi)"(10.0R),
           "(min)"(10.0R),"(min)"(10.0R)," "(10.0R)," "(10.0R)," "(10.0R)," "(10.0R),
           "(min)"(10.0R),"(min)"(10.0R)," "(10.0R)," "(10.0R)," "(10.0R)," "(10.0R),
           printo=2
  

LOOP yY=1,NUMoper
;if( modelist[y] != 0)
loop y=1,numoper
if(operlist[y]=operlist1[yy])
;LOOP Y=1,NUMOPER
;if(operlist[y] !=0)
           PRINT list="Operator"(20.0R),
           form=5.0 list=OPERLIST[Y],
           "     ",

       FORM=10.2 LIST=ODIST[Y]/2,
       FORM=10.2 LIST=OTIME[Y]/2,


           "          ",
           fORM=10.1 LIST=OPAX[Y],
           "          ",
           FORM=10.1 LIST=OPAXMI[Y],OPAXHR[Y],

           FORM=10.2 LIST=OTIMEO[Y]/2,

           "          ",
           fORM=10.1 LIST=OPAXO[Y],
           "          ",
           FORM=10.1 LIST=OPAXMIO[Y],OPAXHRO[Y],OPAX[Y]+OPAXO[Y],
           "          ",
           FORM=10.1 LIST=OPAXMI[Y]+OPAXMIO[Y],OPAXHR[Y]+OPAXHRO[Y],           
           printo=2
endif
ENDLOOP
endloop

  PRINT list="All Operators"(20.0R),
           "     ",
           "     ",

      FORM=10.2 LIST=ODISTsum/2,
      FORM=10.2 LIST=OTIMEsum/2,
 

           "          ",
           fORM=10.1 LIST=OPAXsum,
           "          ",
           FORM=10.1 LIST=OPAXMIsum,OPAXHRsum,

           FORM=10.2 LIST=OTIMEOsum/2,


           "          ",
           fORM=10.1 LIST=OPAXOsum,
           "          ",
           FORM=10.1 LIST=OPAXMIOsum,OPAXHROsum,OPAXsum+OPAXOsum,
           "          ",
           FORM=10.1 LIST=OPAXMIsum+OPAXMIOsum,OPAXHRsum+OPAXHROsum,           
           printo=2
;*******************************************************************************************
; ROUTE LEVEL OUTPUT FILE COMPLETE
;*******************************************************************************************


;*******************************************************************************************
; BEGIN PRINTING STOP LEVEL OUTPUT FILE
;*******************************************************************************************
PRINT LIST= "Transit Assignment Route Level Report", printo=1
print list="\n\n",printo=1
print list="Title : ",'{SCENARIO_FULLNAME}',printo=1
print list="Alternative : ",'{alt}',printo=1
print list="Year : ",'{year}',printo=1
print list="\n",printo=1
print list='@date.rundate@', printo=1
print list='@time.runtime@',printo=1
;print list="\n",printo=1
;PRINT LIST= "Transit Assignment Route Level Report", printo=1
;print list="Route Level Report",printo=1
;print list="\n\n",printo=1
;print list="\n",printo=1



  loop k=1,dbi.1.numrecords/2

x=DBIReadRecord(1,2*k-1)
var=di.1.stopa
;print list=var

;if(mode[rtnumber[k]] !=0)
        if (k=1)
           prevrtnum=1
           



           print list="\n\n\n",printo=1
           print list="Route name : ", cform=16.0R list=routename[k],printo=1
           print list="Long name : ",routelname[k],printo=1
           print list="Mode :",form=3.0 list=mode[k]/1,"     ","Operator :",form=3.0 list=operator[k]/1,"     ",
                      "Peak Freq :",form=6.2 list=freq[k]/1," min  (",form=4.1 list=60/freq[k]," vph)","     ","Off-peak Freq :",form=6.2 list=freqo[k],
                       " min  (",form=4.1 list=60/freqo[k]," vph)",printo=1    
           print list="\n",printo=1                  
           print list="                           ","------------------- Peak -------------------"(50.0R),
                      "----------------- Off-peak -----------------"(50.0R),"--------- Daily ---------"(30.0R),printo=1
           print list="Node"(7.0R),"Dist"(10.0R),"CumDist"(10.0R),"Time"(10.0R),"CumTime"(10.0R),"On"(10.0R),"Off"(10.0R),"Load"(10.0R),
                      "Time"(10.0R),"CumTime"(10.0R),"On"(10.0R),"Off"(10.0R),"Load"(10.0R),"On"(10.0R),"Off"(10.0R),"Load"(10.0R),
                      printo=1
           print list="    "(7.0R),"(mi)"(10.0R),"   (mi)"(10.0R),"(min)"(10.0R),"(min)"(10.0R)," "(10.0R)," "(10.0R)," "(10.0R),
                      "(min)"(10.0R),"(min)"(10.0R),""(10.0R),""(10.0R),""(10.0R),""(10.0R),""(10.0R),""(10.0R),
                       printo=1
           print list="\n",printo=1
       endif


  if(rtnumber[k] != prevrtnum)

   if( k!=1)
           prevb=di.1.b
           prevob=offbspl[k]
           prevobo=offbsplo[k]
           prevlds=loadspl[k]
           prevldso=loadsplo[k]

   print  form=7.0  list=bnode[k-1],
           "                                        ","0"(10.0R),
           form=10.1 list=offbspl[k-1],loadspl[k-1],
           "                    ","0"(10.0R),
           form=10.1 list=offbsplo[k-1],loadsplo[k-1],
                          "0"(10.0R),offbspl[k-1]+offbsplo[k-1],loadspl[k-1]+loadsplo[k-1],
                          printo=1
     print list="\n",printo=1
     print list="Totals"(7.0R),"          ",

           form=10.2 list=dist[rtnumber[k-1]]/2,

           "          ",

           form=10.2 list=time[rtnumber[k-1]]/2,

           "          ",
           form=10.1 list=pax[rtnumber[k-1]],maxld[rtnumber[k-1]],
           "          ",

           form=10.2 list=timeo[rtnumber[k-1]]/2,

           "          ",
           form=10.1 list=paxo[rtnumber[k-1]],maxldo[rtnumber[k-1]],
           "          ",
           form=10.1 list=pax[rtnumber[k-1]]+paxo[rtnumber[k-1]], max(maxld[rtnumber[k-1]],maxldo[rtnumber[k-1]]),
           printo=1
     print list="\n",printo=1
     print list="Passenger Miles"(27.0R),"                              ",
           form=10.2 list=paxmi[rtnumber[k-1]],
           "          ","                              ",
           form=10.2 list=paxmio[rtnumber[k-1]],"                    ",
           form=10.2 list=paxmi[rtnumber[k-1]]+paxmio[rtnumber[k-1]],
           printo=1
    print list="Passenger Hours"(27.0R),"                              ",
           form=10.2 list=paxhr[rtnumber[k-1]],
           "          ","                              ",
           form=10.2 list=paxhro[rtnumber[k-1]],"                    ",
           form=10.2 list=paxhr[rtnumber[k-1]]+paxhro[rtnumber[k-1]],
           printo=1  

    if((pax[rtnumber[k-1]]=0) & (paxo[rtnumber[k-1]]=0)) 

           print list="Ave Trip Length (miles)"(27.0R),"                              ",
           form=10.2 list=zero,
           "          ","                              ",
           form=10.2 list=zero,"                    ",
           form=10.2 list=zero,
           printo=1  
           print list="Ave Trip Length (minutes)"(27.0R),"                              ",
           form=10.2 list=zero,
           "          ","                              ",
           form=10.2 list=zero,"                    ",
           form=10.2 list=zero,
           printo=1 

    elseif((pax[rtnumber[k-1]]=0) &(paxo[rtnumber[k-1]]!=0))

           print list="Ave Trip Length (miles)"(27.0R),"                              ",
           form=10.2 list=zero,
           "          ","                              ",
           form=10.2 list=paxmio[rtnumber[k-1]]/paxo[rtnumber[k-1]],"                    ",
           form=10.2 list=(paxmi[rtnumber[k-1]]+paxmio[rtnumber[k-1]])/(pax[rtnumber[k-1]]+paxo[rtnumber[k-1]]),
           printo=1  
           print list="Ave Trip Length (minutes)"(27.0R),"                              ",
           form=10.2 list=zero,
           "          ","                              ",
           form=10.2 list=(paxhro[rtnumber[k-1]]/paxo[rtnumber[k-1]])*60,"                    ",
           form=10.2 list=((paxhr[rtnumber[k-1]]+paxhro[rtnumber[k-1]])/(pax[rtnumber[k-1]]+paxo[rtnumber[k-1]]))*60,
           printo=1 

    elseif((pax[rtnumber[k-1]]!=0) &(paxo[rtnumber[k-1]]=0))

           print list="Ave Trip Length (miles)"(27.0R),"                              ",
           form=10.2 list=paxmi[rtnumber[k-1]]/pax[rtnumber[k-1]],
           "          ","                              ",
           form=10.2 list=zero,"                    ",
           form=10.2 list=(paxmi[rtnumber[k-1]]+paxmio[rtnumber[k-1]])/(pax[rtnumber[k-1]]+paxo[rtnumber[k-1]]),
           printo=1  
           print list="Ave Trip Length (minutes)"(27.0R),"                              ",
           form=10.2 list=(paxhr[rtnumber[k-1]]/pax[rtnumber[k-1]])*60,
           "          ","                              ",
           form=10.2 list=zero,"                    ",
           form=10.2 list=((paxhr[rtnumber[k-1]]+paxhro[rtnumber[k-1]])/(pax[rtnumber[k-1]]+paxo[rtnumber[k-1]]))*60,
           printo=1 

    else

           print list="Ave Trip Length (miles)"(27.0R),"                              ",
           form=10.2 list=paxmi[rtnumber[k-1]]/pax[rtnumber[k-1]],
           "          ","                              ",
           form=10.2 list=paxmio[rtnumber[k-1]]/paxo[rtnumber[k-1]],"                    ",
           form=10.2 list=(paxmi[rtnumber[k-1]]+paxmio[rtnumber[k-1]])/(pax[rtnumber[k-1]]+paxo[rtnumber[k-1]]),
           printo=1  
           print list="Ave Trip Length (minutes)"(27.0R),"                              ",
           form=10.2 list=(paxhr[rtnumber[k-1]]/pax[rtnumber[k-1]])*60,
           "          ","                              ",
           form=10.2 list=(paxhro[rtnumber[k-1]]/paxo[rtnumber[k-1]])*60,"                    ",
           form=10.2 list=((paxhr[rtnumber[k-1]]+paxhro[rtnumber[k-1]])/(pax[rtnumber[k-1]]+paxo[rtnumber[k-1]]))*60,
           printo=1
    ;endif 
    
   endif
    
   endif
           print list="\f",printo=1
           print list="\n\n\n\n\n",printo=1 
           ;print list="_____________________________________________________",printo=1         
           print list="Title : ",'{SCENARIO_FULLNAME}',printo=1
           print list="Alternative : ",'{alt}',printo=1
           print list="Year : ",'{year}',printo=1
           print list="\n",printo=1
           print list='@date.rundate@', printo=1
           print list='@time.runtime@',printo=1
           print list="\n",printo=1
          
          print list="Route name : ", cform=16.0R list=routename[rtnumber[k]],printo=1
          print list="Long name : ",routelname[rtnumber[k]],printo=1
          print list="Mode :",form=3.0 list=mode[rtnumber[k]],"     ","Operator :",form=3.0 list=operator[rtnumber[k]],"     ",
                     "Peak Freq :",form=6.2 list=freq[rtnumber[k]]," min  (",form=4.1 list=60/freq[rtnumber[k]]," vph)","     ","Off-peak Freq :",form=6.2 list=freqo[rtnumber[k]],
                     " min  (",form=4.1 list=60/freqo[rtnumber[k]]," vph)",printo=1 
          print list="\n",printo=1                     
          print list="                           ","------------------- Peak -------------------"(50.0R),
                     "----------------- Off-peak -----------------"(50.0R),"--------- Daily ---------"(30.0R),
                        printo=1
          print list="Node"(7.0R),"Dist"(10.0R),"CumDist"(10.0R),"Time"(10.0R),"CumTime"(10.0R),"On"(10.0R),"Off"(10.0R),"Load"(10.0R),
                      "Time"(10.0R),"CumTime"(10.0R),"On"(10.0R),"Off"(10.0R),"Load"(10.0R),"On"(10.0R),"Off"(10.0R),"Load"(10.0R),
                        printo=1
          print list="    "(7.0R),"(mi)"(10.0R),"   (mi)"(10.0R),"(min)"(10.0R),"(min)"(10.0R)," "(10.0R)," "(10.0R)," "(10.0R),
                     "(min)"(10.0R),"(min)"(10.0R),""(10.0R),""(10.0R),""(10.0R),""(10.0R),""(10.0R),""(10.0R),
                       printo=1
          print list="\n",printo=1
  endif


   if(var=0)
     print list=" -",
           form=5.0 list=node[k],
           form=10.2 list=distan[k],tempdist[k],timean[k],temptime[k],
           form=10.1 list=onasum[k],offasum[k],load[k],
           form=10.2 list=timeano[k],temptimeo[k],
           form=10.1 list=onasumo[k],offasumo[k],loado[k],
                          onasum[k]+onasumo[k],offasum[k]+offasumo[k],load[k]+loado[k],
                          printo=1
else
  print    form=7.0 list=node[k],
           form=10.2 list=distan[k],tempdist[k],timean[k],temptime[k],
           form=10.1 list=onasum[k],offasum[k],load[k],
           form=10.2 list=timeano[k],temptimeo[k],

           form=10.1 list=onasumo[k],offasumo[k],loado[k],
                          onasum[k]+onasumo[k],offasum[k]+offasumo[k],load[k]+loado[k],
                          printo=1
endif

;print list= tempdist[k],(dist[rtnumber[k]])/3,k
 
    ; FORM=10.2 LIST=OTIMEOsum/2,
    
     
   
           prevb=di.1.b
           prevob=offbspl[k]
           prevobo=offbsplo[k]
           prevlds=loadspl[k]
           prevldso=loadsplo[k]

           prevrtnum=rtnumber[k]
;endif


if(k=dbi.1.numrecords/2)
           prevb=di.1.b
           prevob=offbspl[k]
           prevobo=offbsplo[k]
           prevlds=loadspl[k]
           prevldso=loadsplo[k]

   print  form=7.0  list=prevb,
           "                                        ","0"(10.0R),
           form=10.1 list=prevob,prevlds,
           "                    ","0"(10.0R),
           form=10.1 list=prevobo,prevldso,
                          "0"(10.0R),prevob+prevobo,prevlds+prevldso,
                          printo=1
     print list="\n",printo=1
     print list="Totals"(7.0R),"          ",

           form=10.2 list=dist[rtnumber[k]]/2,

           "          ",

           form=10.2 list=time[rtnumber[k]]/2,

           "          ",
           form=10.1 list=pax[rtnumber[k]],maxld[rtnumber[k]],
           "          ",

           form=10.2 list=timeo[rtnumber[k]]/2,

           "          ",
           form=10.1 list=paxo[rtnumber[k]],maxldo[rtnumber[k]],
           "          ",
           form=10.1 list=pax[rtnumber[k]]+paxo[rtnumber[k]], max(maxld[rtnumber[k]],maxldo[rtnumber[k]]),
           printo=1
     print list="\n",printo=1
     print list="Passenger Miles"(27.0R),"                              ",
           form=10.2 list=paxmi[rtnumber[k]],
           "          ","                              ",
           form=10.2 list=paxmio[rtnumber[k]],"                    ",
           form=10.2 list=paxmi[rtnumber[k]]+paxmio[rtnumber[k]],
           printo=1
    print list="Passenger Hours"(27.0R),"                              ",
           form=10.2 list=paxhr[rtnumber[k]],
           "          ","                              ",
           form=10.2 list=paxhro[rtnumber[k]],"                    ",
           form=10.2 list=paxhr[rtnumber[k]]+paxhro[rtnumber[k]],
           printo=1  

    if((pax[rtnumber[k]]=0) & (paxo[rtnumber[k]]=0)) 

           print list="Ave Trip Length (miles)"(27.0R),"                              ",
           form=10.2 list=zero,
           "          ","                              ",
           form=10.2 list=zero,"                    ",
           form=10.2 list=zero,
           printo=1  
           print list="Ave Trip Length (minutes)"(27.0R),"                              ",
           form=10.2 list=zero,
           "          ","                              ",
           form=10.2 list=zero,"                    ",
           form=10.2 list=zero,
           printo=1 

    elseif((pax[rtnumber[k]]=0) &(paxo[rtnumber[k]]!=0))

           print list="Ave Trip Length (miles)"(27.0R),"                              ",
           form=10.2 list=zero,
           "          ","                              ",
           form=10.2 list=paxmio[rtnumber[k]]/paxo[rtnumber[k]],"                    ",
           form=10.2 list=(paxmi[rtnumber[k]]+paxmio[rtnumber[k]])/(pax[rtnumber[k]]+paxo[rtnumber[k]]),
           printo=1  
           print list="Ave Trip Length (minutes)"(27.0R),"                              ",
           form=10.2 list=zero,
           "          ","                              ",
           form=10.2 list=(paxhro[rtnumber[k]]/paxo[rtnumber[k]])*60,"                    ",
           form=10.2 list=((paxhr[rtnumber[k]]+paxhro[rtnumber[k]])/(pax[rtnumber[k]]+paxo[rtnumber[k]]))*60,
           printo=1 

    elseif((pax[rtnumber[k]]!=0) &(paxo[rtnumber[k]]=0))

           print list="Ave Trip Length (miles)"(27.0R),"                              ",
           form=10.2 list=paxmi[rtnumber[k]]/pax[rtnumber[k]],
           "          ","                              ",
           form=10.2 list=zero,"                    ",
           form=10.2 list=(paxmi[rtnumber[k]]+paxmio[rtnumber[k]])/(pax[rtnumber[k]]+paxo[rtnumber[k]]),
           printo=1  
           print list="Ave Trip Length (minutes)"(27.0R),"                              ",
           form=10.2 list=(paxhr[rtnumber[k]]/pax[rtnumber[k]])*60,
           "          ","                              ",
           form=10.2 list=zero,"                    ",
           form=10.2 list=((paxhr[rtnumber[k]]+paxhro[rtnumber[k]])/(pax[rtnumber[k]]+paxo[rtnumber[k]]))*60,
           printo=1 

    else

           print list="Ave Trip Length (miles)"(27.0R),"                              ",
           form=10.2 list=paxmi[rtnumber[k]]/pax[rtnumber[k]],
           "          ","                              ",
           form=10.2 list=paxmio[rtnumber[k]]/paxo[rtnumber[k]],"                    ",
           form=10.2 list=(paxmi[rtnumber[k]]+paxmio[rtnumber[k]])/(pax[rtnumber[k]]+paxo[rtnumber[k]]),
           printo=1  
           print list="Ave Trip Length (minutes)"(27.0R),"                              ",
           form=10.2 list=(paxhr[rtnumber[k]]/pax[rtnumber[k]])*60,
           "          ","                              ",
           form=10.2 list=(paxhro[rtnumber[k]]/paxo[rtnumber[k]])*60,"                    ",
           form=10.2 list=((paxhr[rtnumber[k]]+paxhro[rtnumber[k]])/(pax[rtnumber[k]]+paxo[rtnumber[k]]))*60,
           printo=1
    ;endif 
    
   endif
endif

endloop


;*******************************************************************************************
; END PRINTING STOP LEVEL OUTPUT FILE
;*******************************************************************************************

;*******************************************************************************************
; REACHED END OF SCRIPT
;*******************************************************************************************

; The MATRIX module does not have any explicit phases.  The module does run within an implied ILOOP
; where I is the origin zones.  All user statements in the module are processed once for each origin.
; Matrix computation (MW[#]=) are solved for all values of J for each I.  Thus for a given origin zone I
; the values for all destination zones J are automatically computed.  The user can control the computations
; at each J by using a JLOOP.

ENDRUN


; Script for program MATRIX in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\TAMAT01D.S"
; 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\TAMAT00E.PRN" MSG='5) Print station activity report'
FILEI DBI[1] = "{SCENARIO_DIR}\output\TLINKPK1_{alt}{year}.DBF"
FILEI DBI[6] = "{SCENARIO_DIR}\output\TLINKOP3_{alt}{year}.DBF"
FILEI DBI[5] = "{SCENARIO_DIR}\output\TLINKOP1_{alt}{year}.DBF"
FILEI DBI[2] = "{SCENARIO_DIR}\output\TLINKPK3_{alt}{year}.DBF"

;************************************************************************************************
; SCRIPT TO SUMMARIZE AND REPORT STATION ACTIVITY
;************************************************************************************************

;************************************************************************************************
; INPUT FILES: 4 PEAK LOADED FILES
;              4 OFF-PEAK LOADED FILES
;              STATION DETAILS FILE 
; OUTPUT FIELS: STATION ACTIVITY REPORT FILE
;************************************************************************************************
FILEI DBI[9] = "{SCENARIO_DIR}\INPUT\STATREP_{year}{alt}.DAT",
                                      BRTNODE=1-5, DESCR(C)=8-49

;FIELDS=1-10


FILEO PRINTO[1] = "{SCENARIO_DIR}\output\Stations_{ALT}{YEAR}.prn"

;************************************************************************************************
; DEFINE ALL ARRAYS WITH SIZE AS MAX. NO. OF NODES IN A ROUTE (500)
;************************************************************************************************

ARRAY STNUM=500 STNODE=500 STNAME=500
ARRAY pACCVOL1=500 pEGRVOL1=500 pACCVOL2=500 pEGRVOL2=500 pACCVOL3=500 pEGRVOL3=500 pACCVOL5=500 pEGRVOL5=500
ARRAY pACCVOL6=500 pEGRVOL6=500 pACCVOL11=500 pEGRVOL11=500 pACCVOL12=500 pEGRVOL12=500
ARRAY pBoard=500 pAlite=500
ARRAY oACCVOL1=500 oEGRVOL1=500 oACCVOL2=500 oEGRVOL2=500 oACCVOL3=500 oEGRVOL3=500 oACCVOL5=500 oEGRVOL5=500
ARRAY oACCVOL6=500 oEGRVOL6=500 oACCVOL11=500 oEGRVOL11=500 oACCVOL12=500 oEGRVOL12=500
ARRAY oBoard=500 oAlite=500
array freqo=dbi.5.numrecords
array linkseq1=dbi.1.numrecords
array linkseq2=dbi.2.numrecords
array linkseq5=dbi.5.numrecords
array linkseq6=dbi.6.numrecords

;array routename=500-16


;************************************
; MAIN SCRIPT AREA
;************************************
ZONES=1

LOOP k=1,DBI.9.NUMRECORDS
  COMP x=DBIReadRecord(9,k)
  STNUM[k] = k
  STNODE[k] = DI.9.BRTNODE
ENDLOOP
_numStations = DBI.9.NUMRECORDS

_temp = 0

loop k=1,dbi.1.numrecords
COMP x=DBIReadRecord(1,k)
COMP xx=DBIReadRecord(2,k)

linkseq1[k]=di.1.linkseq
linkseq2[k]=di.2.linkseq

endloop

loop k=1,dbi.5.numrecords
COMP xxx=DBIReadRecord(5,k)
COMP xxxx=DBIReadRecord(6,k)

linkseq5[k]=di.5.linkseq
linkseq6[k]=di.6.linkseq

endloop

; Peak Period
LOOP k=1,DBI.1.NUMRECORDS
  IF ((k % 1000)==0) PRINT LIST="Reading peak period records...",k(C)," of ",DBI.1.NUMRECORDS(C),PRINTO=0
  COMP x=DBIReadRecord(1,k)
  _A = DI.1.A
  _B = DI.1.B

  LOOP y=1,_numStations
    COMP w=DBIReadRecord(9,y)
    ; Access Volumes by Access Mode
    IF (_B == STNODE[y])
      IF (DI.1.MODE == 1) pACCVOL1[y] = pACCVOL1[y] + DI.1.VOL
      IF (DI.1.MODE == 2) pACCVOL2[y] = pACCVOL2[y] + DI.1.VOL
      IF (DI.1.MODE ==11) pACCVOL11[y] = pACCVOL11[y] + DI.1.VOL
      IF (DI.1.MODE ==12) pACCVOL12[y] = pACCVOL12[y] + DI.1.VOL
 if(k <> dbi.1.numrecords)
     if(linkseq1[k+1]==1)
     IF (DI.1.MODE > 20) pALITE[y] = pALITE[y] + DI.1.OFFB
     endif
    else
     IF (DI.1.MODE > 20) pALITE[y] = pALITE[y] + DI.1.OFFB
     endif

    ENDIF
    ; pEGRess Volumes by pEGRess Mode
    IF (_A == STNODE[y])
      IF (DI.1.MODE == 1) pEGRVOL1[y] = pEGRVOL1[y] + DI.1.VOL
      IF (DI.1.MODE == 2) pEGRVOL2[y] = pEGRVOL2[y] + DI.1.VOL
      IF (DI.1.MODE ==11) pEGRVOL11[y] = pEGRVOL11[y] + DI.1.VOL
      IF (DI.1.MODE ==12) pEGRVOL12[y] = pEGRVOL12[y] + DI.1.VOL

      IF (DI.1.MODE > 20) pBOARD[y] = pBOARD[y] + DI.1.ONA
      IF (DI.1.MODE > 20) pALITE[y] = pALITE[y] + DI.1.OFFA
    ENDIF
  ENDLOOP
ENDLOOP


;****************************************
;try area
;****************************************
LOOP k=1,DBI.2.NUMRECORDS
  IF ((k % 1000)==0) PRINT LIST="Reading peak period records...",k(C)," of ",DBI.2.NUMRECORDS(C),PRINTO=0
  COMP x=DBIReadRecord(2,k)
  _A = DI.2.A
  _B = DI.2.B

  LOOP y=1,_numStations
    COMP w=DBIReadRecord(9,y)

    ; Access Volumes by Access Mode
    IF (_B == STNODE[y])
      IF (DI.2.MODE == 1) pACCVOL1[y] = pACCVOL1[y] + DI.2.VOL
     IF (DI.2.MODE == 2) pACCVOL2[y] = pACCVOL2[y] + DI.2.VOL
      IF (DI.2.MODE ==11) pACCVOL11[y] = pACCVOL11[y] + DI.2.VOL
      IF (DI.2.MODE ==12) pACCVOL12[y] = pACCVOL12[y] + DI.2.VOL
if(k <> dbi.2.numrecords)
     if(linkseq2[k+1]==1)
     IF (DI.2.MODE > 20) pALITE[y] = pALITE[y] + DI.2.OFFB
     endif
    else
     IF (DI.2.MODE > 20) pALITE[y] = pALITE[y] + DI.2.OFFB
     endif

    ENDIF
    ; pEGRess Volumes by pEGRess Mode
    IF (_A == STNODE[y])
      IF (DI.2.MODE == 1) pEGRVOL1[y] = pEGRVOL1[y] + DI.2.VOL
      IF (DI.2.MODE == 2) pEGRVOL2[y] = pEGRVOL2[y] + DI.2.VOL
      IF (DI.2.MODE ==11) pEGRVOL11[y] = pEGRVOL11[y] + DI.2.VOL
      IF (DI.2.MODE ==12) pEGRVOL12[y] = pEGRVOL12[y] + DI.2.VOL

      IF (DI.2.MODE > 20) pBOARD[y] = pBOARD[y] + DI.2.ONA
      IF (DI.2.MODE > 20) pALITE[y] = pALITE[y] + DI.2.OFFA
    ENDIF
  ENDLOOP
ENDLOOP





altstr='{alt}'
yearstr='{year}'
altyr=insertstr(altstr,yearstr,3)



LOOP k=1,DBI.5.NUMRECORDS
  IF ((k % 1000)==0) PRINT LIST="Reading offpeak period records...",k(C)," of ",DBI.5.NUMRECORDS(C),PRINTO=0
  COMP x=DBIReadRecord(5,k)
  _A = DI.5.A
  _B = DI.5.B
  LOOP y=1,_numStations
    COMP w=DBIReadRecord(9,y)
    ; Access Volumes by Access Mode
    IF (_B == STNODE[y])
      IF (DI.5.MODE == 1) oACCVOL1[y] = oACCVOL1[y] + DI.5.VOL
      IF (DI.5.MODE == 2) oACCVOL2[y] = oACCVOL2[y] + DI.5.VOL
      IF (DI.5.MODE ==11) oACCVOL11[y] = oACCVOL11[y] + DI.5.VOL
      IF (DI.5.MODE ==12) oACCVOL12[y] = oACCVOL12[y] + DI.5.VOL
if(k <> dbi.5.numrecords)
    if(linkseq5[k+1]==1)
     IF (DI.5.MODE > 20) oALITE[y] = oALITE[y] + DI.5.OFFB
    endif
    else
     IF (DI.5.MODE > 20) oALITE[y] = oALITE[y] + DI.5.OFFB
     endif

    ENDIF
    ; oEGRess Volumes by oEGRess Mode
    IF (_A == STNODE[y])
      IF (DI.5.MODE == 1) oEGRVOL1[y] = oEGRVOL1[y] + DI.5.VOL
      IF (DI.5.MODE == 2) oEGRVOL2[y] = oEGRVOL2[y] + DI.5.VOL
      IF (DI.5.MODE ==11) oEGRVOL11[y] = oEGRVOL11[y] + DI.5.VOL
      IF (DI.5.MODE ==12) oEGRVOL12[y] = oEGRVOL12[y] + DI.5.VOL
      IF (DI.5.MODE > 20) oBOARD[y] = oBOARD[y] + DI.5.ONA
      IF (DI.5.MODE > 20) oALITE[y] = oALITE[y] + DI.5.OFFA
    ENDIF
  ENDLOOP
ENDLOOP


LOOP k=1,DBI.6.NUMRECORDS
  IF ((k % 1000)==0) PRINT LIST="Reading offpeak period records...",k(C)," of ",DBI.6.NUMRECORDS(C),PRINTO=0
  COMP x=DBIReadRecord(6,k)
  _A = DI.6.A
  _B = DI.6.B
  LOOP y=1,_numStations
    COMP w=DBIReadRecord(9,y)
    ; Access Volumes by Access Mode
    IF (_B == STNODE[y])
     IF (DI.6.MODE == 1) oACCVOL1[y] = oACCVOL1[y] + DI.6.VOL
     IF (DI.6.MODE == 2) oACCVOL2[y] = oACCVOL2[y] + DI.6.VOL
     IF (DI.6.MODE ==11) oACCVOL11[y] = oACCVOL11[y] + DI.6.VOL
     IF (DI.6.MODE ==12) oACCVOL12[y] = oACCVOL12[y] + DI.6.VOL
 
if(k <> dbi.6.numrecords)
     if(linkseq6[k+1]==1)
     IF (DI.6.MODE > 20) oALITE[y] = oALITE[y] + DI.6.OFFB
     endif
    else
     IF (DI.6.MODE > 20) oALITE[y] = oALITE[y] + DI.6.OFFB
     endif

   ENDIF
    ; oEGRess Volumes by oEGRess Mode
    IF (_A == STNODE[y])
      IF (DI.6.MODE == 1) oEGRVOL1[y] = oEGRVOL1[y] + DI.6.VOL
      IF (DI.6.MODE == 2) oEGRVOL2[y] = oEGRVOL2[y] + DI.6.VOL
      IF (DI.6.MODE ==11) oEGRVOL11[y] = oEGRVOL11[y] + DI.6.VOL
      IF (DI.6.MODE ==12) oEGRVOL12[y] = oEGRVOL12[y] + DI.6.VOL
      IF (DI.6.MODE > 20) oBOARD[y] = oBOARD[y] + DI.6.ONA
      IF (DI.6.MODE > 20) oALITE[y] = oALITE[y] + DI.6.OFFA
    ENDIF
  ENDLOOP
ENDLOOP



loop qw=1,dbi.5.numrecords
abc=DBIReadRecord(5,qw)
freqo[qw]=dBi.5.NFIELD[10]
endloop




PRINT LIST="STATION ACTIVITY & ACCESS/EGRESS REPORT (station node is in paranthesis after name)",PRINTO=1
print list="\n",printo=1
IF (I == _ZONES)
print list="Title : ",'{SCENARIO_FULLNAME}',printo=1
print list="Alternative : ",altyr,printo=1
;print list="Year : ",'{year}',printo=1
;print list="\n",printo=1
print list='@date.rundate@',"     ",'@time.runtime@', printo=1
print list="\n",printo=1


 
PRINT LIST="\n\n",PRINTO=1
;PRINT LIST=" "(44),"       P E A K      ","    O F F P E A K   ","      D A I L Y     ",PRINTO=1
;  PRINT LIST="No.   Node      Station Name                    Access    Egress    Access    Egress    Access    Egress     ",PRINTO=1
  print list="\n",printo=1
    LOOP x=1,_numStations
    cumroutes=0
    cumpeakvph=0
    cumopeakvph=0
    COMP y=DBIReadRecord(9,x)
print list="-----------------------------------------------------------------------------------------------",printo=1
print list=stnum[x](3.0L),". Station Name : ",DI.9.DESCR(40),"(",stnode[x](5.0),")",printo=1 
print list="\n",printo=1
;print list="  Transit Service",printo=1
print list="                                   PEAK              OFF PEAK            ",printo=1
print list="  ----------------------------------+---------+---------+---------",printo=1
print list="  Transit Service          Frequency      vph  Frequency      vph ",printo=1
print list="  ----------------------------------+---------+---------+---------",printo=1
count=0
;prevroute="0"
loop n=1,dbi.1.numrecords
  zz=DBIReadRecord(1,n)

 if((stnode[x]=di.1.a)|(stnode[x]=di.1.b))

    if(di.1.mode>20)
    if(di.1.name != prevroute)
    
             if((DBI.1.NFIELD[10]=0)&(freqo[n]=0))

          print list="  ",cform=23.0 list=di.1.name,form=10.1 list=DBI.1.NFIELD[10],"0"(10.0R),freqo[n],"0"(10.0R),printo=1
             
    
             cumroutes=cumroutes+1
             cumpeakvph=cumpeakvph
             cumopeakvph=cumopeakvph


             elseif((DBI.1.NFIELD[10] !=0)&(freqo[n]=0))
               print list="  ",cform=23.0 list=di.1.name,form=10.1 list=DBI.1.NFIELD[10],(60/DBI.1.NFIELD[10]),freqo[n],"0"(10.0R),printo=1
             
             cumroutes=cumroutes+1
             cumpeakvph=cumpeakvph+(60/DBI.1.NFIELD[10])
             cumopeakvph=cumopeakvph

             elseif((DBI.1.NFIELD[10] =0)&(freqo[n]!=0))
               print list="  ",cform=23.0 list=di.1.name,form=10.1 list=DBI.1.NFIELD[10],"0"(10.0R),freqo[n],(60/freqo[n]),printo=1
             
             cumroutes=cumroutes+1
             cumpeakvph=cumpeakvph
             cumopeakvph=cumopeakvph+(60/freqo[n])

             else              
               print list="  ",cform=23.0 list=di.1.name,form=10.1 list=DBI.1.NFIELD[10],(60/DBI.1.NFIELD[10]),freqo[n],(60/freqo[n]),printo=1
             
             cumroutes=cumroutes+1
             cumpeakvph=cumpeakvph+(60/DBI.1.NFIELD[10])
             cumopeakvph=cumopeakvph+(60/freqo[n])
 
             endif
         
         prevroute=di.1.name
     endif
     endif

 endif

endloop


;print list="\n",printo=1
;print list="                                   PEAK              OFF PEAK            DAILY",printo=1
print list="  ----------------------------------+---------+---------+---------",printo=1
print list="  Total no. of services :",form=3.0 list=cumroutes,"           ",form=6.1 list=cumpeakvph,"              ",form=6.1 list=cumopeakvph,printo=1
print list="  ----------------------------------+---------+---------+---------",printo=1
print list="\n",printo=1
print list="                                   PEAK              OFF PEAK            DAILY",printo=1
print list="  ----------------------------------+---------+---------+---------+---------+--------",printo=1
print list="  Activity                   Access    Egress    Access    Egress    Access    Egress",printo=1
print list="  ----------------------------------+---------+---------+---------+---------+--------",printo=1

   ; PRINT LIST=stnum[x](4.0),stnode[x](9.0),"  ",DI.6.DESCR(40),PRINTO=1

    PRINT LIST="  ","Walk Access            ",pACCVOL1[x](10.1),pEGRVOL1[x](10.1),oACCVOL1[x](10.1),oEGRVOL1[x](10.1),(pACCVOL1[x]+oACCVOL1[x])(10.1),(pEGRVOL1[x]+oEGRVOL1[x])(10.1),PRINTO=1
    PRINT LIST="  ","Auto Access            ",pACCVOL2[x](10.1),pEGRVOL2[x](10.1),oACCVOL2[x](10.1),oEGRVOL2[x](10.1),(pACCVOL2[x]+oACCVOL2[x])(10.1),(pEGRVOL2[x]+oEGRVOL2[x])(10.1),PRINTO=1
    PRINT LIST="  ","Transfer Connector     ",pACCVOL11[x](10.1),pEGRVOL11[x](10.1),oACCVOL11[x](10.1),oEGRVOL11[x](10.1),(pACCVOL11[x]+oACCVOL11[x])(10.1),(pEGRVOL11[x]+oEGRVOL11[x])(10.1),PRINTO=1
    PRINT LIST="  ","Sidewalk Connector     ",pACCVOL12[x](10.1),pEGRVOL12[x](10.1),oACCVOL12[x](10.1),oEGRVOL12[x](10.1),(pACCVOL12[x]+oACCVOL12[x])(10.1),(pEGRVOL12[x]+oEGRVOL12[x])(10.1),PRINTO=1       
    PRINT LIST="  ","Boardings              "," "(10),pBOARD[x](10.1)," "(10),oBOARD[x](10.1)," "(10),(pBOARD[x]+oBOARD[x])(10.1),PRINTO=1
    PRINT LIST="  ","Alightings             "," "(10),pALITE[x](10.1)," "(10),oALITE[x](10.1)," "(10),(pALITE[x]+oALITE[x])(10.1),PRINTO=1
    
print list="-----------------------------------------------------------------------------------------------",printo=1
PRINT LIST="\n\n\n\n",PRINTO=1
  ENDLOOP
ENDIF

; The MATRIX module does not have any explicit phases.  The module does run within an implied ILOOP
; where I is the origin zones.  All user statements in the module are processed once for each origin.
; Matrix computation (MW[#]=) are solved for all values of J for each I.  Thus for a given origin zone I
; the values for all destination zones J are automatically computed.  The user can control the computations
; at each J by using a JLOOP.

ENDRUN


; Script for program NETWORK in file "X:\Projects\CRTPA\Model\C\APPLICATIONS\00NET00A.S"
; Do not change filenames or add or remove FILEI/FILEO statements using an editor. Use Cube/Application Manager.
RUN PGM=NETWORK PRNFILE="X:\Projects\CRTPA\Model\C\APPLICATIONS\00NET00A.PRN" MSG='Generate Network Volume Report'

FILEO NETO = "{SCENARIO_DIR}\output\TransitLinkLoad_{alt}{year}.NET",
INCLUDE=A,B,NTVOL_PK,TVOL_PK,NTVOL_OP,TVOL_OP,TOTAL_VOLUME

FILEI LINKI[5] = "{SCENARIO_DIR}\output\PKWalk.NET"
FILEI LINKI[4] = "{SCENARIO_DIR}\output\TLINKOP3_{alt}{year}_It01.DBF"
FILEI LINKI[3] = "{SCENARIO_DIR}\output\TLINKOP1_{alt}{year}_It01.DBF"
FILEI LINKI[2] = "{SCENARIO_DIR}\output\TLINKPK3_{alt}{year}_It01.DBF"
FILEI LINKI[1] = "{SCENARIO_DIR}\output\TLINKPK1_{alt}{year}_It01.DBF"


MERGE RECORD=F

PROCESS  PHASE=LINKMERGE

  NTVOL_PK = LI.1.NTVOL + LI.2.NTVOL
  TVOL_PK  = LI.1.TVOL + LI.2.TVOL
  NTVOL_OP = LI.3.NTVOL + LI.4.NTVOL
  TVOL_OP  = LI.3.TVOL + LI.4.TVOL
  TOTAL_VOLUME = TVOL_PK+ TVOL_OP

ENDPROCESS

ENDRUN


