]> gitweb.michael.orlitzky.com - dead/census-tools.git/blob - jsroute/jsroute
Added the linear program solving the midatlantic region.
[dead/census-tools.git] / jsroute / jsroute
1 #!/bin/bash
2 #
3 # jsroute, a utility to route via Google Maps using Envjs.
4 #
5 # We take a starting point and a destination as arguments, and
6 # pass them off to a Javascript file (route.js) which is compiled
7 # on-the-fly using Mozilla's Rhino Javascript compiler. Then, magic
8 # occurs, and the JSON results are output to the command line.
9 #
10 # Soon the output will be piped through a Python script to convert
11 # it to (usable) KML.
12 #
13
14 # Some exit codes.
15 EXIT_MISSING_START=1
16 EXIT_MISSING_DESTINATION=2
17 EXIT_HELP=3
18 EXIT_GETOPT_UNHAPPY=4
19 EXIT_TOO_MANY_ARGS=5
20
21
22 # Empty by default.
23 ROUTENAME=""
24
25 # A function which just displays the usage information.
26 function usage {
27 echo ""
28 echo "Usage: $0 [-h] [-n \"name\"] \"<start>\" \"<destination>\""
29 echo ""
30 echo "ARGUMENTS"
31 echo " <start>, Your starting location. Use quotes."
32 echo " <destination>, Your destination. Use quotes."
33 echo ""
34 echo "OPTIONS"
35 echo " -h, Show the usage information and bail."
36 echo " -n <name>, Give the route a meaningful name. Use quotes."
37 echo ""
38 }
39
40
41 while getopts "hn:" option; do
42 case $option in
43 n ) ROUTENAME="$OPTARG";
44 # Shift the number of remaining arguments down by two,
45 # so that the non-option parameters are accessible via
46 # $1, $2, etc.
47 shift $((OPTIND-1));;
48 h ) usage;
49 exit $EXIT_HELP;;
50 * ) usage;
51 exit $EXIT_GETOPT_UNHAPPY;;
52 esac
53 done
54
55
56 # The non-option parameters.
57 START=$1
58 DESTINATION=$2
59
60 # Dollarsign-octothorpe contains the number of parameter arguments.
61 if [ "$#" -gt 2 ]; then
62 echo "Error: too many arguments. Maybe you forgot to place the source and destination in quotes?"
63 usage;
64 exit $EXIT_TOO_MANY_ARGS
65 fi
66
67 if [ "$START" == "" ]; then
68 usage;
69 exit $EXIT_MISSING_START
70 fi
71
72 if [ "$DESTINATION" == "" ]; then
73 usage;
74 exit $EXIT_MISSING_DESTINATION
75 fi
76
77 if [ "$ROUTENAME" == "" ]; then
78 # Set it to a default of "<start> to <destination>".
79 ROUTENAME="$START to $DESTINATION"
80 fi
81
82 java -jar ../lib/env-js/rhino/js.jar -opt -1 route.js "$1" "$2"