auxiliary.f 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. SUBROUTINE READPARAM(FILENAME)
  2. IMPLICIT NONE
  3. C Read file for parameter values and store these in
  4. C common blocks
  5. INTEGER N, LENGTH, IND, NGRID
  6. DOUBLE PRECISION R0,R1,S0,S1,VF,K,L,P,TMAX
  7. DOUBLE PRECISION M0, MBAR
  8. INTEGER ITMAX
  9. CHARACTER*10 FILENAME
  10. CHARACTER*20 LINE
  11. CHARACTER*6 VARNAME
  12. DOUBLE PRECISION VARVALUE
  13. COMMON /MODELPARAM/ R0,R1,S0,S1,VF,K,L,P,TMAX
  14. COMMON /OTHERPARAM/ M0, MBAR, ITMAX
  15. OPEN(UNIT=1,FILE=FILENAME)
  16. 1 READ(1,'(a20)',END=3) LINE
  17. LENGTH=SCAN(LINE,'#',.FALSE.)
  18. IF(LENGTH.GT.0) GOTO 1
  19. LENGTH=SCAN(LINE,'=',.FALSE.)
  20. IF(LENGTH.EQ.0) GOTO 1
  21. READ(LINE(1:LENGTH-1),'(A6)') VARNAME
  22. READ(LINE(LENGTH+1:40),*) VARVALUE
  23. IF(VARNAME.EQ.'VF') THEN
  24. VF=VARVALUE
  25. ELSEIF(VARNAME.EQ.'P') THEN
  26. P=VARVALUE
  27. ELSEIF(VARNAME.EQ.'L') THEN
  28. L=VARVALUE
  29. ELSEIF(VARNAME.EQ.'K') THEN
  30. K=VARVALUE
  31. ELSEIF(VARNAME.EQ.'TMAX') THEN
  32. TMAX=VARVALUE
  33. ELSEIF(VARNAME.EQ.'R0') THEN
  34. R0=VARVALUE
  35. ELSEIF(VARNAME.EQ.'R1') THEN
  36. R1=VARVALUE
  37. ELSEIF(VARNAME.EQ.'S0') THEN
  38. S0=VARVALUE
  39. ELSEIF(VARNAME.EQ.'S1') THEN
  40. S1=VARVALUE
  41. ELSEIF(VARNAME.EQ.'M0') THEN
  42. M0=VARVALUE
  43. ELSEIF(VARNAME.EQ.'MBAR') THEN
  44. MBAR=VARVALUE
  45. ELSEIF(VARNAME.EQ.'ITMAX') THEN
  46. ITMAX=NINT(VARVALUE)
  47. ENDIF
  48. GOTO 1
  49. 3 CONTINUE
  50. CLOSE(1)
  51. RETURN
  52. END
  53. C ==================================================
  54. C Descriptive values for given vector of entry rates
  55. C ==================================================
  56. SUBROUTINE STATDES(N, E, DAT, IDAT)
  57. IMPLICIT NONE
  58. INTEGER I, N, NL, NMAX, NE
  59. PARAMETER (NMAX=10000)
  60. DOUBLE PRECISION U, E(N), EE(N)
  61. DOUBLE PRECISION DAT(NMAX)
  62. INTEGER IDAT(NMAX)
  63. C Variables used for intermediate computations
  64. DOUBLE PRECISION V(NMAX), T(NMAX), TT(NMAX)
  65. DOUBLE PRECISION UE(NMAX), UX(NMAX)
  66. DOUBLE PRECISION SUME(NMAX),CUME(NMAX)
  67. C Parameters of the problem
  68. DOUBLE PRECISION R0, R1, S0, S1, VF, K, L, P, TMAX
  69. COMMON /MODELPARAM/ R0, R1, S0, S1, VF, K, L, P, TMAX
  70. NL = IDAT(2)
  71. NE = IDAT(3)
  72. C Compute travel speed, travel time and clock-time on each interval
  73. I=1
  74. TT(I) = DAT(I) / VF
  75. SUME(I)=E(I)
  76. V(I) = VF * ( 1.0D0 - P * SUME(I) / K )
  77. T(I) = ( DAT(I+1) - DAT(I) ) / V(I)
  78. TT(I+1) = TT(I) + T(I)
  79. DO 1, I = 2, N + NL - 1
  80. IF(I.LE.NL) THEN
  81. SUME(I) = SUME(I-1) + E(I)
  82. ELSEIF (I.LE.N) THEN
  83. SUME(I) = SUME(I-1) + E(I) - E(I-NL)
  84. ELSE
  85. SUME(I) = SUME(I-1) - E(I-NL)
  86. ENDIF
  87. V(I) = VF * ( 1.0D0 - P * SUME(I) / K )
  88. T(I) = ( DAT(I+1) - DAT(I) ) / V(I)
  89. TT(I+1) = TT(I) + T(I)
  90. 1 CONTINUE
  91. C Compute entry and exit sub-utilities
  92. DO 20, I = 1, N
  93. UE(I) = R0 * DLOG( R1 * TT(I ) ) * E(I) * P
  94. UX(I) = S0 * DLOG( S1 * ( TMAX - TT(I + NL))) * E(I) * P
  95. 20 CONTINUE
  96. EE = 0.0D0
  97. CUME(1) = E(1)
  98. DO 30, I = 1, N+NL-1
  99. IF(MOD(I-1,10).EQ.0) PRINT'(A5,10A9)',"I","M","e","E","e-x",
  100. 1 "t","v","Te","Ue","Tx","Ux"
  101. IF(I.LE.N-1) THEN
  102. CUME(I+1)=CUME(I)+E(I+1)
  103. ELSE
  104. CUME(I+1)=CUME(I)
  105. ENDIF
  106. IF(I.LE.N) EE(I) = E(I)
  107. PRINT'(I5,10F9.3)',I,DAT(I),EE(I),CUME(I),SUME(I),
  108. 1 T(I),V(I),TT(I),UE(I),TT(I+NL),UX(I)
  109. 30 CONTINUE
  110. I=N+NL
  111. PRINT'(I5,10F9.3)',I,DAT(I),EE(I),CUME(I),0.0D0,
  112. 1 T(I),VF,TT(I),UE(I),TT(I+NL),UX(I)
  113. RETURN
  114. END
  115. SUBROUTINE CHECK_GRAD(N, E, M, CON, DAT, IDAT)
  116. IMPLICIT NONE
  117. C IDAT(2) = NL
  118. C DAT (3) = K
  119. C DAT (4) = P
  120. C DAT (5) = TMAX
  121. INTEGER N, M, NMAX, NE, NL
  122. PARAMETER (NMAX=10000)
  123. DOUBLE PRECISION CON(M), E(N)
  124. DOUBLE PRECISION DAT(NMAX)
  125. INTEGER IDAT(NMAX)
  126. DOUBLE PRECISION D_T(N+IDAT(2)-1), D_TT(N+IDAT(2),N)
  127. DOUBLE PRECISION V(N+IDAT(2)-1), T(N+IDAT(2)-1), TT(N+IDAT(2))
  128. DOUBLE PRECISION SUME
  129. INTEGER I, J
  130. C Parameters of the problem
  131. DOUBLE PRECISION R0, R1, S0, S1, VF, K, L, P, TMAX
  132. COMMON /MODELPARAM/ R0, R1, S0, S1, VF, K, L, P, TMAX
  133. NL = IDAT(2)
  134. NE = IDAT(3)
  135. C Constraints 1 to NE - NL + 1
  136. DO 10, I = 1, NE - NL + 1
  137. SUME = 0.0D0
  138. DO 15, J = I, I + NL -1
  139. SUME = SUME + E(J)
  140. 15 CONTINUE
  141. CON(I) = SUME + E(NE+I) - K / P
  142. 10 CONTINUE
  143. C Constraint NE - NL + 1 + 1 (copied from UTIL, except last line)
  144. I=1
  145. TT(I) = DAT(I) / VF
  146. SUME=E(I)
  147. V(I) = VF * ( 1.0D0 - P * SUME / K )
  148. T(I) = ( DAT(I+1) - DAT(I) ) / V(I)
  149. TT(I+1) = TT(I) + T(I)
  150. DO 20, I = 2, N + NL - 1
  151. IF(I.LE.NL) THEN
  152. SUME = SUME + E(I)
  153. ELSEIF (I.LE.NE) THEN
  154. SUME = SUME + E(I) - E(I-NL)
  155. ELSE
  156. SUME = SUME - E(I-NL)
  157. ENDIF
  158. V(I) = VF * ( 1.0D0 - P * SUME / K )
  159. T(I) = ( DAT(I+1) - DAT(I) ) / V(I)
  160. TT(I+1) = TT(I) + T(I)
  161. 20 CONTINUE
  162. CON(NE-NL+1+1) = TT(NE+NL) + E(NE+NE-NL+1+1) - TMAX
  163. C Constraint NE + NE - NL + 1 + 1 + 1
  164. SUME = 0.0D0
  165. DO 30, I = 1, NE
  166. SUME = SUME + E(I)
  167. 30 CONTINUE
  168. CON(NE-NL+3) = SUME - 1.0D0
  169. RETURN
  170. END