A small, comfortable nook pertaining to technology, current events, astronomy, and sailing and navigation.

Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Thursday, February 14, 2008

Bit Reversal By Bit-Banging

Here's an interesting C function to reverse the bits of an unsigned integer:
unsigned int reverse(unsigned int v)
{
v = (((v & 0xaaaaaaaa) >> 1) |
((v & 0x55555555) << 1));
v = (((v & 0xcccccccc) >> 2) |
((v & 0x33333333) << 2));
v = (((v & 0xf0f0f0f0) >> 4) |
((v & 0x0f0f0f0f) << 4));
v = (((v & 0xff00ff00) >> 8) |
((v & 0x00ff00ff) << 8));
return((v >> 16) | (v << 16));
}
I really need my reverse(0x77ff0300) in the morning! Sorry, bad joke (and for the odd word-wrapping)...

Version Control With Subversion

Over the years, I've used more than a few methods of version or source control -- SCCS, RCS, CVS -- but I discovered that each had its weaknesses, and eventually stopped using them altogether. Then, about six months ago, I set aside my preconceived notions about learning yet another version control system (at the risk of wasting time), and began investigating Subversion. I cannot overemphasize how glad I am that I did. In addition to being significantly easier to use than CVS, Subversion provides atomic commits. This means that either the commit succeeds in its entirety, or it doesn't commit at all (i.e. all commits in the current context are rolled-back). This is a vital piece that insures the integrity of your data (e.g. if you experience a network or disk failure during the commit). Subversion also supports WebDAV access to the repository. This means that, in addition to direct access via the file:// method, and svn:// or svn+ssh:// protocol, a properly-configured Apache web server will allow access to the repository via http:// or https:// protocols.

If you're on the fence about whether or not Subversion can help you, or if you are seeking an experienced opinion about using it, leave a comment and I'll get back to you as soon as I can.

Pretty-Print With Enscript

Here's how I obtain high-quality, syntax-colored prints (or PDFs) of my source code files:
#!/bin/bash

ENSCRIPT_OPTS="--fancy-header=emacs -H3 -j -f Courier7"
ENSCRIPT_OPTS="${ENSCRIPT_OPTS} --color -2 -r -E"
ENSCRIPT_OPTS="${ENSCRIPT_OPTS} --mark-wrapped-lines=arrow"
ENSCRIPT_OPTS="${ENSCRIPT_OPTS} --ul-position=+125-25"

if [ $# -lt 1 ]; then
echo "Usage: ..."
exit 1
fi

FILE=${1}

enscript ${ENSCRIPT_OPTS} ${FILE} -o ${FILE}.ps
Enscript knows about dozens of types of source for colorizing its output. Once I've created the Postscript output, I can either print it as it is, or generate a PDF file for a handy on-screen reference.

Wednesday, September 26, 2007

When Will The Moon Be There Again?

While driving this evening sometime between sunset and the end of civil twilight, my two-and-a-half-year-old son noticed a blood-red, rising full moon. Upon seeing it, I immediately felt disappointed for not having my camera with me to photograph it in the midst of this particular farmland scene. I began to wonder when the full moon would be in that position again, which led me to begin thinking about how to solve the problem.

In theory, it seems there should be a fairly straightforward solution. First, determine the apparent azimuth and elevation (which may or may not be that easy; I cheated and used Planetarium, my Palm-based astronomy application) at the time of observation. The solution could then be determined by iteration or by rewriting the position determination equations to accept the azimuth, elevation, and position information. The former seems easiest to implement, but much more resource-intensive. The latter seems exceedingly difficult (at least for me) to implement, but would be preferred because of the ability to perform a direct calculation of the solution. If I have some time, I'll try to solve the problem using both methods.

Monday, September 24, 2007

JPL Ephemerides CD-ROM

A few days ago, I received the JPL Ephemerides CD-ROM I recently purchased from Willmann-Bell. Being a big fan of VSOP87, I hope to implement this theory in C in a short amount of time.

Wednesday, September 19, 2007

VSOP87 C Application Programming Interface (API)

On and off [albeit more off than on] over the past few years, I've been developing an astronomy C library. The crown jewel (in my opinion) is the VSOP87 portion of it since it solves the equations using the complete theory which is comprised of thousands of terms for each celestial body. A couple of days ago, I decided it was time to blow-off some of the dust and start working on it again. I did so by starting to write some documentation for the entire library using Doxygen, an open-source tool designed for such a task. If you're interested in seeing what I have done so far, point your browser at http://www.garychambers.com/orbital-docs/ and let me know what you think. I'm also trying to determine the license under which I should release the code, so I'd also appreciate any input you might have in that respect.