Astro::Cosmology is a Perl module that can calculate cosmological distances, volumes, and times.
This module provides a set of routines to calculate a number of cosmological quantities based on distance and time. Some are a bit complex - e.g. the volume element at a given redshift - while some, such as the conversion between flux and luminosity, are more mundane.
To calculate results for a given cosmology you create an Astro::Cosmology object with the desired cosmological parameters, and then call the object's methods to perform the actual calculations. If you aren't used to objects, it may sound confusing; hopefully the SYNOPSIS section below will help (after all, a bit of code is worth a thousand words). The advantage of using an object-orientated interface is that the object can carry around the cosmological parameters, so you don't need to keep on specifying them whenever you want to calculate anything; it also means you can write routines which can just accept an Astro::Cosmology object rather than all the cosmological parameters.
This module requires that the PDL distribution is installed on your machine; PDL is available from CPAN or http://pdl.perl.org/
Whilst I believe the results are accurate, I do not guarantee this. Caveat emptor, as the Romans used to say...
use Astro::Cosmology qw( :constants );
# what is the luminosity distance, in metres, for
# a couple of cosmologies
my $z = sequence(10) / 10;
my $eds = Astro::Cosmology->new;
my $sn = Astro::Cosmology->new( matter => 0.3, lambda => 0.7 );
my $de = 1.0e6 * PARSEC * $eds->lum_dist($z);
my $ds = 1.0e6 * PARSEC * $sn->lum_dist($z);
# let's change the parameters of the $sn cosmology
$sn->setvars( lambda=>0.6, matter=>0.2 );
If H0 is set to 0, then the units used are the Hubble distance, volume per steradian, or time. If greater than zero, distances are measured in Mpc, volumes in Mpc^3/steradian, and time in years.