I wanted to write some python scripts that would provide me with basic astronomical ephemeris data, such as sunrise/sunset, twilight times, moonrise/moonset and moon phase, and planet positions, all specific to my location. My first approach was to use the algorithms in Meeus' Astronomical Algorithms. I got far enough to duplicate the sunrise/sunset tables provided on the USNO website (go here and click on "Data Services"). But it was time consuming to write the code, as I also had to debug and test it.
I had known about the NOVAS-C package from the USNO and I wished that it was written in python. I first tried to use SWIG to produce a DLL for python, but I was unable to get things to link correctly. Someone has already done this (find the file pynovas-0.1a.tar.gz on the web, probably at the Vaults of Parnassus), but I wished for a pure python solution, as I wouldn't be interested in speed of calculation.
I started thinking about how much time it would take me to translate the 1600 lines of C code into python. I decided to tackle the translation process by writing some python scripts to do most of the translation work; these scripts did about 90% of the work. I had to do the remainder by hand.
The first run of the novas.py script duplicated the test data with the NOVAS package to within 4-6 significant figures. This was a good sign, as it told me things were on the right track. I spent some time with a debugger and traced the discrepancy to three break statements that I should have removed (they were there from a C switch statement). After that fix, the python code duplicated the results of the C code for the test data included with the NOVAS-C package.
I did this work in early 2003. If you'd like access to the python scripts that did the translation, please email me.
The only surprise is that some parameters to NOVAS functions need to be passed as single element lists (those that aren't arrays). You'll need to look at the C prototypes to see which variables these are. For example, in the prototype
short int app_star (double tjd, body *earth, cat_entry *star,you'll need to know that body and cat_entry are structures in the C code and are passed as dictionaries in the python code. Where you see a pointer to a double, you know that is a variable that must be passed as a list with one element. The C code's prototypes (in novas.h in the NOVAS package) will also tell you which parameters are being passed as arrays.
double *ra, double *dec);
There are no guarantees that this software produces the correct output. You should verify that it produces the output you need before using it. If you have some critical application that needs to make use of the NOVAS routines, I would recommend that you utilize the NOVAS C or FORTRAN code.