; 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 "D:\JOB\D3\MODEL\NEW\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="D:\JOB\D3\MODEL\NEW\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 "D:\JOB\D3\MODEL\NEW\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[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"
FILEI DBI[1] = "{SCENARIO_DIR}\output\TLINKPK1_{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 "D:\JOB\D3\MODEL\NEW\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 "D:\JOB\D3\MODEL\NEW\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[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"
FILEI DBI[1] = "{SCENARIO_DIR}\output\TLINKPK1_{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 "D:\JOB\D3\MODEL\NEW\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="D:\JOB\D3\MODEL\NEW\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


