Have you studied the software that is available on that page you linked to?
Does it not do what you want?
...R