Astroconst v2.3, 3 June 2002 Created and maintained by Jeremy Bailin Java patch created by Colin McNally For all information and downloads, please see: http://web.astroconst.org/ 0. LICENSE Astroconst is completely free, both as in speech and beer. 1. INTRODUCTION Astroconst is a package of header files for a variety of languages that defines a plethora of astrophysical constants. The different language files are all generated from one central data file, so it is easy to add new constants. Currently supported languages are C, Fortran, Perl, Java, IDL and gnuplot. If you would like to see other languages, please email jbailin@astroconst.org with an example of the appropriate syntax in the language and/or a language reference. 2. INSTALLATION The astroconst package consists of the following files: README Documentation (this file) CHANGES Recent changes astroconst.h C header file astroconst.F Fortran header file astroconst.pl Perl header file astroconst.java Java source file astroconst.gp Gnuplot header file astroconst.ogp Gnuplot (old versions) header file AC_CGS.class Java CGS class file AC_MKS.class Java MKS class file AC_NA.class Java dimensionless class file (used by AC_CGS and AC_MKS) astroconst.idl IDL header file astroconst.dat Master data file for constants generate.pl Generates header files from master data file astrocalc Simple bc-like Perl-based calculator that uses astroconst astrocalc-mks Like astrocalc, but in MKS units examples/sample-cgs.c C CGS sample file examples/sample-mks.c C MKS sample file examples/sample-cgs.F Fortran CGS sample file examples/sample-mks.F Fortran MKS sample file examples/sample-cgs.pl Perl CGS sample file examples/sample-mks.pl Perl MKS sample file examples/sample-cgs.java Java CGS sample file examples/sample-mks.java Java MKS sample file examples/sample-cgs.idl IDL CGS sample file examples/sample-mks.idl IDL MKS sample file examples/sample-cgs.gp Gnuplot CGS sample file examples/sample-mks.gp Gnuplot MKS sample file examples/sample-cgs.ogp Gnuplot (old versions) CGS sample file examples/sample-mks.ogp Gnuplot (old versions) MKS sample file The header files can be put in such places as $HOME/include, /usr/local/include, or anywhere else that makes sense on your system. In the examples I use "/usr/local/include", but substitute this with the actual path on your system. 2.1. System-specific Changes 2.1.1. Disabling/Modifying Java Compilation When regenerating the header files, the Java source file is compiled by default using "javac" (which is assumed to be in the PATH). To change this, set $JAVAC in generate.pl to your compiler, or to '' to disable Java compilation. 2.1.2. Perls and Paths Depending on the location of perl and the astroconst header files on your system, you will need to change: a) The 'require' line in astrocalc to point to where astroconst.pl is installed. b) The #!/usr/bin/perl line in both generate.pl and astrocalc to where your Perl5 binary is installed (do a 'which perl' if you don't know offhand). Note: If you don't have Perl, it's still possible to use all of the other header files without a problem, but you won't be able to use the astrocalc utility or generate new header files. 3. USAGE 3.1. Header Files The names of the constants are all of the form A_constname. The list and description of constants can be found in astroconst.dat, or any of the header files. Examples of simple programs which use the constants are provided in the example/sample-system.language files, where system is one of "cgs" or "mks". 3.1.1. C To include the header file using CGS: #include "/usr/local/include/astroconst.h" To include the header file using MKS: #define MKS #include "/usr/local/include/astroconst.h" To use a constant: A_constname Eg. to find the light-crossing time of the sun: crosstime = 2 * A_rsun / A_c; 3.1.2. Fortran Fortran files which use Astroconst must use the C preprocessor (for many compilers, this means they must end in .F instead of .f). To include the header file using CGS: #include "/usr/local/include/astroconst.F" To include the header file using MKS: #define MKS #include '/usr/local/include/astroconst.F' To use a constant: A_constname Eg. to find the light-crossing time of the sun: crosstime = 2 * A_rsun / A_c 3.1.3. Perl To include the header file using CGS: require '/usr/local/include/astroconst.pl'; To include the header file using MKS: $MKS=1; require '/usr/local/include/astroconst.pl'; To use a constant: $A_constname Eg. to find the light-crossing time of the sun: $crosstime = 2 * $A_rsun / $A_c; 3.1.4. Java To include the header file using CGS: import AC_CGS; To include the header file using MKS: import AC_MKS; To use a constant: AC_CGS.A_constname or AC_MKS.A_constname Note that in Java it is possible to use both CGS and MKS by importing both classes and using the constant from whichever class you want. Eg. to find the light-crossing time of the sun: crosstime = 2 * AC_CGS.A_rsun / AC_CGS.A_c; 3.1.5. IDL NB: Due to the syntax of the IDL programming language, it is not possible to use the astroconst.idl file for command-line interpreted IDL use, only for separate programs. To include the header file using CGS: @/usr/local/include/astroconst.idl To include the header file using MKS: MKS=1 @/usr/local/include/astroconst.idl To use a constant: A_constname Eg. to find the light-crossing time of the sun: crosstime = 2 * A_rsun / A_c 3.1.6. Gnuplot There were many substantial changes made to gnuplot between versions 3.6 and 3.7, so I have created separate header files for each, with their own instructions. 3.1.6.1. Gnuplot 3.7 and later To include the header file using CGS: call '/usr/local/include/astroconst.gp' To include the header file using MKS: call '/usr/local/include/astroconst.gp' 1 To use a constant: A_constname Eg. to find the light-crossing time of the sun: crosstime = 2 * A_rsun / A_c 3.1.6.2. Gnuplot 3.6 and earlier To include the header file using CGS: MKS=0 load '/usr/local/include/astroconst.ogp' To include the header file using MKS: MKS=1 load '/usr/local/include/astroconst.ogp' To use a constant: A_constname Eg. to find the light-crossing time of the sun: crosstime = 2 * A_rsun / A_c 3.2. Adding Constants The list of constants, including their description and values in CGS and MKS, are in the file astroconst.dat, which can be modified to add new constants. The format of the data file is: constnamedescriptionCGS valueMKS value or constnamedescriptiondimensionless value Lines starting with '#' are comments and are ignore. To generate new language header files after modyfing astroconst.dat, run generate.pl. NOTE: If you do not want to compile the Java file, or your Java compiler is something other than "javac" (or not in your PATH), you will need to modify the $JAVAC line in generate.pl accordingly. 3.3. Astrocalc Astrocalc is a line-by-line interpreted bc-like calculator written in Perl. The astroconst constants (in CGS) are available as $A_constname. The way astrocalc works is by calling "eval" on every line, so anything you could do in a Perl program (eg. defining new variables and functions) you can do inside astrocalc. The following variables are also defined: $prev The last result evaluated @result The array of results in this session Here is a sample run, calculating the light-crossing time of the sun, the ratio of the Hubble time to that, and the length of the Hubble time in years: 2 * $A_rsun / $A_c result[1] 4.64321155465864 $crosstime = $result[1] result[2] 4.64321155465864 $A_tH / $crosstime result[3] 6.64476637275862e+16 $A_tH / $A_yr result[4] 9776000000 4. NOTES 4.1 "Parametrized constants" Some so-called constants are really parameters whose value depends on another unknown parameter. For example, the critical density of the universe depends on the imprecisely-known value of the Hubble constant. In these cases, the description of the constant will have a multiplicative (or divisive) factor at the end to show what the value A_constant really means. The following constants are parametrized: 4.1.1. A_rhoc "critical density /h^2" If the current value of the Hubble constant H_0 = h * 100 km/s/Mpc, then the critical density is A_rhoc * h * h. 4.1.2. A_tH "Hubble time *h" If the current value of the Hubble constant H_0 = h * 100 km/s/Mpc, then the Hubble time is A_tH / h. 5. ACKNOWLEDGEMENTS The Java port was originally written by Colin McNally.