; Cross-country from L.A. to Cape Cod, December 2000.
; Calculations to go into tripplan.xml.

;   STRUCTURE: See lines with ";;;"
;   7 lines matching ";;;" in buffer tripplan.el.
;       3:;   STRUCTURE: See lines with ";;;"
;      13:; HIGHWAY: West to East ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;     146:; HIGHWAY: East to West ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;     160:; FUEL: West to East to West ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;     196:; PROGRAM ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;     223:; Loop: FUEL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;     263:; Loop: HIGHWAY ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


; Example in mark-up: 
;	      <li>461 miles on $20.30 (43 MPG diesel)</li>
;	      <li>461 miles on $20.30 (43 MPG diesel)</li>

;	      <li>485 miles on $17.40 (43.7 MPG diesel)</li>
;	      <li>946 miles on $37.70 (43.4 MPG diesel)</li>

; -------------------------------------------------------
; HIGHWAY: West to East ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; -------------------------------------------------------
(setq                 hwy_des (list "I-10"))
(setq                 hwy_odo (list (list 43502 43546)))
(setq                 hwy_tme (list (list (+ 14 (/ 45 60.0))
					(+ 16 (/ 25 60.0)))))
;
(setq hwy_des (append hwy_des (list "I-15")))
(setq hwy_odo (append hwy_odo (list (list 43546 43617))))
(setq hwy_tme (append hwy_tme (list (list (+ 16 (/ 25 60.0))
					  (+ 17 (/ 38 60.0))))))
;
(setq hwy_des (append hwy_des (list "All of I-40 in CA")))
(setq hwy_odo (append hwy_odo (list (list 43617 43771))))
(setq hwy_tme (append hwy_tme (list (list (+ 17 (/ (+ 38 10) 60.0))
					  (+ 19 (/ 47 60.0))))))
;
(setq hwy_des (append hwy_des (list "Colorado to Flagstaff")))
(setq hwy_odo (append hwy_odo (list (list 43771 43963))))
(setq hwy_tme (append hwy_tme (list (list (+ 19 (/ 47 60.0))
					  (+ 22 (/ 11 60.0))))))
;
(setq hwy_des (append hwy_des (list "Flagstaff to NM")))
(setq hwy_odo (append hwy_odo (list (list 43963 44135))))
(setq hwy_tme (append hwy_tme (list (list (+ 23 (/ 6 60.0))
					  (+ 25 (/ 7 60.0))))))
;
(setq hwy_des (append hwy_des (list "AZ to El Malpais")))
(setq hwy_odo (append hwy_odo (list (list 44135 44223))))
(setq hwy_tme (append hwy_tme (list (list (+ 25 (/ 7 60.0))
					  (+ 26 (/ 12 60.0))))))
;
(setq hwy_des (append hwy_des (list "El Malpais to Albquerque")))
(setq hwy_odo (append hwy_odo (list (list 44256 44323))))
(setq hwy_tme (append hwy_tme (list (list (+ 10 (/ 51 60.0))
					  (+ 11 (/ 42 60.0))))))
;
(setq hwy_des (append hwy_des (list "Albquerque to Tucumcari")))
(setq hwy_odo (append hwy_odo (list (list 44330 44499))))
(setq hwy_tme (append hwy_tme (list (list (+ 13 (/ 30 60.0))
					  (+ 15 (/ 38 60.0))))))
;
(setq hwy_des (append hwy_des (list "Tucumcari to TX")))
(setq hwy_odo (append hwy_odo (list (list 44506 44543))))
(setq hwy_tme (append hwy_tme (list (list (+ 16 (/ 2 60.0))
					  (+ 16 (/ 31 60.0))))))
;
(setq hwy_des (append hwy_des (list "NM to OK")))
(setq hwy_odo (append hwy_odo (list (list 44543 44718))))
(setq hwy_tme (append hwy_tme (list (list (+ 16 (/ 31 60.0))
					  (+ 19 (/ 1 60.0))))))
;
(setq hwy_des (append hwy_des (list "TX to rest area in OK")))
(setq hwy_odo (append hwy_odo (list (list 44718 44966))))
(setq hwy_tme (append hwy_tme (list (list (+ 19 (/ 1 60.0))
					  (+ 22 (/ 19 60.0))))))
;
(setq hwy_des (append hwy_des (list "Rest area in OK to AR")))
(setq hwy_odo (append hwy_odo (list (list 44966 45046))))
(setq hwy_tme (append hwy_tme (list (list (+ 9 (/ 26 60.0))
					  (+ 10 (/ 31 60.0))))))
;
(setq hwy_des (append hwy_des (list "OK to TN")))
(setq hwy_odo (append hwy_odo (list (list 45046 (- 45329 2)))))
(setq hwy_tme (append hwy_tme (list (list (+ 10 (/ 31 60.0))
					  (+ 14 (/ (- 42 24) 60.0))))))
;
(setq hwy_des (append hwy_des (list "AR to Cookeville, TN")))
(setq hwy_odo (append hwy_odo (list (list 45329 45617))))
(setq hwy_tme (append hwy_tme (list (list (+ 14 (/ 42 60.0))
					  (+ 18 (/ (- 46 8) 60.0))))))
;
(setq hwy_des (append hwy_des (list "Cookeville, TN to NC")))
(setq hwy_odo (append hwy_odo (list (list 45618 45781))))
(setq hwy_tme (append hwy_tme (list (list (+ 19 (/ 25 60.0))
					  (+ 21 (/ 37 60.0))))))
;
(setq hwy_des (append hwy_des (list "TN to Great Smokey Mts. N.P.")))
(setq hwy_odo (append hwy_odo (list (list 45781 45802))))
(setq hwy_tme (append hwy_tme (list (list (+ 21 (/ 37 60.0))
					  (+ 21 (/ 57 60.0))))))
;
(setq hwy_des (append hwy_des (list "Great Smokey Mts. N.P. to Chapel Hill, NC")))
(setq hwy_odo (append hwy_odo (list (list 45818 46059))))
(setq hwy_tme (append hwy_tme (list (list (+ 6 (/ 17 60.0))
					  (+ 9 (/ 52 60.0))))))
;
(setq hwy_des (append hwy_des (list "Carborro, NC to 301-N")))
(setq hwy_odo (append hwy_odo (list (list 46072 46242))))
(setq hwy_tme (append hwy_tme (list (list (+ 8 (/ (+ 46 10) 60.0))
					  (+ 11 (/ 31 60.0))))))
;
(setq hwy_des (append hwy_des (list "301-N")))
(setq hwy_odo (append hwy_odo (list (list 46242 46364))))
(setq hwy_tme (append hwy_tme (list (list (+ 11 (/ 31 60.0))
					  (+ 13 (/ 54 60.0))))))
;
(setq hwy_des (append hwy_des (list "301-N to Delaware")))
(setq hwy_odo (append hwy_odo (list (list 46364 46439))))
(setq hwy_tme (append hwy_tme (list (list (+ 13 (/ 54 60.0))
					  (+ 15 (/ 6 60.0))))))
;
(setq hwy_des (append hwy_des (list "Delaware")))
(setq hwy_odo (append hwy_odo (list (list 46439 46454))))
(setq hwy_tme (append hwy_tme (list (list (+ 15 (/ 6 60.0))
					  (+ 15 (/ 20 60.0))))))
;
(setq hwy_des (append hwy_des (list "New Jersey")))
(setq hwy_odo (append hwy_odo (list (list 46454 46577))))
(setq hwy_tme (append hwy_tme (list (list (+ 15 (/ 20 60.0))
					  (+ 17 (/ 6 60.0))))))
;
(setq hwy_des (append hwy_des (list "New York")))
(setq hwy_odo (append hwy_odo (list (list 46577 46601))))
(setq hwy_tme (append hwy_tme (list (list (+ 17 (/ 6 60.0))
					  (+ 17 (/ 33 60.0))))))
;
(setq hwy_des (append hwy_des (list "NY to Wallingford, CT")))
(setq hwy_odo (append hwy_odo (list (list 46601 46662))))
(setq hwy_tme (append hwy_tme (list (list (+ 17 (/ (+ 33 19) 60.0))
					  (+ 18 (/ 45 60.0))))))
;
(setq hwy_des (append hwy_des (list "Wallingford, CT to MA")))
(setq hwy_odo (append hwy_odo (list (list 46662 46725))))
(setq hwy_tme (append hwy_tme (list (list (+ 6 (/ 50 60.0))
					  (+ 7 (/ 45 60.0))))))
;
(setq hwy_des (append hwy_des (list "CT to Sandwich, MA")))
(setq hwy_odo (append hwy_odo (list (list 46725 46834))))
(setq hwy_tme (append hwy_tme (list (list (+ 7 (/ 45 60.0))
					  (+ 9 (/ 20 60.0))))))

; -------------------------------------------------------
; HIGHWAY: East to West ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; -------------------------------------------------------
(setq                 hwy_des (list "Brooklyn to Virginia"))
(setq                 hwy_odo (list (list 47916 48154)))
(setq                 hwy_tme (list (list (+ 9 (/ 37 60.0))
					(+ 13 (/ (- 36 7) 60.0)))))
;
(setq hwy_des (append hwy_des (list "Maryland to Alex's apt.")))
(setq hwy_odo (append hwy_odo (list (list 48154 48424))))
(setq hwy_tme (append hwy_tme (list (list (+ 13 (/ (+ 36 15) 60.0))
					  (+ 18 (/ 4 60.0))))))
;
(setq hwy_des (append hwy_des (list "Alex's apt. to Tennessee")))
(setq hwy_odo (append hwy_odo (list (list 48426 48694))))
(setq hwy_tme (append hwy_tme (list (list (+ 5 (/ (+ 35 18) 60.0))
					  (+ 9 (/ 57 60.0))))))
;
(setq hwy_des (append hwy_des (list "North Carolina to Mississippi River")))
(setq hwy_odo (append hwy_odo (list (list 48694 (- 49144 1)))))
(setq hwy_tme (append hwy_tme (list (list (+ 9 (/ 57 60.0))
					  (+ 16 (/ (- 37 36) 60.0))))))
;
(setq hwy_des (append hwy_des (list "Mississippi River to rest area")))
(setq hwy_odo (append hwy_odo (list (list 49144 (- 49653 1)))))
(setq hwy_tme (append hwy_tme (list (list (+ 16 (/ 37 60.0))
					  (+ 23 (/ (- 41 10) 60.0))))))
;
(setq hwy_des (append hwy_des (list "Rest area to Texas")))
(setq hwy_odo (append hwy_odo (list (list 49656 (- 49756 1)))))
(setq hwy_tme (append hwy_tme (list (list (+ 7 (/ 50 60.0))
					  (+ 9 (/ (- 30 19) 60.0))))))
;
(setq hwy_des (append hwy_des (list "Oklahoma to New Mexico: Texas")))
(setq hwy_odo (append hwy_odo (list (list 49756 49933))))
(setq hwy_tme (append hwy_tme (list (list (+ 9 (/ 30 60.0))
					  (+ 12 (/ 11 60.0))))))
;
(setq hwy_des (append hwy_des (list "Texas to Arizona: New Mexico")))
(setq hwy_odo (append hwy_odo (list (list 49933 (- 50302 1)))))
(setq hwy_tme (append hwy_tme (list (list (+ 12 (/ (+ 11 11) 60.0))
					  (+ 17 (/ (- 05 2) 60.0))))))
;
(setq hwy_des (append hwy_des (list "New Mexico to Seligman, Arizona")))
(setq hwy_odo (append hwy_odo (list (list 50302 (- 50535 8)))))
(setq hwy_tme (append hwy_tme (list (list (+ 17 (/ (+ 05 29) 60.0))
					  (+ 20 (/ 21 60.0))))))
;
(setq hwy_des (append hwy_des (list "Seligman, Arizona to California")))
(setq hwy_odo (append hwy_odo (list (list 50540 50661))))
(setq hwy_tme (append hwy_tme (list (list (+ 8 (/ 54 60.0))
					  (+ 10 (/ (- 36 11) 60.0))))))
;
(setq hwy_des (append hwy_des (list "Arizona to exit for Amboy, CA")))
(setq hwy_odo (append hwy_odo (list (list 50661 50700))))
(setq hwy_tme (append hwy_tme (list (list (+ 10 (/ 36 60.0))
					  (+ 11 (/ 06 60.0))))))
;
(setq hwy_des (append hwy_des (list "I-40 to I-10 via Twenty-nine Palms")))
(setq hwy_odo (append hwy_odo (list (list 50700 50836))))
(setq hwy_tme (append hwy_tme (list (list (+ 11 (/ 06 60.0))
					  (+ 13 (/ 13 60.0))))))
;
(setq hwy_des (append hwy_des (list "29 Palms to 101 & Vermont Ave.")))
(setq hwy_odo (append hwy_odo (list (list 50836 (- 50941 3)))))
(setq hwy_tme (append hwy_tme (list (list (+ 13 (/ (+ 13 34) 60.0))
					  (+ 15 (/ 13 60.0))))))
;
; (setq hwy_des (append hwy_des (list "DESCRIPTION")))
; (setq hwy_odo (append hwy_odo (list (list 111 999))))
; (setq hwy_tme (append hwy_tme (list (list (+ 1 (/ 2 60.0))
; 					  (+ 23 (/ 59 60.0))))))


; -------------------------------------------------------
; FUEL: West to East to West ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; -------------------------------------------------------
(setq                 fuel_des (list "Flagstaff, AZ"))
(setq                 fuel_odo (list (list 43502 43969)))
(setq                 fuel_gal (list 10.689))
(setq                 fuel_prc (list 20.30))
;
(setq fuel_des (append fuel_des (list "Tucumcari, NM")))
(setq fuel_odo (append fuel_odo (list (list 43969 44505))))
(setq fuel_gal (append fuel_gal (list 11.088)))
(setq fuel_prc (append fuel_prc (list 17.40)))
;
(setq fuel_des (append fuel_des (list "Van Buren, AR")))
(setq fuel_odo (append fuel_odo (list (list 44505 45053))))
(setq fuel_gal (append fuel_gal (list 11.716)))
(setq fuel_prc (append fuel_prc (list 17.80)))
;
(setq fuel_des
      (append fuel_des
	      (list "Cookeville, TN (not full tank) and Carrboro, NC")))
(setq fuel_odo (append fuel_odo (list (list 45053 46065))))
(setq fuel_gal (append fuel_gal (list (+ 9.741 12.013))))
(setq fuel_prc (append fuel_prc (list (+ 14.60 19.21))))
;
(setq fuel_des (append fuel_des (list "Dairen, CT")))
(setq fuel_odo (append fuel_odo (list (list 46065 46613))))
(setq fuel_gal (append fuel_gal (list 10.908)))
(setq fuel_prc (append fuel_prc (list 20.50)))
;
(setq fuel_des (append fuel_des (list "Raymond, NH (TWICE)")))
(setq fuel_odo (append fuel_odo (list (list 46613 47415))))
(setq fuel_gal (append fuel_gal (list (+ 6.025 12.176))))
(setq fuel_prc (append fuel_prc (list (+ 10.00 20.20))))
;
(setq fuel_des (append fuel_des (list "NJ Turnpike")))
(setq fuel_odo (append fuel_odo (list (list 47415 47998))))
(setq fuel_gal (append fuel_gal (list 12.339)))
(setq fuel_prc (append fuel_prc (list 18.50)))
;
(setq fuel_des (append fuel_des (list "Sugar Hill, NC")))
(setq fuel_odo (append fuel_odo (list (list 47998 48614))))
(setq fuel_gal (append fuel_gal (list 12.408)))
(setq fuel_prc (append fuel_prc (list 18.60)))
;
(setq fuel_des (append fuel_des (list "Arkansas")))
(setq fuel_odo (append fuel_odo (list (list 48614 49214))))
(setq fuel_gal (append fuel_gal (list 11.97))) ; pump accurate to 1/100
(setq fuel_prc (append fuel_prc (list 17.11)))
;
(setq fuel_des (append fuel_des (list "Erick, OK")))
(setq fuel_odo (append fuel_odo (list (list 49214 49749))))
(setq fuel_gal (append fuel_gal (list 11.85))) ; pump accurate to 1/100
(setq fuel_prc (append fuel_prc (list 15.75)))
;
(setq fuel_des (append fuel_des (list "Grants, NM (37 mi. east of Continental Divide)")))
(setq fuel_odo (append fuel_odo (list (list 49749 50217))))
(setq fuel_gal (append fuel_gal (list 11.477)))
(setq fuel_prc (append fuel_prc (list 19.50)))
;
(setq fuel_des (append fuel_des (list "Flagstaff, AZ")))
(setq fuel_odo (append fuel_odo (list (list 50217 50461))))
(setq fuel_gal (append fuel_gal (list 5.477)))
(setq fuel_prc (append fuel_prc (list 9.09)))
;
;                 THIS ONE NEEDS TO BE FILL-UP IN LOS ANGELES:
(setq fuel_des (append fuel_des (list "Los Angeles")))
(setq fuel_odo (append fuel_odo (list (list 50461 50976))))
(setq fuel_gal (append fuel_gal (list 11.897)))
(setq fuel_prc (append fuel_prc (list 19.50)))


; -------------------------------------------------------
; PROGRAM ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; -------------------------------------------------------

; User-defined function:
(defun rjc-real-to-time (real)
  (setq _i 1)
  (while (> real _i)
    (setq _i (+ _i 1)))
  (if (= 0 (mod real _i))
      (concat _i ":00")
    (concat (- _i 1) ":" (int-to-string (* 60 (- real (- _i 1)))))
    ))
; Examples:
(rjc-real-to-time 2.9) ; "2:53.99999999999999"
(rjc-real-to-time 3.0) ; "3:00"
(rjc-real-to-time 3.1) ; "3:6.000000000000005"

; Initialization:
(setq i (length fuel_des))
(setq fuel_des_drip fuel_des)
(setq fuel_odo_drip fuel_odo)
(setq fuel_gal_drip fuel_gal)
(setq fuel_prc_drip fuel_prc)
(setq fuel_odo_cume 0)
(setq fuel_gal_cume 0)
(setq fuel_prc_cume 0)

; Loop: FUEL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq fuel_report nil)
(while (> i 0)
  (setq fuel_des_data (car fuel_des_drip))
  (setq fuel_des_drip (cdr fuel_des_drip))
  ;
  (setq fuel_odo_data (car fuel_odo_drip))
  (setq fuel_odo_drip (cdr fuel_odo_drip))
  ;
  (setq fuel_gal_data (car fuel_gal_drip))
  (setq fuel_gal_drip (cdr fuel_gal_drip))
  ;
  (setq fuel_prc_data (car fuel_prc_drip))
  (setq fuel_prc_drip (cdr fuel_prc_drip))
  ;
  (setq fuel_odo_inc (- (car (cdr fuel_odo_data)) (car fuel_odo_data)))
  (setq fuel_odo_cume (+ fuel_odo_cume fuel_odo_inc))
  (setq fuel_gal_cume (+ fuel_gal_cume fuel_gal_data))
  (setq fuel_prc_cume (+ fuel_prc_cume fuel_prc_data))
  ;

  (setq _fuel_inc (format "Miles per gallon..............................
  %s:
    Tank: %d miles at $%6.2f (%4.1f MPG)"
		     fuel_des_data fuel_odo_inc
		     fuel_prc_data
		     (/ fuel_odo_inc fuel_gal_data)))

  (setq _fuel_tot (format "%s
    Trip: %d miles at $%6.2f (%4.1f MPG)"
		     "" fuel_odo_cume
		     fuel_prc_cume
		     (/ fuel_odo_cume fuel_gal_cume)))

  (setq fuel_report (concat fuel_report _fuel_inc))
  (setq fuel_report (concat fuel_report _fuel_tot))

  (setq i (- i 1))
  )

; Loop: HIGHWAY ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(setq i (length hwy_des))
(setq hwy_des_drip hwy_des)
(setq hwy_odo_drip hwy_odo)
(setq hwy_tme_drip hwy_tme)
(setq hwy_odo_cume 0)
(setq hwy_tme_cume 0)

(setq hwy_report nil)
(while (> i 0)
  (setq hwy_des_data (car hwy_des_drip))
  (setq hwy_des_drip (cdr hwy_des_drip))
  ;
  (setq hwy_odo_data (car hwy_odo_drip))
  (setq hwy_odo_drip (cdr hwy_odo_drip))
  ;
  (setq hwy_tme_data (car hwy_tme_drip))
  (setq hwy_tme_drip (cdr hwy_tme_drip))
  ;
  (setq hwy_odo_inc (- (car (cdr hwy_odo_data)) (car hwy_odo_data)))
  (setq hwy_tme_inc (- (car (cdr hwy_tme_data)) (car hwy_tme_data)))
  (setq hwy_odo_cume (+ hwy_odo_cume hwy_odo_inc))
  (setq hwy_tme_cume (+ hwy_tme_cume hwy_tme_inc))
  ;

  (setq _dist_inc (format "Mileage.......................................
  %s
    %d miles in %s (%d MPH)"
		     hwy_des_data hwy_odo_inc
		     (substring (rjc-real-to-time hwy_tme_inc) 0 6)
		     (/ hwy_odo_inc hwy_tme_inc)))

  (setq _dist_tot (format "
    %d miles in %s (%d MPH)
"
		     hwy_odo_cume
		     (substring (rjc-real-to-time hwy_tme_cume) 0 6)
		     (/ hwy_odo_cume hwy_tme_cume)))

  (setq hwy_report (concat hwy_report _dist_inc))
  (setq hwy_report (concat hwy_report _dist_tot))

  (setq i (- i 1))
  )

(message (concat _dist_inc _dist_tot _fuel_inc _fuel_tot))
(switch-to-buffer "*Messages*")
(end-of-buffer)

;   the end.
; -------------------------------------------------------