├── lib └── astrolib │ ├── coords │ ├── tests │ │ ├── __init__.py │ │ └── test_README.txt │ ├── jdnow.py │ ├── __init__.py │ ├── pytpm.py │ └── pytpm_wrapper.py │ └── __init__.py ├── doc ├── tpm.pdf ├── source │ ├── angsep.rst │ ├── astrodate.rst │ ├── coord.rst │ ├── position.rst │ ├── index.rst │ ├── pytpm_wrapper.rst │ └── intro.rst └── leap_seconds.txt ├── MANIFEST.in ├── src ├── jdnow.c ├── tpm │ ├── v6alpha.c │ ├── v6delta.c │ ├── ecl2equ.c │ ├── equ2ecl.c │ ├── v32v6.c │ ├── jd2j.c │ ├── jd_sum.c │ ├── jd_diff.c │ ├── v3unit.c │ ├── v6unit.c │ ├── m6O.c │ ├── m6I.c │ ├── m6v3.c │ ├── h2hms.c │ ├── d2dms.c │ ├── h2h.c │ ├── hms2h.c │ ├── v3scale.c │ ├── dms2d.c │ ├── j2jd.c │ ├── r2r.c │ ├── hms_sum.c │ ├── dms_sum.c │ ├── hms_diff.c │ ├── d2d.c │ ├── dms_diff.c │ ├── m3Rx.c │ ├── m3Ry.c │ ├── m3Rz.c │ ├── m6Qx.c │ ├── m6Qy.c │ ├── m6Qz.c │ ├── ymd2y.c │ ├── m6scale.c │ ├── dms2hms.c │ ├── m6inv.c │ ├── hms2dms.c │ ├── m6sum.c │ ├── m3O.c │ ├── m3scale.c │ ├── v3mod.c │ ├── v6mod.c │ ├── m3RxDot.c │ ├── m3RyDot.c │ ├── m3RzDot.c │ ├── m6diff.c │ ├── v6scale.c │ ├── v3sum.c │ ├── m3I.c │ ├── v3diff.c │ ├── y2doy.c │ ├── hadec2azel.c │ ├── m3m3.c │ ├── v3init.c │ ├── azel2hadec.c │ ├── fmt_alpha.c │ ├── m6v6.c │ ├── precess.c │ ├── v3dot.c │ ├── v6dot.c │ ├── m3v3.c │ ├── y2ymd.c │ ├── m3sum.c │ ├── misc.h │ ├── v62v3.c │ ├── ydd2ymd.c │ ├── j2dow.c │ ├── m3diff.c │ ├── m6m6.c │ ├── fmt_j.c │ ├── hms2hms.c │ ├── v6sum.c │ ├── jcal2j.c │ ├── jd_now.c │ ├── ymd2rdb.c │ ├── v6diff.c │ ├── m3inv.c │ ├── m6.h │ ├── ymd2dd.c │ ├── v3alpha.c │ ├── v3cross.c │ ├── v6cross.c │ ├── v6init.c │ ├── gcal2j.c │ ├── jd2jd.c │ ├── dms2dms.c │ ├── equ2gal.c │ ├── aberrate.c │ ├── gal2equ.c │ ├── fmt_rdb.c │ ├── v3s2c.c │ ├── fmt_ymd_raw.c │ ├── v3fmt.c │ ├── m3v6.c │ ├── m3fmt.c │ ├── eccentricity.c │ ├── utc_now.c │ ├── proper_motion.c │ ├── ymd2jd.c │ ├── v3delta.c │ ├── jd2ymd.c │ ├── ut12gmst.c │ ├── tdt2tdb.c │ ├── ellab.c │ ├── rdb2ymd.c │ ├── TPM_LICENSE.txt │ ├── v6fmt.c │ ├── solar_perigee.c │ ├── fmt_h.c │ ├── fmt_d.c │ ├── obliquity.c │ ├── j2gcal.c │ ├── j2jcal.c │ ├── v3c2s.c │ ├── trapzd.c │ ├── fmt_delta.c │ ├── ymd2ymd.c │ ├── geod2geoc.c │ ├── precess_m.c │ ├── ldeflect.c │ ├── refco.c │ ├── eterms.c │ ├── v6s2c.c │ ├── tpm_state.c │ ├── qromb.c │ ├── fmt_ymd.c │ ├── v6c2s.c │ ├── m6fmt.c │ ├── refract.c │ ├── argvParse.c │ ├── delta_AT.c │ ├── polint.c │ ├── v3.h │ ├── m3.h │ └── vec.h └── blackbox.c ├── setup.py ├── README.md ├── LICENSE.txt └── ReleaseNotes.txt /lib/astrolib/coords/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/tpm.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spacetelescope/astrolib.coords/master/doc/tpm.pdf -------------------------------------------------------------------------------- /lib/astrolib/__init__.py: -------------------------------------------------------------------------------- 1 | from pkgutil import extend_path 2 | __path__ = extend_path(__path__, __name__) 3 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include * 2 | recursive-include * * 3 | prune doc/build 4 | prune build 5 | prune dist 6 | exclude *.pyc *.pyo 7 | -------------------------------------------------------------------------------- /src/jdnow.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "tpm/astro.h" 3 | 4 | /* Simple program used to test astrodate.utc2jd function */ 5 | /* against TPM utc_now function. Use together with jdnow.py. */ 6 | 7 | int main() 8 | { 9 | 10 | double stamp; 11 | stamp=utc_now(); 12 | printf("Now (UTC JD): %f\n",stamp); 13 | } 14 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | try: 4 | from setuptools import setup 5 | except ImportError: 6 | from distribute_setup import use_setuptools 7 | use_setuptools() 8 | from setuptools import setup 9 | 10 | setup( 11 | setup_requires=['d2to1>=0.2.3', 'stsci.distutils'], 12 | d2to1=True, 13 | use_2to3=False, 14 | zip_safe=False 15 | ) 16 | -------------------------------------------------------------------------------- /lib/astrolib/coords/jdnow.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import, print_function 2 | 3 | """ Simple script used to test astrodate.utc2jd function 4 | against TPM utc_now function. Use together with jdnow.c.""" 5 | 6 | from .astrodate import utc2jd 7 | import datetime 8 | 9 | stamp=datetime.datetime.utcnow() 10 | print("Now (GM) = ", stamp) 11 | 12 | print("Now (UTC JD): %f"%utc2jd(stamp)) 13 | -------------------------------------------------------------------------------- /doc/source/angsep.rst: -------------------------------------------------------------------------------- 1 | ************* 2 | coords.angsep 3 | ************* 4 | 5 | .. currentmodule:: astrolib.coords 6 | 7 | Angular separation between two `~position.Position`. 8 | 9 | Can be defined by hand, or produced by "subtracting" two positions. 10 | Like `~position.Position`, it will have an internal representation, 11 | and a variety of user-selected representations. 12 | 13 | .. automodule:: astrolib.coords.angsep 14 | :members: 15 | :undoc-members: 16 | -------------------------------------------------------------------------------- /doc/source/astrodate.rst: -------------------------------------------------------------------------------- 1 | **************** 2 | coords.astrodate 3 | **************** 4 | 5 | .. automodule:: astrolib.coords.astrodate 6 | :members: 7 | :undoc-members: 8 | 9 | Global Variables 10 | ---------------- 11 | .. autodata:: astrolib.coords.astrodate.B1950 12 | .. autodata:: astrolib.coords.astrodate.J2000 13 | .. autodata:: astrolib.coords.astrodate.CB 14 | .. autodata:: astrolib.coords.astrodate.CJ 15 | .. autodata:: astrolib.coords.astrodate.MJD_0 16 | -------------------------------------------------------------------------------- /doc/source/coord.rst: -------------------------------------------------------------------------------- 1 | ********************* 2 | coords.position.Coord 3 | ********************* 4 | 5 | .. autoclass:: astrolib.coords.position.Coord 6 | 7 | Subclasses 8 | ^^^^^^^^^^ 9 | 10 | .. autoclass:: astrolib.coords.position.Degrees 11 | :members: 12 | :undoc-members: 13 | 14 | .. autoclass:: astrolib.coords.position.Hmsdms 15 | :members: 16 | :undoc-members: 17 | 18 | .. autoclass:: astrolib.coords.position.Radians 19 | :members: 20 | :undoc-members: 21 | -------------------------------------------------------------------------------- /doc/leap_seconds.txt: -------------------------------------------------------------------------------- 1 | Whenever a leap second is added to the civil calendar, 2 | the file src/tpm/delta_AT.c must be 3 | updated to reflect the new accumulated number of leap seconds for 4 | subsequent dates. 5 | 6 | You can compute the MJD test value that should be added to the code 7 | using the AstroDate class as follows: 8 | 9 | import datetime 10 | from coords import AstroDate 11 | 12 | newyear=datetime.datetime(2009,1,1) #year, month, day, 0, 0, 0 13 | t=AstroDate(newyear) 14 | t.mjd 15 | -------------------------------------------------------------------------------- /doc/source/position.rst: -------------------------------------------------------------------------------- 1 | ************************ 2 | coords.position.Position 3 | ************************ 4 | 5 | Position object to manage coordinate transformations. 6 | 7 | .. currentmodule:: astrolib.coords 8 | 9 | .. autoclass:: astrolib.coords.position.Position 10 | :members: 11 | :undoc-members: 12 | 13 | Utility Functions 14 | ^^^^^^^^^^^^^^^^^ 15 | 16 | .. autofunction:: astrolib.coords.position.dms 17 | 18 | .. autofunction:: astrolib.coords.position.gcdist 19 | 20 | .. autofunction:: astrolib.coords.position.hav 21 | 22 | .. autofunction:: astrolib.coords.position.ahav 23 | -------------------------------------------------------------------------------- /doc/source/index.rst: -------------------------------------------------------------------------------- 1 | .. AstroLib Coords documentation master file, created by 2 | sphinx-quickstart on Wed Oct 3 12:39:47 2012. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to AstroLib Coords's documentation! 7 | =========================================== 8 | 9 | Contents: 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | 14 | intro.rst 15 | position.rst 16 | coord.rst 17 | angsep.rst 18 | astrodate.rst 19 | pytpm_wrapper.rst 20 | 21 | 22 | Indices and tables 23 | ================== 24 | 25 | * :ref:`genindex` 26 | * :ref:`modindex` 27 | * :ref:`search` 28 | -------------------------------------------------------------------------------- /doc/source/pytpm_wrapper.rst: -------------------------------------------------------------------------------- 1 | ******************** 2 | coords.pytpm_wrapper 3 | ******************** 4 | 5 | .. automodule:: astrolib.coords.pytpm_wrapper 6 | :members: 7 | :undoc-members: 8 | 9 | Global Variables 10 | ---------------- 11 | 12 | .. autodata:: astrolib.coords.pytpm.b1950 13 | .. autodata:: astrolib.coords.pytpm.j2000 14 | .. autodata:: astrolib.coords.pytpm.CJ 15 | .. autodata:: astrolib.coords.pytpm.CB 16 | .. autodata:: astrolib.coords.pytpm.s01 17 | .. autodata:: astrolib.coords.pytpm.s02 18 | .. autodata:: astrolib.coords.pytpm.s03 19 | .. autodata:: astrolib.coords.pytpm.s04 20 | .. autodata:: astrolib.coords.pytpm.s05 21 | .. autodata:: astrolib.coords.pytpm.s06 22 | -------------------------------------------------------------------------------- /lib/astrolib/coords/__init__.py: -------------------------------------------------------------------------------- 1 | """Package: AstroLib Coords""" 2 | from __future__ import absolute_import 3 | from .position import Position 4 | from .angsep import AngSep 5 | from .astrodate import AstroDate 6 | 7 | from .version import * 8 | 9 | def _test(): 10 | """use nose to run the coords tests""" 11 | 12 | import nose 13 | 14 | # give a list of the names of modules that contain tests as 15 | # strings containing the fully qualified module name. It does 16 | # NOT work to pass the actual module object to nose. 17 | nose.run(defaultTest= [ 18 | 'astrolib.coords.tests.test_angsep', 19 | 'astrolib.coords.tests.test_astrodate', 20 | 'astrolib.coords.tests.test_tpm', 21 | 'astrolib.coords.test' 22 | ] 23 | ) 24 | 25 | test = _test 26 | -------------------------------------------------------------------------------- /src/tpm/v6alpha.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v6alpha.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v6alpha.c,v $ - return the angle in the x-y plane (right ascension) 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | double 24 | v6alpha(V6 v) 25 | { 26 | return(v3alpha(v6GetPos(v))); 27 | } 28 | -------------------------------------------------------------------------------- /src/tpm/v6delta.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v6delta.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v6delta.c,v $ - return the angle out of the x-y plane (declination) 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | double 24 | v6delta(V6 v) 25 | { 26 | return(v3delta(v6GetPos(v))); 27 | } 28 | -------------------------------------------------------------------------------- /lib/astrolib/coords/pytpm.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | from . import _pytpm 3 | 4 | # the only function defined in _pytpm 5 | blackbox = _pytpm.blackbox 6 | 7 | # These are constants that are supposed to be in astrolib.coords.pytpm 8 | # These constants used to come from astrolib.coords._pytpm but without 9 | # swig is it much easier to just define them in python here and then 10 | # stuff them back into _pytpm. 11 | b1950 = (2433282.42345905) 12 | j2000 = (2451545.0) 13 | CJ = (36525.0) # the julian century 14 | CB = (36524.21987817305) # the tropical century at 1900.0 15 | s01 = 1 16 | s02 = 2 17 | s03 = 3 18 | s04 = 4 19 | s05 = 5 20 | s06 = 6 21 | 22 | _pytpm.b1950 = b1950 23 | _pytpm.j2000 = j2000 24 | _pytpm.CJ = CJ 25 | _pytpm.CB = CB 26 | _pytpm.s01 = s01 27 | _pytpm.s02 = s02 28 | _pytpm.s03 = s03 29 | _pytpm.s04 = s04 30 | _pytpm.s05 = s05 31 | _pytpm.s06 = s06 32 | -------------------------------------------------------------------------------- /src/tpm/ecl2equ.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: ecl2equ.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: ecl2equ.c,v $ 18 | ** convert a state vector from ecliptic to FK5 equatorial 19 | ** ******************************************************************* 20 | */ 21 | 22 | #include "astro.h" 23 | 24 | V6 25 | ecl2equ(V6 v6, double obl) 26 | { 27 | v6 = m3v6(m3Rx(-obl), v6); 28 | 29 | return(v6); 30 | } 31 | -------------------------------------------------------------------------------- /src/tpm/equ2ecl.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: equ2ecl.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: equ2ecl.c,v $ 18 | ** convert a state vector from FK4 equatorial to ecliptic 19 | ** ******************************************************************* 20 | */ 21 | 22 | #include "astro.h" 23 | 24 | V6 25 | equ2ecl(V6 v6, double obl) 26 | { 27 | v6 = m3v6(m3Rx(obl), v6); 28 | 29 | return(v6); 30 | } 31 | -------------------------------------------------------------------------------- /src/tpm/v32v6.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v32v6.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v32v6.c,v $ - upgrade a 3-vector to a 6-vector 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | V6 24 | v32v6(V3 v3) 25 | { 26 | V6 v6; 27 | 28 | v6 = v6init(v3GetType(v3)); 29 | v6SetPos(v6, v3); 30 | 31 | return(v6); 32 | } 33 | -------------------------------------------------------------------------------- /src/tpm/jd2j.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: jd2j.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: jd2j.c,v $ - convert a jd time into a scalar julian date 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | double 24 | jd2j(JD jd) 25 | { 26 | double j; 27 | 28 | j = jdGetDay(jd) + (hms2h(jd.hms) / 24.0); 29 | 30 | return(j); 31 | } 32 | -------------------------------------------------------------------------------- /src/tpm/jd_sum.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: jd_sum.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: jd_sum.c,v $ - sum of two jd times 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | JD 24 | jd_sum(JD jd1, JD jd2) 25 | { 26 | jdIncDay(jd1, jdGetDay(jd2)); 27 | jd1.hms = hms_sum(jd1.hms, jd2.hms); 28 | 29 | return(jd1); 30 | } 31 | -------------------------------------------------------------------------------- /src/tpm/jd_diff.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: jd_diff.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: jd_diff.c,v $ - difference of two jd times 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | JD 24 | jd_diff(JD jd1, JD jd2) 25 | { 26 | jdDecDay(jd1, jdGetDay(jd2)); 27 | jd1.hms = hms_diff(jd1.hms, jd2.hms); 28 | 29 | return(jd1); 30 | } 31 | -------------------------------------------------------------------------------- /src/tpm/v3unit.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v3unit.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v3unit.c,v $ - return a unit 3-vector 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | V3 24 | v3unit(V3 v) 25 | { 26 | double m; 27 | 28 | m = v3mod(v); 29 | if (m != 0.0) { 30 | v = v3scale(v, 1/m); 31 | } 32 | 33 | return(v); 34 | } 35 | -------------------------------------------------------------------------------- /src/tpm/v6unit.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v6unit.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v6unit.c,v $ - return a unit 6-vector 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | V6 24 | v6unit(V6 v) 25 | { 26 | double m; 27 | 28 | m = v6mod(v); 29 | if (m != 0.0) { 30 | v = v6scale(v, 1/m); 31 | } 32 | 33 | return(v); 34 | } 35 | -------------------------------------------------------------------------------- /src/tpm/m6O.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m6O.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m6O.c,v $ - the null 6-matrix 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M6 24 | m6O(void) 25 | { 26 | M6 m; 27 | 28 | m.m[0][0] = m3O(); 29 | m.m[0][1] = m3O(); 30 | m.m[1][0] = m3O(); 31 | m.m[1][1] = m3O(); 32 | 33 | return(m); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/tpm/m6I.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m6I.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m6I.c,v $ - the identity 6-matrix 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M6 24 | m6I(double x) 25 | { 26 | M6 m; 27 | 28 | m.m[0][0] = m3I(x); 29 | m.m[0][1] = m3O(); 30 | m.m[1][0] = m3O(); 31 | m.m[1][1] = m3I(x); 32 | 33 | return(m); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/tpm/m6v3.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m6v3.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m6v3.c,v $ - product of a 6-matrix and a 3-vector. 18 | ** we define this operation to be a normal m6m6 with a null velocity component. 19 | ** ******************************************************************* 20 | */ 21 | 22 | #include "vec.h" 23 | 24 | V3 25 | m6v3(M6 m, V3 v) 26 | { 27 | v = m3v3(m6GetPP(m), v); 28 | 29 | return(v); 30 | } 31 | -------------------------------------------------------------------------------- /src/tpm/h2hms.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: h2hms.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: h2hms.c,v $ - convert scalar time to hms time 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | HMS 24 | h2hms(double h) 25 | { 26 | HMS hms; 27 | 28 | hmsSetHours(hms, h); 29 | hmsSetMinutes(hms, 0.0); 30 | hmsSetSeconds(hms, 0.0); 31 | 32 | return(hms); 33 | } 34 | -------------------------------------------------------------------------------- /src/tpm/d2dms.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: d2dms.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: d2dms.c,v $ - convert scalar degrees to dms angle 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | DMS 24 | d2dms(double d) 25 | { 26 | DMS dms; 27 | 28 | dmsSetDegrees(dms, d); 29 | dmsSetMinutes(dms, 0.0); 30 | dmsSetSeconds(dms, 0.0); 31 | 32 | return(dms); 33 | } 34 | -------------------------------------------------------------------------------- /src/tpm/h2h.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: h2h.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: h2h.c,v $ scalar hours 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include 22 | #include "times.h" 23 | 24 | double 25 | h2h(double h) 26 | { 27 | if (h < 0.0) { 28 | h += ceil(h / -24.0) * 24.0; 29 | } 30 | if (h >= 24.0) { 31 | h -= floor(h / 24.0) * 24.0; 32 | } 33 | 34 | return(h); 35 | } 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## NOTE: Superseded by Astropy Coordinates package! 2 | 3 | This package aims to provide much of the IDL "astron" functionality that 4 | pertains to coordinate manipulations in an OO framework. Our target user is 5 | a typical astronomer who needs to analyze data, work with catalogs, prepare 6 | observing proposals, and prepare for observing runs. 7 | 8 | It depends on numpy, which must already be installed on your 9 | system. 10 | 11 | It incorporates the TPM library, graciously contributed by Jeff 12 | Percival, to perform coordinate system transformations. This will be 13 | installed as part of the package installation. 14 | 15 | Install this package in the usual way: 16 | 17 | python setup.py install 18 | 19 | After installation, you can test the package as follows: 20 | 21 | >>> import coords as C 22 | >>> C._test() 23 | 24 | A successful test run will produce no output from this command. 25 | 26 | If you have questions about this module, send mail to 27 | help@stsci.edu and it will get to the appropriate 28 | person. 29 | -------------------------------------------------------------------------------- /src/tpm/hms2h.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: hms2h.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: hms2h.c,v $ - convert hms time into scalar time 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | double 24 | hms2h(HMS hms) 25 | { 26 | double h; 27 | 28 | h = hmsGetHours(hms); 29 | h += hmsGetMinutes(hms) / 60.0; 30 | h += hmsGetSeconds(hms) / 3600.0; 31 | 32 | return(h); 33 | } 34 | -------------------------------------------------------------------------------- /src/tpm/v3scale.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v3scale.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v3scale.c,v $ - 3-vector scaling 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | V3 24 | v3scale(V3 v, double s) 25 | { 26 | if (v3GetType(v) == CARTESIAN) { 27 | v3MulX(v, s); 28 | v3MulY(v, s); 29 | v3MulZ(v, s); 30 | } else { 31 | v3MulR(v, s); 32 | } 33 | 34 | return(v); 35 | } 36 | -------------------------------------------------------------------------------- /src/tpm/dms2d.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: dms2d.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: dms2d.c,v $ - convert dms angle to scalar degrees 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | double 24 | dms2d(DMS dms) 25 | { 26 | double d; 27 | 28 | d = dmsGetDegrees(dms); 29 | d += dmsGetMinutes(dms) / 60.0; 30 | d += dmsGetSeconds(dms) / 3600.0; 31 | 32 | return(d); 33 | } 34 | -------------------------------------------------------------------------------- /src/tpm/j2jd.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: j2jd.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: j2jd.c,v $ - convert a scalar julian date into a jd date 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | JD 24 | j2jd(double j) 25 | { 26 | JD jd; 27 | 28 | jdSetDay(jd, j); 29 | jdSetHours(jd, 0.0); 30 | jdSetMinutes(jd, 0.0); 31 | jdSetSeconds(jd, 0.0); 32 | 33 | return(jd); 34 | } 35 | -------------------------------------------------------------------------------- /src/tpm/r2r.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: r2r.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: r2r.c,v $ - normalize scalar radians 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | double 24 | r2r(double r) 25 | { 26 | if (r < 0.0) { 27 | r += ceil(r / (-2*M_PI)) * (2*M_PI); 28 | } 29 | if (r >= (2 * M_PI)) { 30 | r -= floor(r / (2*M_PI)) * (2*M_PI); 31 | } 32 | 33 | return(r); 34 | } 35 | -------------------------------------------------------------------------------- /src/tpm/hms_sum.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: hms_sum.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: hms_sum.c,v $ - sum of hms times 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | HMS 24 | hms_sum(HMS hms1, HMS hms2) 25 | { 26 | hmsIncHours(hms1, hmsGetHours(hms2)); 27 | hmsIncMinutes(hms1, hmsGetMinutes(hms2)); 28 | hmsIncSeconds(hms1, hmsGetSeconds(hms2)); 29 | 30 | return(hms1); 31 | } 32 | -------------------------------------------------------------------------------- /src/tpm/dms_sum.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: dms_sum.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: dms_sum.c,v $ - sum of dms angles 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | DMS 24 | dms_sum(DMS dms1, DMS dms2) 25 | { 26 | dmsIncDegrees(dms1, dmsGetDegrees(dms2)); 27 | dmsIncMinutes(dms1, dmsGetMinutes(dms2)); 28 | dmsIncSeconds(dms1, dmsGetSeconds(dms2)); 29 | 30 | return(dms1); 31 | } 32 | -------------------------------------------------------------------------------- /src/tpm/hms_diff.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: hms_diff.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: hms_diff.c,v $ - difference of hms times 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | HMS 24 | hms_diff(HMS hms1, HMS hms2) 25 | { 26 | hmsDecHours(hms1, hmsGetHours(hms2)); 27 | hmsDecMinutes(hms1, hmsGetMinutes(hms2)); 28 | hmsDecSeconds(hms1, hmsGetSeconds(hms2)); 29 | 30 | return(hms1); 31 | } 32 | -------------------------------------------------------------------------------- /src/tpm/d2d.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: d2d.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: d2d.c,v $ - normalize scalar degrees 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include 22 | #include "times.h" 23 | 24 | double 25 | d2d(double d) 26 | { 27 | 28 | if (d <= -360.0) { 29 | d += ceil(d / -360.0) * 360.0; 30 | } 31 | if (d >= 360.0) { 32 | d -= floor(d / 360.0) * 360.0; 33 | } 34 | 35 | return(d); 36 | } 37 | -------------------------------------------------------------------------------- /src/tpm/dms_diff.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: dms_diff.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: dms_diff.c,v $ - difference of dms angles 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | DMS 24 | dms_diff(DMS dms1, DMS dms2) 25 | { 26 | dmsDecDegrees(dms1, dmsGetDegrees(dms2)); 27 | dmsDecMinutes(dms1, dmsGetMinutes(dms2)); 28 | dmsDecSeconds(dms1, dmsGetSeconds(dms2)); 29 | 30 | return(dms1); 31 | } 32 | -------------------------------------------------------------------------------- /src/tpm/m3Rx.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m3Rx.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m3Rx.c,v $ - the R1 matrix from Yallop et al., AJ 97, 274. 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M3 24 | m3Rx(double x) 25 | { 26 | M3 m3; 27 | 28 | m3 = m3I(1.0); 29 | m3SetYY(m3, cos(x)); 30 | m3SetYZ(m3, sin(x)); 31 | m3SetZY(m3, -sin(x)); 32 | m3SetZZ(m3, cos(x)); 33 | 34 | return(m3); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/tpm/m3Ry.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m3Ry.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m3Ry.c,v $ - the R2 matrix from Yallop et al., AJ 97, 274. 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M3 24 | m3Ry(double y) 25 | { 26 | M3 m3; 27 | 28 | m3 = m3I(1.0); 29 | m3SetXX(m3, cos(y)); 30 | m3SetXZ(m3, -sin(y)); 31 | m3SetZX(m3, sin(y)); 32 | m3SetZZ(m3, cos(y)); 33 | 34 | return(m3); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/tpm/m3Rz.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m3Rz.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m3Rz.c,v $ - the R3 matrix from Yallop et al., AJ 97, 274. 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M3 24 | m3Rz(double z) 25 | { 26 | M3 m3; 27 | 28 | m3 = m3I(1.0); 29 | m3SetXX(m3, cos(z)); 30 | m3SetXY(m3, sin(z)); 31 | m3SetYX(m3, -sin(z)); 32 | m3SetYY(m3, cos(z)); 33 | 34 | return(m3); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/tpm/m6Qx.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m6Qx.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m6Qx.c,v $ - the Q1 matrix from Yallop et al., AJ 97, 274. 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M6 24 | m6Qx(double x, double xdot) 25 | { 26 | M6 m6; 27 | 28 | m6SetPP(m6, m3Rx(x)); 29 | m6SetPV(m6, m3O()); 30 | m6SetVP(m6, m3RxDot(x, xdot)); 31 | m6SetVV(m6, m3Rx(x)); 32 | 33 | return(m6); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/tpm/m6Qy.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m6Qy.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m6Qy.c,v $ - the Q2 matrix from Yallop et al., AJ 97, 274. 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M6 24 | m6Qy(double y, double ydot) 25 | { 26 | M6 m6; 27 | 28 | m6SetPP(m6, m3Ry(y)); 29 | m6SetPV(m6, m3O()); 30 | m6SetVP(m6, m3RyDot(y, ydot)); 31 | m6SetVV(m6, m3Ry(y)); 32 | 33 | return(m6); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/tpm/m6Qz.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m6Qz.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m6Qz.c,v $ - the Q3 matrix from Yallop et al., AJ 97, 274. 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M6 24 | m6Qz(double z, double zdot) 25 | { 26 | M6 m6; 27 | 28 | m6SetPP(m6, m3Rz(z)); 29 | m6SetPV(m6, m3O()); 30 | m6SetVP(m6, m3RzDot(z, zdot)); 31 | m6SetVV(m6, m3Rz(z)); 32 | 33 | return(m6); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/tpm/ymd2y.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: ymd2y.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: ymd2y.c,v $ - convert a ymd time into a scalar year 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | double 24 | ymd2y(YMD ymd) 25 | { 26 | double y; 27 | 28 | /* normalize the time */ 29 | ymd = ymd2ymd(ymd); 30 | 31 | y = (double)ymdGetYear(ymd) + (ymd2dd(ymd) / y2doy(ymdGetYear(ymd))); 32 | 33 | return(y); 34 | } 35 | -------------------------------------------------------------------------------- /src/tpm/m6scale.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m6scale.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m6scale.c,v $ - scale a 6-matrix by a constant 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M6 24 | m6scale(M6 m, double s) 25 | { 26 | m.m[0][0] = m3scale(m.m[0][0], s); 27 | m.m[0][1] = m3scale(m.m[0][1], s); 28 | m.m[1][0] = m3scale(m.m[1][0], s); 29 | m.m[1][1] = m3scale(m.m[1][1], s); 30 | 31 | return(m); 32 | } 33 | -------------------------------------------------------------------------------- /src/tpm/dms2hms.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: dms2hms.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: dms2hms.c,v $ - convert dms angle to hms time 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | HMS 24 | dms2hms(DMS dms) 25 | { 26 | HMS hms; 27 | 28 | hmsSetHours(hms, dmsGetDegrees(dms) / 15.0); 29 | hmsSetMinutes(hms, dmsGetMinutes(dms) / 15.0); 30 | hmsSetSeconds(hms, dmsGetSeconds(dms) / 15.0); 31 | 32 | return(hms); 33 | } 34 | -------------------------------------------------------------------------------- /src/tpm/m6inv.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m6inv.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m6inv.c,v $ - invert a 6-matrix 18 | ** we assume it is composed of orthogonal 3-matrices 19 | ** ******************************************************************* 20 | */ 21 | 22 | #include "vec.h" 23 | 24 | M6 25 | m6inv(M6 m) 26 | { 27 | m.m[0][0] = m3inv(m.m[0][0]); 28 | m.m[0][1] = m3inv(m.m[0][1]); 29 | m.m[1][0] = m3inv(m.m[1][0]); 30 | m.m[1][1] = m3inv(m.m[1][1]); 31 | 32 | return(m); 33 | } 34 | -------------------------------------------------------------------------------- /src/tpm/hms2dms.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: hms2dms.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: hms2dms.c,v $ - convert hms time into dms angle 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | DMS 24 | hms2dms(HMS hms) 25 | { 26 | DMS dms; 27 | 28 | dmsSetDegrees(dms, hmsGetHours(hms) * 15.0); 29 | dmsSetMinutes(dms, hmsGetMinutes(hms) * 15.0); 30 | dmsSetSeconds(dms, hmsGetSeconds(hms) * 15.0); 31 | 32 | return(dms); 33 | } 34 | -------------------------------------------------------------------------------- /src/tpm/m6sum.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m6sum.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m6sum.c,v $ - sum of two 6-matrices 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M6 24 | m6sum(M6 m1, M6 m2) 25 | { 26 | m1.m[0][0] = m3sum(m1.m[0][0], m2.m[0][0]); 27 | m1.m[0][1] = m3sum(m1.m[0][1], m2.m[0][1]); 28 | m1.m[1][0] = m3sum(m1.m[1][0], m2.m[1][0]); 29 | m1.m[1][1] = m3sum(m1.m[1][1], m2.m[1][1]); 30 | 31 | return(m1); 32 | } 33 | -------------------------------------------------------------------------------- /lib/astrolib/coords/tests/test_README.txt: -------------------------------------------------------------------------------- 1 | These test files are intended to be usable with pandokia, nose, or 2 | by importing the file and calling the functions directly. 3 | 4 | If you add more test files, be sure to add them to: 5 | __init__.py 6 | the stsci_python coords.snout file in the nightly regtests 7 | 8 | -- 9 | 10 | nosetests notes: 11 | 12 | You can run these directly from the source directory, but they 13 | require an installed copy of coords. 14 | 15 | -- 16 | 17 | pandokia notes: 18 | 19 | Use pdkrun on one of the test*.py files or use this in the file 20 | coords.snout : 21 | 22 | coords.test_angsep 23 | coords.test_astrodate 24 | coords.test_tpm 25 | coords.test_pos 26 | 27 | -- 28 | 29 | running directly: 30 | 31 | import coords 32 | coords.test() 33 | 34 | -- 35 | 36 | developer: 37 | 38 | Each test file has a function run() that calls each of the test 39 | functions without using any test framework. This works stand-alone, 40 | but the first failing test terminates your test run. 41 | 42 | The test functions can be called individually. 43 | 44 | -------------------------------------------------------------------------------- /src/tpm/m3O.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m3O.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m3O.c,v $ - the null 3-matrix 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M3 24 | m3O(void) 25 | { 26 | M3 m; 27 | 28 | m3SetXX(m, 0); 29 | m3SetXY(m, 0); 30 | m3SetXZ(m, 0); 31 | 32 | m3SetYX(m, 0); 33 | m3SetYY(m, 0); 34 | m3SetYZ(m, 0); 35 | 36 | m3SetZX(m, 0); 37 | m3SetZY(m, 0); 38 | m3SetZZ(m, 0); 39 | 40 | return(m); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/tpm/m3scale.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m3scale.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m3scale.c,v $ - scale a 3-matrix 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M3 24 | m3scale(M3 m, double s) 25 | { 26 | m3MulXX(m, s); 27 | m3MulXY(m, s); 28 | m3MulXZ(m, s); 29 | 30 | m3MulYX(m, s); 31 | m3MulYY(m, s); 32 | m3MulYZ(m, s); 33 | 34 | m3MulZX(m, s); 35 | m3MulZY(m, s); 36 | m3MulZZ(m, s); 37 | 38 | return(m); 39 | } 40 | -------------------------------------------------------------------------------- /src/tpm/v3mod.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v3mod.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v3mod.c,v $ - 3-vector modulus 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | double 24 | v3mod(V3 v) 25 | { 26 | double x = 0.0; 27 | 28 | if (v3GetType(v) == SPHERICAL) { 29 | x = fabs(v3GetR(v)); 30 | } else { 31 | x += v3GetX(v) * v3GetX(v); 32 | x += v3GetY(v) * v3GetY(v); 33 | x += v3GetZ(v) * v3GetZ(v); 34 | x = sqrt(x); 35 | } 36 | 37 | return(x); 38 | } 39 | -------------------------------------------------------------------------------- /src/tpm/v6mod.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v6mod.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v6mod.c,v $ - 6-vector modulus 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | double 24 | v6mod(V6 v) 25 | { 26 | double x = 0.0; 27 | 28 | if (v6GetType(v) == SPHERICAL) { 29 | x = fabs(v6GetR(v)); 30 | } else { 31 | x += v6GetX(v) * v6GetX(v); 32 | x += v6GetY(v) * v6GetY(v); 33 | x += v6GetZ(v) * v6GetZ(v); 34 | x = sqrt(x); 35 | } 36 | 37 | return(x); 38 | } 39 | -------------------------------------------------------------------------------- /src/tpm/m3RxDot.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m3RxDot.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m3RxDot.c,v $ - the R1-dot matrix from Yallop et al., AJ 97, 274. 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M3 24 | m3RxDot(double x, double xdot) 25 | { 26 | M3 m3; 27 | 28 | m3 = m3O(); 29 | m3SetYY(m3, xdot * -sin(x)); 30 | m3SetYZ(m3, xdot * cos(x)); 31 | m3SetZY(m3, xdot * -cos(x)); 32 | m3SetZZ(m3, xdot * -sin(x)); 33 | 34 | return(m3); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/tpm/m3RyDot.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m3RyDot.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m3RyDot.c,v $ - the R2-dot matrix from Yallop et al., AJ 97, 274. 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M3 24 | m3RyDot(double y, double ydot) 25 | { 26 | M3 m3; 27 | 28 | m3 = m3O(); 29 | m3SetXX(m3, ydot * -sin(y)); 30 | m3SetXZ(m3, ydot * -cos(y)); 31 | m3SetZX(m3, ydot * cos(y)); 32 | m3SetZZ(m3, ydot * -sin(y)); 33 | 34 | return(m3); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/tpm/m3RzDot.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m3RzDot.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m3RzDot.c,v $ - the R3-dot matrix from Yallop et al., AJ 97, 274. 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M3 24 | m3RzDot(double z, double zdot) 25 | { 26 | M3 m3; 27 | 28 | m3 = m3O(); 29 | m3SetXX(m3, zdot * -sin(z)); 30 | m3SetXY(m3, zdot * cos(z)); 31 | m3SetYX(m3, zdot * -cos(z)); 32 | m3SetYY(m3, zdot * -sin(z)); 33 | 34 | return(m3); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/tpm/m6diff.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m6diff.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m6diff.c,v $ - the difference of two 6-matrices 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M6 24 | m6diff(M6 m1, M6 m2) 25 | { 26 | M6 m; 27 | 28 | m.m[0][0] = m3diff(m1.m[0][0], m2.m[0][0]); 29 | m.m[0][1] = m3diff(m1.m[0][1], m2.m[0][1]); 30 | m.m[1][0] = m3diff(m1.m[1][0], m2.m[1][0]); 31 | m.m[1][1] = m3diff(m1.m[1][1], m2.m[1][1]); 32 | 33 | return(m); 34 | } 35 | -------------------------------------------------------------------------------- /src/tpm/v6scale.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v6scale.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v6scale.c,v $ - 6-vector scaling 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | V6 24 | v6scale(V6 v, double s) 25 | { 26 | if (v6GetType(v) == CARTESIAN) { 27 | v6MulX(v, s); 28 | v6MulY(v, s); 29 | v6MulZ(v, s); 30 | v6MulXDot(v, s); 31 | v6MulYDot(v, s); 32 | v6MulZDot(v, s); 33 | } else { 34 | v6MulR(v, s); 35 | v6MulRDot(v, s); 36 | } 37 | 38 | return(v); 39 | } 40 | -------------------------------------------------------------------------------- /src/tpm/v3sum.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v3sum.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v3sum.c,v $ - 3-vector sum 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | V3 24 | v3sum(V3 v1, V3 v2) 25 | { 26 | if (v3GetType(v1) == SPHERICAL) { 27 | v1 = v3s2c(v1); 28 | } 29 | 30 | if (v3GetType(v2) == SPHERICAL) { 31 | v2 = v3s2c(v2); 32 | } 33 | 34 | v3IncX(v1, v3GetX(v2)); 35 | v3IncY(v1, v3GetY(v2)); 36 | v3IncZ(v1, v3GetZ(v2)); 37 | 38 | return(v1); 39 | } 40 | -------------------------------------------------------------------------------- /src/tpm/m3I.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m3I.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m3I.c,v $ - the identity 3-matrix (scaled by the given value) 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M3 24 | m3I(double x) 25 | { 26 | M3 m; 27 | 28 | m3SetXX(m, x); 29 | m3SetXY(m, 0); 30 | m3SetXZ(m, 0); 31 | 32 | m3SetYX(m, 0); 33 | m3SetYY(m, x); 34 | m3SetYZ(m, 0); 35 | 36 | m3SetZX(m, 0); 37 | m3SetZY(m, 0); 38 | m3SetZZ(m, x); 39 | 40 | return(m); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/tpm/v3diff.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v3diff.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v3diff.c,v $ - 3-vector difference 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | V3 24 | v3diff(V3 v1, V3 v2) 25 | { 26 | 27 | if (v3GetType(v1) == SPHERICAL) { 28 | v1 = v3s2c(v1); 29 | } 30 | 31 | if (v3GetType(v2) == SPHERICAL) { 32 | v2 = v3s2c(v2); 33 | } 34 | 35 | v3DecX(v1, v3GetX(v2)); 36 | v3DecY(v1, v3GetY(v2)); 37 | v3DecZ(v1, v3GetZ(v2)); 38 | 39 | return(v1); 40 | } 41 | -------------------------------------------------------------------------------- /src/tpm/y2doy.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: y2doy.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: y2doy.c,v $ - return days per year given the gregorian proleptic calendar year 18 | ** 0 => 1 BC 19 | ** ******************************************************************* 20 | */ 21 | 22 | #include "times.h" 23 | 24 | int 25 | y2doy(int y) 26 | { 27 | int doy; 28 | 29 | if ((y % 400) == 0) { 30 | doy = 366; 31 | } else if ((y % 100) == 0) { 32 | doy = 365; 33 | } else if ((y % 4) == 0) { 34 | doy = 366; 35 | } else { 36 | doy = 365; 37 | } 38 | 39 | return(doy); 40 | } 41 | -------------------------------------------------------------------------------- /src/tpm/hadec2azel.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: hadec2azel.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: hadec2azel.c,v $ 18 | ** convert a state vector from (ha,dec) to (az,el) 19 | ** ******************************************************************* 20 | */ 21 | 22 | #include "astro.h" 23 | 24 | V6 25 | hadec2azel(V6 v6, double latitude) 26 | { 27 | /* rotate by (90-latitude) in the plane of the meridian */ 28 | v6 = m3v6(m3Ry((M_PI/2 - latitude)), v6); 29 | 30 | /* do a simple rotation about Z through 180 degrees */ 31 | v6 = m3v6(m3Rz(M_PI), v6); 32 | 33 | return(v6); 34 | } 35 | -------------------------------------------------------------------------------- /src/tpm/m3m3.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m3m3.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m3m3.c,v $ - product of two 3-matrices 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M3 24 | m3m3(M3 m1, M3 m2) 25 | { 26 | int row, col; 27 | int i; 28 | M3 m; 29 | 30 | for (row = 0; row < 3; row++) { 31 | for (col = 0; col < 3; col++) { 32 | m.m[row][col] = 0; 33 | for (i = 0; i < 3; i++) { 34 | m.m[row][col] += m1.m[row][i] * m2.m[i][col]; 35 | } 36 | } 37 | } 38 | 39 | return(m); 40 | } 41 | -------------------------------------------------------------------------------- /src/tpm/v3init.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v3init.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v3init.c,v $ - 3-vector initialization 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | V3 24 | v3init(int type) 25 | { 26 | V3 v; 27 | 28 | if (type == SPHERICAL) { 29 | v3SetType(v, SPHERICAL); 30 | v3SetR(v, 0.0); 31 | v3SetAlpha(v, 0.0); 32 | v3SetDelta(v, 0.0); 33 | } else { 34 | v3SetType(v, CARTESIAN); 35 | v3SetX(v, 0.0); 36 | v3SetY(v, 0.0); 37 | v3SetZ(v, 0.0); 38 | } 39 | 40 | return(v); 41 | } 42 | -------------------------------------------------------------------------------- /src/tpm/azel2hadec.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: azel2hadec.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: azel2hadec.c,v $ 18 | ** convert a state vector form (az,el) to (ha,dec) 19 | ** ******************************************************************* 20 | */ 21 | 22 | #include "astro.h" 23 | 24 | V6 25 | azel2hadec(V6 v6, double latitude) 26 | { 27 | /* do a simple rotation about Z through 180 degrees */ 28 | v6 = m3v6(m3Rz(-M_PI), v6); 29 | 30 | /* rotate by -(90-latitude) in the plane of the meridian */ 31 | v6 = m3v6(m3Ry(-(M_PI/2 - latitude)), v6); 32 | 33 | return(v6); 34 | } 35 | -------------------------------------------------------------------------------- /src/tpm/fmt_alpha.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: fmt_alpha.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: fmt_alpha.c,v $ - format a scalar angle as time from 0 to 24 hours 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | char * 24 | fmt_alpha(double alpha) 25 | { 26 | HMS hms; 27 | 28 | if (alpha < 0.0) { 29 | alpha += ceil(alpha / (-2*M_PI)) * 2*M_PI; 30 | } 31 | 32 | if (alpha >= 2*M_PI) { 33 | alpha -= floor(alpha / (2*M_PI)) * 2*M_PI; 34 | } 35 | 36 | hms = r2hms(alpha); 37 | 38 | return(fmt_hms(hms)); 39 | } 40 | -------------------------------------------------------------------------------- /src/tpm/m6v6.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m6v6.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m6v6.c,v $ - product of a 6-matrix and a 6-vector 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | V6 24 | m6v6(M6 m, V6 v1) 25 | { 26 | V6 v2; 27 | 28 | if (v6GetType(v1) == SPHERICAL) { 29 | v1 = v6s2c(v1); 30 | } 31 | 32 | v2 = v6init(CARTESIAN); 33 | 34 | v2.v[0] = v3sum(m3v3(m.m[0][0], v1.v[0]), m3v3(m.m[0][1], v1.v[1])); 35 | v2.v[1] = v3sum(m3v3(m.m[1][0], v1.v[0]), m3v3(m.m[1][1], v1.v[1])); 36 | 37 | return(v2); 38 | } 39 | -------------------------------------------------------------------------------- /src/tpm/precess.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: precess.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: precess.c,v $ 18 | ** precess a state vector 19 | ** ******************************************************************* 20 | */ 21 | 22 | #include "astro.h" 23 | 24 | #undef DEBUG 25 | 26 | V6 27 | precess(double j1, double j2, V6 v6, int pflag) 28 | { 29 | M6 pm; /* the precession matrix */ 30 | 31 | pm = precess_m(j1, j2, pflag, PRECESS_INERTIAL); 32 | 33 | #ifdef DEBUG 34 | (void)fprintf(stdout, "precess: pm \n%s\n", m6fmt(pm)); 35 | #endif 36 | 37 | v6 = m6v6(pm, v6); 38 | 39 | return(v6); 40 | } 41 | -------------------------------------------------------------------------------- /src/tpm/v3dot.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v3dot.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v3dot.c,v $ - 3-vector dot product 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | double 24 | v3dot(V3 v1, V3 v2) 25 | { 26 | double x = 0; 27 | 28 | if (v3GetType(v1) == SPHERICAL) { 29 | v1 = v3s2c(v1); 30 | } 31 | 32 | if (v3GetType(v2) == SPHERICAL) { 33 | v2 = v3s2c(v2); 34 | } 35 | 36 | x += v3GetX(v1) * v3GetX(v2); 37 | x += v3GetY(v1) * v3GetY(v2); 38 | x += v3GetZ(v1) * v3GetZ(v2); 39 | 40 | return(x); 41 | } 42 | -------------------------------------------------------------------------------- /src/tpm/v6dot.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v6dot.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v6dot.c,v $ - 6-vector dot product 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | double 24 | v6dot(V6 v1, V6 v2) 25 | { 26 | double x = 0; 27 | 28 | if (v6GetType(v1) == SPHERICAL) { 29 | v1 = v6s2c(v1); 30 | } 31 | 32 | if (v6GetType(v2) == SPHERICAL) { 33 | v2 = v6s2c(v2); 34 | } 35 | 36 | x += v6GetX(v1) * v6GetX(v2); 37 | x += v6GetY(v1) * v6GetY(v2); 38 | x += v6GetZ(v1) * v6GetZ(v2); 39 | 40 | return(x); 41 | } 42 | -------------------------------------------------------------------------------- /src/tpm/m3v3.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m3v3.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m3v3.c,v $ - product of a 3-matrix and a 3-vector 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | V3 24 | m3v3(M3 m, V3 v1) 25 | { 26 | int row, col; 27 | V3 v2; 28 | 29 | if (v3GetType(v1) == SPHERICAL) { 30 | v1 = v3s2c(v1); 31 | } 32 | 33 | v2 = v3init(CARTESIAN); 34 | 35 | for (row = 0; row < 3; row++) { 36 | for (col = 0; col < 3; col++) { 37 | v2.v[row] += m.m[row][col] * v1.v[col]; 38 | } 39 | } 40 | 41 | return(v2); 42 | } 43 | -------------------------------------------------------------------------------- /src/tpm/y2ymd.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: y2ymd.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: y2ymd.c,v $ - convert a scalar year into a ymd year 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | YMD 24 | y2ymd(double y) 25 | { 26 | YMD ymd; 27 | double f; 28 | 29 | f = floor(y); 30 | ymdSetYear(ymd, (int)f); 31 | 32 | ymdSetMonth(ymd, 1); 33 | 34 | ymdSetDay(ymd, (y - f) * y2doy(ymdGetYear(ymd))); 35 | 36 | ymdSetHours(ymd, 0.0); 37 | ymdSetMinutes(ymd, 0.0); 38 | ymdSetSeconds(ymd, 0.0); 39 | 40 | return(ymd); 41 | } 42 | -------------------------------------------------------------------------------- /src/tpm/m3sum.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m3sum.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m3sum.c,v $ - sum of two 3-matrices 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M3 24 | m3sum(M3 m1, M3 m2) 25 | { 26 | m3IncXX(m1, m3GetXX(m2)); 27 | m3IncXY(m1, m3GetXY(m2)); 28 | m3IncXZ(m1, m3GetXZ(m2)); 29 | 30 | m3IncYX(m1, m3GetYX(m2)); 31 | m3IncYY(m1, m3GetYY(m2)); 32 | m3IncYZ(m1, m3GetYZ(m2)); 33 | 34 | m3IncZX(m1, m3GetZX(m2)); 35 | m3IncZY(m1, m3GetZY(m2)); 36 | m3IncZZ(m1, m3GetZZ(m2)); 37 | 38 | return(m1); 39 | } 40 | -------------------------------------------------------------------------------- /src/tpm/misc.h: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: misc.h,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: misc.h,v $ - header file for miscellaneous routines 18 | ** ******************************************************************* 19 | */ 20 | 21 | 22 | #ifndef MISC_H 23 | 24 | #include 25 | 26 | #define REAL (0) 27 | #define IMAG (1) 28 | 29 | 30 | #define MISC_H 31 | 32 | #endif 33 | 34 | extern double trapzd(double (*func)(double), double a, double b, int n); 35 | extern double polint(double *xa, double *ya, int n, double x, double *dy); 36 | extern double qromb(double (*func)(double), double a, double b, double 37 | eps, int imax); 38 | -------------------------------------------------------------------------------- /src/tpm/v62v3.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v62v3.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v62v3.c,v $ - downgrade a 6-vector to a 3-vector by adding space motion 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | V3 24 | v62v3(V6 v6, double dt) 25 | { 26 | V3 v3; 27 | 28 | if (v6GetType(v6) == SPHERICAL) { 29 | v6 = v6s2c(v6); 30 | } 31 | 32 | v3 = v3init(CARTESIAN); 33 | v3SetX(v3, v6GetX(v6) + v6GetXDot(v6) * dt); 34 | v3SetY(v3, v6GetY(v6) + v6GetYDot(v6) * dt); 35 | v3SetZ(v3, v6GetZ(v6) + v6GetZDot(v6) * dt); 36 | 37 | return(v3); 38 | } 39 | -------------------------------------------------------------------------------- /src/tpm/ydd2ymd.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: ydd2ymd.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: ydd2ymd.c,v $ - given a year and a day, return a ymd structure 18 | ** note that dd is a double, not an int. 19 | ** it can have a fractional part. 20 | ** ******************************************************************* 21 | */ 22 | 23 | #include "times.h" 24 | 25 | YMD 26 | ydd2ymd(int y, double dd) 27 | { 28 | YMD ymd; 29 | 30 | ymdSetYear(ymd, y); 31 | ymdSetMonth(ymd, 1); 32 | ymdSetDay(ymd, dd); 33 | ymdSetHours(ymd, 0.0); 34 | ymdSetMinutes(ymd, 0.0); 35 | ymdSetSeconds(ymd, 0.0); 36 | 37 | return(ymd); 38 | } 39 | -------------------------------------------------------------------------------- /src/tpm/j2dow.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: j2dow.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: j2dow.c,v $ - map a julian day number onto the day of the week. (0 = sunday) 18 | ** the algorithm is from 19 | ** The Explanatory Supplement to the Astronomical Almanac (1992), 20 | ** section 12.91, equation 12.91-1, page 603. 21 | ** ******************************************************************* 22 | */ 23 | 24 | #include "times.h" 25 | 26 | int 27 | j2dow(double j) 28 | { 29 | int i; 30 | 31 | /* remember to round the JD to the next higher civil day */ 32 | i = (int)(j+0.5) - 7 * (((int)(j+0.5) + 1) / 7) + 1; 33 | 34 | return(i); 35 | } 36 | -------------------------------------------------------------------------------- /src/tpm/m3diff.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m3diff.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m3diff.c,v $ - the difference of two 3-matrices 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M3 24 | m3diff(M3 m1, M3 m2) 25 | { 26 | m3DecXX(m1, m3GetXX(m2)); 27 | m3DecXY(m1, m3GetXY(m2)); 28 | m3DecXZ(m1, m3GetXZ(m2)); 29 | 30 | m3DecYX(m1, m3GetYX(m2)); 31 | m3DecYY(m1, m3GetYY(m2)); 32 | m3DecYZ(m1, m3GetYZ(m2)); 33 | 34 | m3DecZX(m1, m3GetZX(m2)); 35 | m3DecZY(m1, m3GetZY(m2)); 36 | m3DecZZ(m1, m3GetZZ(m2)); 37 | 38 | return(m1); 39 | } 40 | -------------------------------------------------------------------------------- /src/tpm/m6m6.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m6m6.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m6m6.c,v $ - product of twp 6-matrices 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | M6 24 | m6m6(M6 m1, M6 m2) 25 | { 26 | M6 m; 27 | 28 | m.m[0][0] = m3sum(m3m3(m1.m[0][0],m2.m[0][0]),m3m3(m1.m[0][1],m2.m[1][0])); 29 | m.m[0][1] = m3sum(m3m3(m1.m[0][0],m2.m[0][1]),m3m3(m1.m[0][1],m2.m[1][1])); 30 | m.m[1][0] = m3sum(m3m3(m1.m[1][0],m2.m[0][0]),m3m3(m1.m[1][1],m2.m[1][0])); 31 | m.m[1][1] = m3sum(m3m3(m1.m[1][0],m2.m[0][1]),m3m3(m1.m[1][1],m2.m[1][1])); 32 | 33 | return(m); 34 | } 35 | -------------------------------------------------------------------------------- /src/tpm/fmt_j.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: fmt_j.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: fmt_j.c,v $ - format julian date 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include 22 | #include "times.h" 23 | 24 | #define NBUF (5) 25 | static char buf[NBUF][32]; 26 | static int nxtbuf = 0; 27 | 28 | char * 29 | fmt_j(double j) 30 | { 31 | char *p; 32 | double h; 33 | int d; 34 | 35 | /* get a buffer */ 36 | p = buf[nxtbuf++]; 37 | nxtbuf %= NBUF; 38 | 39 | d = floor(j); 40 | h = (j - d) * 24; 41 | 42 | (void)sprintf(p, "%8d %s", d, fmt_h(h)); 43 | 44 | return(p); 45 | } 46 | -------------------------------------------------------------------------------- /src/tpm/hms2hms.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: hms2hms.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: hms2hms.c,v $ - normalize an hms time 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | HMS 24 | hms2hms(HMS hms) 25 | { 26 | double x; 27 | 28 | /* convert to decimal hours */ 29 | x = hms2h(hms); 30 | hmsSetHours(hms, floor(x)); 31 | 32 | /* promote the minutes part */ 33 | x = (x - floor(x)) * 60.0; 34 | hmsSetMinutes(hms, floor(x)); 35 | 36 | /* promote the seconds part */ 37 | x = (x - floor(x)) * 60.0; 38 | hmsSetSeconds(hms, x); 39 | 40 | return(hms); 41 | } 42 | -------------------------------------------------------------------------------- /src/tpm/v6sum.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v6sum.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v6sum.c,v $ - 6-vector sum 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | V6 24 | v6sum(V6 v1, V6 v2) 25 | { 26 | if (v6GetType(v1) == SPHERICAL) { 27 | v1 = v6s2c(v1); 28 | } 29 | 30 | if (v6GetType(v2) == SPHERICAL) { 31 | v2 = v6s2c(v2); 32 | } 33 | 34 | v6IncX(v1, v6GetX(v2)); 35 | v6IncY(v1, v6GetY(v2)); 36 | v6IncZ(v1, v6GetZ(v2)); 37 | v6IncXDot(v1, v6GetXDot(v2)); 38 | v6IncYDot(v1, v6GetYDot(v2)); 39 | v6IncZDot(v1, v6GetZDot(v2)); 40 | 41 | return(v1); 42 | } 43 | -------------------------------------------------------------------------------- /src/tpm/jcal2j.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: jcal2j.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: jcal2j.c,v $ - map a julian proleptic calendar date onto a julian day number 18 | ** the algorithm is from 19 | ** The Explanatory Supplement to the Astronomical Almanac (1992), 20 | ** section 12.95, equation 12.95-x, page 606. 21 | ** ******************************************************************* 22 | */ 23 | 24 | #include "times.h" 25 | 26 | double 27 | jcal2j(int y, int m, int d) 28 | { 29 | int j; 30 | 31 | j = 367 * y; 32 | j -= (7 * (y + 5001 + (m - 9) / 7)) / 4; 33 | j += (275 * m) / 9; 34 | j += d; 35 | j += 1729777; 36 | 37 | return((double)j); 38 | } 39 | -------------------------------------------------------------------------------- /src/tpm/jd_now.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: jd_now.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: jd_now.c,v $ - return the current UTC julian day number 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include 22 | #include "times.h" 23 | 24 | JD 25 | jd_now(void) 26 | { 27 | JD jd; 28 | double j; 29 | time_t t; 30 | 31 | /* get the julian day number of the epoch */ 32 | j = gcal2j(1970, 1, 1) - 0.5; 33 | 34 | /* get the elapsed seconds since the unix epoch */ 35 | t = time(&t); 36 | 37 | /* offset to now */ 38 | j += (double)t / 86400; 39 | 40 | jd = j2jd(j); 41 | 42 | return(jd); 43 | } 44 | -------------------------------------------------------------------------------- /src/tpm/ymd2rdb.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: ymd2rdb.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: ymd2rdb.c,v $ - convert a ymd time into an rdb time 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | double 24 | ymd2rdb(YMD ymd) 25 | { 26 | double rdb; 27 | 28 | /* make sure the time is well formed */ 29 | ymd = ymd2ymd(ymd); 30 | 31 | rdb = (ymdGetYear(ymd) % 100) * 1e4; 32 | rdb += ymdGetMonth(ymd) * 1e2; 33 | rdb += ymdGetDay(ymd); 34 | rdb += ymdGetHours(ymd) / 1e2; 35 | rdb += ymdGetMinutes(ymd) / 1e4; 36 | rdb += ymdGetSeconds(ymd) / 1e6; 37 | 38 | return(rdb); 39 | } 40 | -------------------------------------------------------------------------------- /src/tpm/v6diff.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v6diff.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v6diff.c,v $ - 6-vector difference 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | V6 24 | v6diff(V6 v1, V6 v2) 25 | { 26 | if (v6GetType(v1) == SPHERICAL) { 27 | v1 = v6s2c(v1); 28 | } 29 | 30 | if (v6GetType(v2) == SPHERICAL) { 31 | v2 = v6s2c(v2); 32 | } 33 | 34 | v6DecX(v1, v6GetX(v2)); 35 | v6DecY(v1, v6GetY(v2)); 36 | v6DecZ(v1, v6GetZ(v2)); 37 | v6DecXDot(v1, v6GetXDot(v2)); 38 | v6DecYDot(v1, v6GetYDot(v2)); 39 | v6DecZDot(v1, v6GetZDot(v2)); 40 | 41 | return(v1); 42 | } 43 | -------------------------------------------------------------------------------- /src/tpm/m3inv.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m3inv.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m3inv.c,v $ - invert a 3-matrix 18 | ** we assume orthogonality, so the inverse is merely the transpose 19 | ** ******************************************************************* 20 | */ 21 | 22 | #include "vec.h" 23 | 24 | M3 25 | m3inv(M3 m) 26 | { 27 | M3 mi; 28 | 29 | m3SetXX(mi, m3GetXX(m)); 30 | m3SetXY(mi, m3GetYX(m)); 31 | m3SetXZ(mi, m3GetZX(m)); 32 | 33 | m3SetYX(mi, m3GetXY(m)); 34 | m3SetYY(mi, m3GetYY(m)); 35 | m3SetYZ(mi, m3GetZY(m)); 36 | 37 | m3SetZX(mi, m3GetXZ(m)); 38 | m3SetZY(mi, m3GetYZ(m)); 39 | m3SetZZ(mi, m3GetZZ(m)); 40 | 41 | return(mi); 42 | } 43 | -------------------------------------------------------------------------------- /src/tpm/m6.h: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m6.h,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ********************************************************************** 17 | ** $RCSfile: m6.h,v $ - 18 | ********************************************************************** 19 | */ 20 | 21 | #ifndef M6_INCLUDE 22 | #define M6_INCLUDE 23 | 24 | typedef struct s_m6 { 25 | M3 m[2][2]; 26 | } M6; 27 | 28 | #define m6GetPP(m6) (m6.m[0][0]) 29 | #define m6GetPV(m6) (m6.m[0][1]) 30 | #define m6GetVP(m6) (m6.m[1][0]) 31 | #define m6GetVV(m6) (m6.m[1][1]) 32 | 33 | #define m6SetPP(m6,m3) (m6.m[0][0] = (m3)) 34 | #define m6SetPV(m6,m3) (m6.m[0][1] = (m3)) 35 | #define m6SetVP(m6,m3) (m6.m[1][0] = (m3)) 36 | #define m6SetVV(m6,m3) (m6.m[1][1] = (m3)) 37 | 38 | /* EXTERN_START */ 39 | /* EXTERN_STOP */ 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/tpm/ymd2dd.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: ymd2dd.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: ymd2dd.c,v $ - convert a ymd time into a scalar day 18 | ** note the day is a double, not an int 19 | ** ******************************************************************* 20 | */ 21 | 22 | #include "times.h" 23 | 24 | double 25 | ymd2dd(YMD ymd) 26 | { 27 | double dd; 28 | double j0; 29 | double j; 30 | 31 | /* normalize the time */ 32 | ymd = ymd2ymd(ymd); 33 | 34 | /* get the julian day number of the target date */ 35 | j = ymd2j(ymd); 36 | 37 | /* get the julian day number of the start of the year */ 38 | j0 = gcal2j(ymdGetYear(ymd), 1, 1) - 0.5; 39 | 40 | dd = j - j0 + 1; 41 | 42 | return(dd); 43 | } 44 | -------------------------------------------------------------------------------- /src/tpm/v3alpha.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v3alpha.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v3alpha.c,v $ - return the angle in the x-y plane (right ascension) 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | double 24 | v3alpha(V3 v) 25 | { 26 | double alpha; 27 | 28 | if (v3GetType(v) == CARTESIAN) { 29 | v = v3c2s(v); 30 | } 31 | 32 | alpha = v3GetAlpha(v); 33 | if (v3GetR(v) < 0.0) { 34 | alpha += M_PI; 35 | } 36 | 37 | if (alpha < 0.0) { 38 | alpha += ceil(alpha / (-2 * M_PI)) * (2 * M_PI); 39 | } 40 | if (alpha >= (2 * M_PI)) { 41 | alpha -= floor(alpha / (2 * M_PI)) * (2 * M_PI); 42 | } 43 | 44 | return(alpha); 45 | } 46 | -------------------------------------------------------------------------------- /src/tpm/v3cross.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v3cross.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v3cross.c,v $ - 3-vector cross product 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | V3 24 | v3cross(V3 v1, V3 v2) 25 | { 26 | V3 v; 27 | 28 | if (v3GetType(v1) == SPHERICAL) { 29 | v1 = v3s2c(v1); 30 | } 31 | 32 | if (v3GetType(v2) == SPHERICAL) { 33 | v2 = v3s2c(v2); 34 | } 35 | 36 | v = v3init(CARTESIAN); 37 | 38 | v3SetX(v, v3GetY(v1) * v3GetZ(v2) - v3GetZ(v1) * v3GetY(v2)); 39 | v3SetY(v, v3GetZ(v1) * v3GetX(v2) - v3GetX(v1) * v3GetZ(v2)); 40 | v3SetZ(v, v3GetX(v1) * v3GetY(v2) - v3GetY(v1) * v3GetX(v2)); 41 | 42 | return(v); 43 | } 44 | -------------------------------------------------------------------------------- /src/tpm/v6cross.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v6cross.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v6cross.c,v $ - 6-vector cross product 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | V6 24 | v6cross(V6 v1, V6 v2) 25 | { 26 | V6 v; 27 | 28 | if (v6GetType(v1) == SPHERICAL) { 29 | v1 = v6s2c(v1); 30 | } 31 | 32 | if (v6GetType(v2) == SPHERICAL) { 33 | v2 = v6s2c(v2); 34 | } 35 | 36 | v = v6init(CARTESIAN); 37 | 38 | v6SetX(v, v6GetY(v1) * v6GetZ(v2) - v6GetZ(v1) * v6GetY(v2)); 39 | v6SetY(v, v6GetZ(v1) * v6GetX(v2) - v6GetX(v1) * v6GetZ(v2)); 40 | v6SetZ(v, v6GetX(v1) * v6GetY(v2) - v6GetY(v1) * v6GetX(v2)); 41 | 42 | return(v); 43 | } 44 | -------------------------------------------------------------------------------- /src/tpm/v6init.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v6init.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v6init.c,v $ - 6-vector initialization 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | V6 24 | v6init(int type) 25 | { 26 | V6 v; 27 | 28 | if (type == SPHERICAL) { 29 | v6SetType(v, POLAR); 30 | v6SetR(v, 0.0); 31 | v6SetAlpha(v, 0.0); 32 | v6SetDelta(v, 0.0); 33 | v6SetRDot(v, 0.0); 34 | v6SetAlphaDot(v, 0.0); 35 | v6SetDeltaDot(v, 0.0); 36 | } else { 37 | v6SetType(v, CARTESIAN); 38 | v6SetX(v, 0.0); 39 | v6SetY(v, 0.0); 40 | v6SetZ(v, 0.0); 41 | v6SetXDot(v, 0.0); 42 | v6SetYDot(v, 0.0); 43 | v6SetZDot(v, 0.0); 44 | } 45 | 46 | return(v); 47 | } 48 | -------------------------------------------------------------------------------- /src/tpm/gcal2j.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: gcal2j.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: gcal2j.c,v $ - map a gregorian proleptic calendar date onto a julian day number 18 | ** the algorithm is from 19 | ** The Explanatory Supplement to the Astronomical Almanac (1992), 20 | ** section 12.92, equation 12.92-1, page 604. 21 | ** ******************************************************************* 22 | */ 23 | 24 | #include "times.h" 25 | 26 | double 27 | gcal2j(int y, int m, int d) 28 | { 29 | int j; 30 | 31 | j = (1461 * (y + 4800 + (m - 14) / 12)) / 4; 32 | j += (367 * (m - 2 - 12 * ((m - 14) / 12))) / 12; 33 | j -= (3 * ((y + 4900 + (m - 14) / 12) / 100)) / 4; 34 | j += d; 35 | j -= 32075; 36 | 37 | return((double)j); 38 | } 39 | -------------------------------------------------------------------------------- /src/tpm/jd2jd.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: jd2jd.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: jd2jd.c,v $ - normalize a jd time 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | JD 24 | jd2jd(JD jd) 25 | { 26 | double x; 27 | 28 | /* convert to decimal days */ 29 | x = jd2j(jd); 30 | jdSetDay(jd, floor(x)); 31 | 32 | /* promote the hours part */ 33 | x = (x - floor(x)) * 24.0; 34 | jdSetHours(jd, floor(x)); 35 | 36 | /* promote the minutes part */ 37 | x = (x - floor(x)) * 60.0; 38 | jdSetMinutes(jd, floor(x)); 39 | 40 | /* promote the seconds part */ 41 | x = (x - floor(x)) * 60.0; 42 | jdSetSeconds(jd, x); 43 | 44 | return(jd); 45 | } 46 | -------------------------------------------------------------------------------- /src/tpm/dms2dms.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: dms2dms.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: dms2dms.c,v $ - normalize a dms angle 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | DMS 24 | dms2dms(DMS dms) 25 | { 26 | double x; 27 | 28 | /* convert to decimal degrees */ 29 | x = dms2d(dms); 30 | dmsSetDegrees(dms, floor(x)); 31 | 32 | /* promote the minutes part */ 33 | x = (x - floor(x)) * 60.0; 34 | dmsSetMinutes(dms, floor(x)); 35 | 36 | /* promote the seconds part */ 37 | x = (x - floor(x)) * 60.0; 38 | dmsSetSeconds(dms, x); 39 | 40 | /* normalize the degrees */ 41 | dmsSetDegrees(dms, d2d(dmsGetDegrees(dms))); 42 | 43 | return(dms); 44 | } 45 | -------------------------------------------------------------------------------- /src/tpm/equ2gal.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: equ2gal.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: equ2gal.c,v $ 18 | ** convert a state vector from FK4 equatorial to galactic 19 | ** 20 | ** the galactic pole is at (ra,dec) = (192.25, 27.4) degrees, 21 | ** and the longitude of the ascending node of the galactic plane 22 | ** on the equator is 33 degrees. 23 | ** the transformation is Rz(90-lon) * Ry(90-dec) * Rz(ra) 24 | ** ******************************************************************* 25 | */ 26 | 27 | #include "astro.h" 28 | 29 | V6 30 | equ2gal(V6 v6) 31 | { 32 | /* subtract e-terms */ 33 | v6 = ellab(B1950, v6, -1); 34 | 35 | v6 = m3v6(m3Rz(d2r(GAL_RA)), v6); 36 | v6 = m3v6(m3Ry(d2r(90-GAL_DEC)), v6); 37 | v6 = m3v6(m3Rz(d2r(90-GAL_LON)), v6); 38 | 39 | return(v6); 40 | } 41 | -------------------------------------------------------------------------------- /src/tpm/aberrate.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: aberrate.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: aberrate.c,v $ 18 | ** apply aberration of light to a state vector. 19 | ** ******************************************************************* 20 | */ 21 | 22 | #include "astro.h" 23 | 24 | V6 25 | aberrate(V6 p, V6 e, int flag) 26 | { 27 | double tau; 28 | 29 | tau = v6mod(p) / (IAU_C*(86400/IAU_AU)); 30 | 31 | /* ensure cartesian vectors */ 32 | p = v6s2c(p); 33 | e = v6s2c(e); 34 | 35 | if (flag > 0) { 36 | v6IncX(p, v6GetXDot(e) * tau); 37 | v6IncY(p, v6GetYDot(e) * tau); 38 | v6IncZ(p, v6GetZDot(e) * tau); 39 | } else { 40 | v6DecX(p, v6GetXDot(e) * tau); 41 | v6DecY(p, v6GetYDot(e) * tau); 42 | v6DecZ(p, v6GetZDot(e) * tau); 43 | } 44 | 45 | return(p); 46 | } 47 | -------------------------------------------------------------------------------- /src/tpm/gal2equ.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: gal2equ.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: gal2equ.c,v $ 18 | ** convert a state vector from galactic to FK4 equatorial 19 | ** 20 | ** the galactic pole is at (ra,dec) = (192.25, 27.4) degrees, 21 | ** and the longitude of the ascending node of the galactic plane 22 | ** on the equator is 33 degrees. 23 | ** the transformation is Rz(-ra) * Ry(-(90-dec)) * Rz(-(90-lon)) 24 | ** ******************************************************************* 25 | */ 26 | 27 | #include "astro.h" 28 | 29 | V6 30 | gal2equ(V6 v6) 31 | { 32 | v6 = m3v6(m3Rz(-d2r(90-GAL_LON)), v6); 33 | v6 = m3v6(m3Ry(-d2r(90-GAL_DEC)), v6); 34 | v6 = m3v6(m3Rz(-d2r(GAL_RA)), v6); 35 | 36 | /* add e-terms */ 37 | v6 = ellab(B1950, v6, 1); 38 | 39 | return(v6); 40 | } 41 | -------------------------------------------------------------------------------- /src/tpm/fmt_rdb.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: fmt_rdb.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: fmt_rdb.c,v $ - format an rdb date 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include 22 | #include "times.h" 23 | 24 | #define NRDBBUF 5 25 | static char rdbbuf[NRDBBUF][32]; 26 | static int nxtrdbbuf = 0; 27 | 28 | char * 29 | fmt_rdb(double rdb) 30 | { 31 | char *p; 32 | int fpart; 33 | int ipart; 34 | 35 | /* get a buffer */ 36 | p = rdbbuf[nxtrdbbuf++]; 37 | nxtrdbbuf %= NRDBBUF; 38 | *p = '\0'; 39 | 40 | /* make sure the time is well-formed */ 41 | rdb = rdb2rdb(rdb); 42 | 43 | ipart = (int)rdb; 44 | fpart = 1e6 * (rdb - ipart); 45 | 46 | (void)sprintf(p, "%d.%06d", ipart, fpart); 47 | 48 | return(p); 49 | } 50 | -------------------------------------------------------------------------------- /src/tpm/v3s2c.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v3s2c.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v3s2c.c,v $ - 3-vector spherical to cartesian 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | /* some convenience macros */ 24 | #define X (v3GetX(vc)) 25 | #define Y (v3GetY(vc)) 26 | #define Z (v3GetZ(vc)) 27 | #define R (v3GetR(vs)) 28 | #define A (v3GetAlpha(vs)) 29 | #define D (v3GetDelta(vs)) 30 | 31 | V3 32 | v3s2c(V3 vs) 33 | { 34 | double rcosd; 35 | V3 vc; 36 | 37 | if (v3GetType(vs) == CARTESIAN) { 38 | return(vs); 39 | } 40 | 41 | vc = v3init(CARTESIAN); 42 | 43 | rcosd = R*cos(D); 44 | 45 | v3SetX(vc, rcosd*cos(A)); 46 | v3SetY(vc, rcosd*sin(A)); 47 | v3SetZ(vc, R*sin(D)); 48 | 49 | return(vc); 50 | } 51 | -------------------------------------------------------------------------------- /src/tpm/fmt_ymd_raw.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: fmt_ymd_raw.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: fmt_ymd_raw.c,v $ - format a ymd time as it is expected from a user. 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include 22 | #include "times.h" 23 | 24 | #define NYMDBUF 5 25 | static char ymdbuf[NYMDBUF][32]; 26 | static int nxtymdbuf = 0; 27 | 28 | char * 29 | fmt_ymd_raw(YMD ymd) 30 | { 31 | char *p; 32 | 33 | /* get a buffer */ 34 | p = ymdbuf[nxtymdbuf++]; 35 | nxtymdbuf %= NYMDBUF; 36 | 37 | (void)sprintf(p, "%d %d %.15g %.15g %.15g %.15g", 38 | ymdGetYear(ymd), 39 | ymdGetMonth(ymd), 40 | ymdGetDay(ymd), 41 | ymdGetHours(ymd), 42 | ymdGetMinutes(ymd), 43 | ymdGetSeconds(ymd)); 44 | 45 | return(p); 46 | } 47 | -------------------------------------------------------------------------------- /src/tpm/v3fmt.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v3fmt.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v3fmt.c,v $ - format a 3-vector 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include 22 | #include "vec.h" 23 | 24 | #define NV3BUF (5) 25 | static char v3buf[NV3BUF][BUFSIZ]; 26 | static int nxtv3buf = 0; 27 | 28 | char * 29 | v3fmt(V3 v) 30 | { 31 | char *p; 32 | 33 | /* get a buffer */ 34 | p = v3buf[nxtv3buf++]; 35 | nxtv3buf %= NV3BUF; 36 | 37 | if (v3GetType(v) == CARTESIAN) { 38 | (void)sprintf(p, "%22.15e %22.15e %22.15e", 39 | v3GetX(v), 40 | v3GetY(v), 41 | v3GetZ(v)); 42 | } else { 43 | (void)sprintf(p, "%22.15e %22.15e %22.15e", 44 | v3GetR(v), 45 | v3GetAlpha(v), 46 | v3GetDelta(v)); 47 | } 48 | 49 | return(p); 50 | } 51 | -------------------------------------------------------------------------------- /src/tpm/m3v6.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m3v6.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m3v6.c,v $ - product of a 3-matrix and a 6-vector. 18 | ** we define this operation to be multiplying both position and velocity 19 | ** components of the 6-vector by the matrix. 20 | ** ******************************************************************* 21 | */ 22 | 23 | #include "vec.h" 24 | 25 | V6 26 | m3v6(M3 m, V6 v1) 27 | { 28 | int row, col; 29 | V6 v2; 30 | 31 | if (v6GetType(v1) == SPHERICAL) { 32 | v1 = v6s2c(v1); 33 | } 34 | 35 | v2 = v6init(CARTESIAN); 36 | 37 | for (row = 0; row < 3; row++) { 38 | for (col = 0; col < 3; col++) { 39 | v2.v[POS].v[row] += m.m[row][col] * v1.v[POS].v[col]; 40 | v2.v[VEL].v[row] += m.m[row][col] * v1.v[VEL].v[col]; 41 | } 42 | } 43 | 44 | return(v2); 45 | } 46 | -------------------------------------------------------------------------------- /src/tpm/m3fmt.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m3fmt.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m3fmt.c,v $ - format a 3-matrix 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include 22 | #include "vec.h" 23 | 24 | #define NM3BUF (5) 25 | static char m3buf[NM3BUF][BUFSIZ]; 26 | static int nxtm3buf = 0; 27 | 28 | char * 29 | m3fmt(M3 m) 30 | { 31 | char *p; 32 | 33 | /* get a buffer */ 34 | p = m3buf[nxtm3buf++]; 35 | nxtm3buf %= NM3BUF; 36 | 37 | (void)sprintf(p, "%22.15e %22.15e %22.15e", 38 | m3GetXX(m), m3GetXY(m), m3GetXZ(m)); 39 | (void)sprintf(p, "%s\n%22.15e %22.15e %22.15e", p, 40 | m3GetYX(m), m3GetYY(m), m3GetYZ(m)); 41 | (void)sprintf(p, "%s\n%22.15e %22.15e %22.15e", p, 42 | m3GetZX(m), m3GetZY(m), m3GetZZ(m)); 43 | 44 | return(p); 45 | } 46 | -------------------------------------------------------------------------------- /src/tpm/eccentricity.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: eccentricity.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: eccentricity.c,v $ 18 | ** return the eccentricity of the earth's orbit 19 | ** from Exp. Supp. 1992, p. 171 20 | ** ******************************************************************* 21 | */ 22 | 23 | #include "astro.h" 24 | 25 | double 26 | eccentricity(double tdt) 27 | { 28 | double T; /* elapsed julian centuries */ 29 | double e; 30 | 31 | T = (tdt - B1950) / CJ; 32 | 33 | e = 0.01673011 + T * (-0.00004193 + (T * (-0.000000126))); 34 | 35 | return(e); 36 | } 37 | 38 | double 39 | eccentricity_dot(double tdt) 40 | { 41 | double T; /* elapsed julian centuries */ 42 | double edot; 43 | 44 | T = (tdt - B1950) / CJ; 45 | 46 | edot = (-0.00004193 + 2 * (T * (-0.000000126))); 47 | 48 | return(edot); 49 | } 50 | -------------------------------------------------------------------------------- /src/tpm/utc_now.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: utc_now.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: utc_now.c,v $ - return the current UTC julian date, to the nearest second. 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include 22 | #include 23 | #include "times.h" 24 | 25 | double 26 | utc_now(void) 27 | { 28 | double utc; 29 | time_t t; 30 | struct tm *ptm; 31 | 32 | /* get the system time in seconds */ 33 | t = time(NULL); 34 | 35 | /* convert to UTC */ 36 | ptm = gmtime(&t); 37 | 38 | /* get the julian date of the start of the day */ 39 | utc = gcal2j(1900+ptm->tm_year, ptm->tm_mon+1, ptm->tm_mday) - 0.5; 40 | 41 | /* offset to now */ 42 | utc += (ptm->tm_hour + (ptm->tm_min + (ptm->tm_sec / 60.0)) / 60.0) / 24.0; 43 | 44 | return(utc); 45 | } 46 | -------------------------------------------------------------------------------- /src/tpm/proper_motion.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: proper_motion.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: proper_motion.c,v $ 18 | ** apply proper motion to a state vector 19 | ** ******************************************************************* 20 | */ 21 | 22 | #include "astro.h" 23 | 24 | V6 25 | proper_motion(V6 v6, double t, double t0) 26 | { 27 | double dt = (t - t0); 28 | /**********************************/ 29 | /* add in the position derivative */ 30 | /**********************************/ 31 | 32 | if (v6GetType(v6) == SPHERICAL) { 33 | v6IncR(v6, v6GetRDot(v6) * dt); 34 | v6IncAlpha(v6, v6GetAlphaDot(v6) * dt); 35 | v6IncDelta(v6, v6GetDeltaDot(v6) * dt); 36 | } else { 37 | v6IncX(v6, v6GetXDot(v6) * dt); 38 | v6IncY(v6, v6GetYDot(v6) * dt); 39 | v6IncZ(v6, v6GetZDot(v6) * dt); 40 | } 41 | 42 | return(v6); 43 | } 44 | -------------------------------------------------------------------------------- /src/tpm/ymd2jd.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: ymd2jd.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: ymd2jd.c,v $ - convert a ymd time into a jd time 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | JD 24 | ymd2jd(YMD ymd) 25 | { 26 | JD jd; 27 | int m, y; 28 | 29 | y = ymdGetYear(ymd); 30 | m = ymdGetMonth(ymd); 31 | 32 | /* normalize the month */ 33 | if (m < 1) { 34 | y -= (1 - m) / 12; 35 | m = (m % 12) + 12; 36 | } 37 | 38 | if (m > 12) { 39 | y += (m - 1) / 12; 40 | m = ((m - 1) % 12) + 1; 41 | } 42 | 43 | jdSetDay(jd, gcal2j(y, m, 0)); 44 | jdIncDay(jd, ymdGetDay(ymd)); 45 | 46 | /* now the fractional day... */ 47 | jd.hms = ymd.hms; 48 | 49 | /* julian days start 12 hours after civil days */ 50 | jdDecHours(jd, 12.0); 51 | 52 | return(jd); 53 | } 54 | -------------------------------------------------------------------------------- /src/tpm/v3delta.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v3delta.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v3delta.c,v $ - return the angle out of the x-y plane (declination) 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | double 24 | v3delta(V3 v) 25 | { 26 | double delta; 27 | 28 | if (v3GetType(v) == CARTESIAN) { 29 | v = v3c2s(v); 30 | } 31 | 32 | delta = v3GetDelta(v); 33 | if (v3GetR(v) < 0.0) { 34 | delta *= -1.0; 35 | } 36 | 37 | /* map onto -pi to pi */ 38 | if (delta <= -M_PI) { 39 | delta += ceil(delta / (-2 * M_PI)) * (2 * M_PI); 40 | } 41 | if (delta > M_PI) { 42 | delta -= floor(delta / (2 * M_PI)) * (2 * M_PI); 43 | } 44 | 45 | if (delta > M_PI/2) { 46 | delta = M_PI - delta; 47 | } 48 | 49 | if (delta < -M_PI/2) { 50 | delta = -M_PI - delta; 51 | } 52 | 53 | return(delta); 54 | } 55 | -------------------------------------------------------------------------------- /src/tpm/jd2ymd.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: jd2ymd.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: jd2ymd.c,v $ - convert a jd time into a ymd time 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | YMD 24 | jd2ymd(JD jd) 25 | { 26 | YMD ymd; 27 | double j; 28 | double x; 29 | int y, m, d; 30 | 31 | j = jdGetDay(jd); 32 | j2gcal(&y, &m, &d, j); 33 | ymdSetYear(ymd, y); 34 | ymdSetMonth(ymd, m); 35 | ymdSetDay(ymd, (double)d); 36 | 37 | x = (j - floor(j)); 38 | /* 39 | ** we do this next step because the rounding of j in j2gcal() 40 | ** either credits or debits us with 12 hours 41 | */ 42 | if (x < 0.5) { 43 | x += 0.5; 44 | } else { 45 | x -= 0.5; 46 | } 47 | ymdIncDay(ymd, x); 48 | 49 | /* pick up the hours, minutes, and seconds */ 50 | ymd.hms = jd.hms; 51 | 52 | return(ymd); 53 | } 54 | -------------------------------------------------------------------------------- /src/tpm/ut12gmst.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: ut12gmst.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: ut12gmst.c,v $ 18 | ** compute the greenwich mean sidereal time from UT1. 19 | ** return the gmst in radians (0 -> 2pi) 20 | ** ******************************************************************* 21 | */ 22 | 23 | #include "astro.h" 24 | 25 | double 26 | ut12gmst(double ut1) 27 | { 28 | double T; /* elapsed julian centuries */ 29 | double gmst; /* greenwich mean sidereal time */ 30 | 31 | T = (ut1 - J2000) / 36525; 32 | 33 | gmst = 67310.54841 + (T*(8640184.812866 + (T*(0.093104 + (T * -6.2e-6))))); 34 | 35 | /* convert this to hours */ 36 | gmst /= 3600.0; 37 | 38 | /* pick up the final term in the expansion */ 39 | gmst += 876600.0 * T; 40 | 41 | /* convert from hours to radians */ 42 | gmst = h2r(gmst); 43 | 44 | /* normalize it */ 45 | gmst = r2r(gmst); 46 | 47 | return(gmst); 48 | } 49 | -------------------------------------------------------------------------------- /src/tpm/tdt2tdb.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: tdt2tdb.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: tdt2tdb.c,v $ 18 | ** convert Terrestrial Dynamical Time (TDT) 19 | ** to Barycentric Dynamical Time (TDB) 20 | ** use formulation in Astronomical Almanac, 1984, p S15 21 | ** note that g is a function of TDB julian centuries, not TDT julian centuries, 22 | ** but the error in using TDT to compute g is negligible for computing 23 | ** apparent places of stars 24 | ** ******************************************************************* 25 | */ 26 | 27 | #include "astro.h" 28 | 29 | double 30 | tdt2tdb(double tdt) 31 | { 32 | double T; /* elapsed julian centuries */ 33 | double dt; /* (tdb - tdt) in seconds */ 34 | double g; 35 | double tdb; 36 | 37 | T = (tdt - J2000) / 36525; 38 | g = d2r(357.528 + (T * 35999.050)); 39 | dt = 0.001658 * sin(g + (0.01671 * sin(g))); 40 | tdb = tdt + (dt / 86400); 41 | 42 | return(tdb); 43 | } 44 | -------------------------------------------------------------------------------- /src/tpm/ellab.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: ellab.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: ellab.c,v $ 18 | ** add or remove elliptic aberration 19 | ** to adjust mean catalog place to catalog place. 20 | ** ******************************************************************* 21 | */ 22 | 23 | #include "astro.h" 24 | 25 | V6 26 | ellab(double tdt, V6 star, int flag) 27 | { 28 | double r; /* modulus of star vector */ 29 | V6 e; /* eterms */ 30 | 31 | /* cache the modulus of the star vector */ 32 | r = v6mod(star); 33 | 34 | /* make it a unit vector */ 35 | star = v6unit(star); 36 | 37 | /* get the e-terms */ 38 | e = eterms(tdt); 39 | 40 | if (flag > 0) { 41 | star = v6sum(star, e); 42 | } else if (flag < 0) { 43 | star = v6diff(star, e); 44 | } 45 | 46 | /* preserve the unit length */ 47 | star = v6unit(star); 48 | 49 | /* restore the true length */ 50 | star = v6scale(star, r); 51 | 52 | return(star); 53 | } 54 | -------------------------------------------------------------------------------- /src/tpm/rdb2ymd.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: rdb2ymd.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: rdb2ymd.c,v $ - convert a rdb time into a ymd time 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | YMD 24 | rdb2ymd(double rdb) 25 | { 26 | YMD ymd; 27 | 28 | ymdSetYear(ymd, (int)(rdb * 1e-4)); 29 | rdb -= (ymdGetYear(ymd) * 1e4); 30 | ymdSetMonth(ymd, (int)(rdb * 1e-2)); 31 | rdb -= (ymdGetMonth(ymd) * 1e2); 32 | ymdSetDay(ymd, (int)rdb); 33 | rdb -= (ymdGetDay(ymd)); 34 | 35 | /* shift the fraction by 6 digits */ 36 | rdb *= 1e6; 37 | rdb += 0.5; 38 | 39 | ymdSetHours(ymd, (int)(rdb * 1e-4)); 40 | rdb -= (ymdGetHours(ymd) * 1e4); 41 | ymdSetMinutes(ymd, (int)(rdb * 1e-2)); 42 | rdb -= (ymdGetMinutes(ymd) * 1e2); 43 | ymdSetSeconds(ymd, (int)rdb); 44 | rdb -= (ymdGetSeconds(ymd)); 45 | 46 | ymdIncYear(ymd, 1900); 47 | 48 | return(ymd); 49 | } 50 | -------------------------------------------------------------------------------- /src/tpm/TPM_LICENSE.txt: -------------------------------------------------------------------------------- 1 | The TPM library is copyright (C) 2006 Jeffrey W. Percival 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following 11 | disclaimer in the documentation and/or other materials provided 12 | with the distribution. 13 | 14 | 3. The name of Jeffrey W. Percival may not be used to 15 | endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY JEFFREY W. PERCIVAL ``AS IS'' AND ANY 19 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AURA BE LIABLE FOR ANY 22 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 24 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 26 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 2006 Association of Universities for Research in Astronomy (AURA) 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following 11 | disclaimer in the documentation and/or other materials provided 12 | with the distribution. 13 | 14 | 3. The name of AURA and its representatives may not be used to 15 | endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY AURA ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL AURA BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 23 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 24 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 26 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 27 | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 28 | DAMAGE. 29 | 30 | -------------------------------------------------------------------------------- /src/tpm/v6fmt.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v6fmt.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v6fmt.c,v $ - 6-vector formatting 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include 22 | #include "vec.h" 23 | 24 | #define NV6BUF (5) 25 | static char v6buf[NV6BUF][BUFSIZ]; 26 | static int nxtv6buf = 0; 27 | 28 | char * 29 | v6fmt(V6 v) 30 | { 31 | char *p; 32 | 33 | /* get a buffer */ 34 | p = v6buf[nxtv6buf++]; 35 | nxtv6buf %= NV6BUF; 36 | 37 | if (v6GetType(v) == CARTESIAN) { 38 | (void)sprintf(p, "%22.15e %22.15e %22.15e %22.15e %22.15e %22.15e", 39 | v6GetX(v), 40 | v6GetY(v), 41 | v6GetZ(v), 42 | v6GetXDot(v), 43 | v6GetYDot(v), 44 | v6GetZDot(v)); 45 | } else { 46 | (void)sprintf(p, "%22.15e %22.15e %22.15e %22.15e %22.15e %22.15e", 47 | v6GetR(v), 48 | v6GetAlpha(v), 49 | v6GetDelta(v), 50 | v6GetRDot(v), 51 | v6GetAlphaDot(v), 52 | v6GetDeltaDot(v)); 53 | } 54 | 55 | return(p); 56 | } 57 | -------------------------------------------------------------------------------- /src/tpm/solar_perigee.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: solar_perigee.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: solar_perigee.c,v $ 18 | ** compute the mean longitude of perigee of the solar orbit 19 | ** from Exp Supp AA 1992, p 171. 20 | ** 21 | ** return the longitude in radians 22 | ** ******************************************************************* 23 | */ 24 | 25 | #include "astro.h" 26 | 27 | double 28 | solar_perigee(double tdt) 29 | { 30 | double T; /* elapsed julian centuries */ 31 | double lon; /* longitude */ 32 | 33 | T = (tdt - B1950) / CJ; 34 | 35 | lon = 1015489.951 + T * (6190.67 + (T * (1.65 + (T * 0.012)))); 36 | 37 | lon = as2r(lon); 38 | 39 | return(lon); 40 | } 41 | 42 | double 43 | solar_perigee_dot(double tdt) 44 | { 45 | double T; /* elapsed julian centuries */ 46 | double ldot; 47 | 48 | T = (tdt - B1950) / CJ; 49 | 50 | ldot = 6190.67 + 2 * (T * (1.65 + 3 * (T * 0.012))); 51 | 52 | ldot = as2r(ldot); 53 | 54 | return(ldot); 55 | } 56 | -------------------------------------------------------------------------------- /src/tpm/fmt_h.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: fmt_h.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: fmt_h.c,v $ - format hours 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include 22 | #include "times.h" 23 | 24 | #define NBUF (5) 25 | static char buf[NBUF][32]; 26 | static int nxtbuf = 0; 27 | 28 | char * 29 | fmt_h(double h) 30 | { 31 | char *p; 32 | char sign = ' '; 33 | double sec; 34 | int fpart; 35 | int hrs; 36 | int ipart; 37 | int min; 38 | 39 | /* get a buffer */ 40 | p = buf[nxtbuf++]; 41 | nxtbuf %= NBUF; 42 | 43 | if (h < 0.0) { 44 | sign = '-'; 45 | h = fabs(h); 46 | } 47 | 48 | hrs = floor(h); 49 | h = 60 * (h - floor(h)); 50 | min = floor(h); 51 | h = 60 * (h - floor(h)); 52 | sec = h; 53 | 54 | ipart = (int)sec; 55 | fpart = 1e3 * (sec - ipart); 56 | 57 | (void)sprintf(p, "%c%02dH %02dM %02d.%03dS", 58 | sign, hrs, min, ipart, fpart); 59 | 60 | return(p); 61 | } 62 | -------------------------------------------------------------------------------- /src/tpm/fmt_d.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: fmt_d.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: fmt_d.c,v $ - format degrees 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include 22 | #include "times.h" 23 | 24 | #define NBUF (5) 25 | static char buf[NBUF][32]; 26 | static int nxtbuf = 0; 27 | 28 | char * 29 | fmt_d(double d) 30 | { 31 | char *p; 32 | char sign = '+'; 33 | double sec; 34 | int deg; 35 | int fpart; 36 | int ipart; 37 | int min; 38 | 39 | /* get a buffer */ 40 | p = buf[nxtbuf++]; 41 | nxtbuf %= NBUF; 42 | 43 | if (d < 0.0) { 44 | sign = '-'; 45 | d = fabs(d); 46 | } 47 | 48 | deg = floor(d); 49 | d = 60 * (d - floor(d)); 50 | min = floor(d); 51 | d = 60 * (d - floor(d)); 52 | sec = d; 53 | 54 | ipart = (int)sec; 55 | fpart = 1e3 * (sec - ipart); 56 | 57 | (void)sprintf(p, "%c%02dD %02d' %02d.%03d\"", 58 | sign, deg, min, ipart, fpart); 59 | 60 | return(p); 61 | } 62 | -------------------------------------------------------------------------------- /src/tpm/obliquity.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: obliquity.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: obliquity.c,v $ 18 | ** compute the mean obliquity of the ecliptic for the epoch J2000 19 | ** from Exp. Supp., 1992, p. 114 20 | ** 21 | ** return the obliquity in radians 22 | ** ******************************************************************* 23 | */ 24 | 25 | #include "astro.h" 26 | 27 | double 28 | obliquity(double tdt) 29 | { 30 | double T; /* elapsed julian centuries */ 31 | double obl; /* obliquity */ 32 | 33 | T = (tdt - J2000) / CJ; 34 | 35 | obl = 84381.448 + T * (-46.8150 + (T * (-0.00059 + (T * 0.001813)))); 36 | 37 | obl = as2r(obl); 38 | 39 | return(obl); 40 | } 41 | 42 | double 43 | obliquity_dot(double tdt) 44 | { 45 | double T; /* elapsed julian centuries */ 46 | double odot; /* obliquity */ 47 | 48 | T = (tdt - J2000) / CJ; 49 | 50 | odot = -46.8150 + 2 * (T * (-0.00059 + 3 * (T * 0.001813))); 51 | 52 | odot = as2r(odot); 53 | 54 | return(odot); 55 | } 56 | -------------------------------------------------------------------------------- /src/tpm/j2gcal.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: j2gcal.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: j2gcal.c,v $ - map a julian day number onto the gregorian proleptic calendar. 18 | ** the algorithm is from 19 | ** The Explanatory Supplement to the Astronomical Almanac (1992), 20 | ** section 12.92, equation 12.92-2, page 604. 21 | ** ******************************************************************* 22 | */ 23 | 24 | #include "times.h" 25 | 26 | void 27 | j2gcal(int *y, int *m, int *d, double j) 28 | { 29 | int i; 30 | int l; 31 | int n; 32 | int x; /* replaces 'j' in reference formula */ 33 | 34 | /* remember to round the JD to the next higher civil day */ 35 | l = (int)(j+0.5) + 68569; 36 | n = (4 * l) / 146097; 37 | l -= ((146097 * n) + 3) / 4; 38 | i = (4000 * (l + 1)) / 1461001; 39 | l -= (1461 * i) / 4 - 31; 40 | x = (80 * l) / 2447; 41 | *d = l - (2447 * x) / 80; 42 | l = x / 11; 43 | *m = x + 2 - (12 * l); 44 | *y = 100 * (n - 49) + i + l; 45 | 46 | return; 47 | } 48 | -------------------------------------------------------------------------------- /src/tpm/j2jcal.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: j2jcal.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: j2jcal.c,v $ - map a julian day number onto the julian proleptic calendar. 18 | ** the algorithm is from 19 | ** The Explanatory Supplement to the Astronomical Almanac (1992), 20 | ** section 12.95, equation 12.95-1, page 606. 21 | ** ******************************************************************* 22 | */ 23 | 24 | #include "times.h" 25 | 26 | void 27 | j2jcal(int *y, int *m, int *d, double j) 28 | { 29 | int i; 30 | int k; 31 | int l; 32 | int n; 33 | int x; /* replaces 'j' in reference formula */ 34 | 35 | /* remember to round the JD to the next higher civil day */ 36 | x = (int)(j+0.5) + 1402; 37 | k = (x - 1) / 1461; 38 | l = x - (1461 * k); 39 | n = (l - 1) / 365 - (l / 1461); 40 | i = l - (365 * n) + 30; 41 | x = (80 * i) / 2447; 42 | *d = i - (2447 * x) / 80; 43 | i = x / 11; 44 | *m = x + 2 - (12 * i); 45 | *y = (4 * k) + n + i - 4716; 46 | 47 | return; 48 | } 49 | -------------------------------------------------------------------------------- /src/tpm/v3c2s.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v3c2s.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v3c2s.c,v $ - 3-vector cartesian to spherical 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | /* some convenience macros */ 24 | #define R (v3GetR(vs)) 25 | #define A (v3GetAlpha(vs)) 26 | #define D (v3GetDelta(vs)) 27 | 28 | V3 29 | v3c2s(V3 vc) 30 | { 31 | V3 vs; 32 | double x = v3GetX(vc); 33 | double y = v3GetY(vc); 34 | double z = v3GetZ(vc); 35 | 36 | if (v3GetType(vc) == SPHERICAL) { 37 | return(vc); 38 | } 39 | 40 | vs = v3init(SPHERICAL); 41 | 42 | v3SetR(vs, v3mod(vc)); 43 | 44 | if (R == 0.0) { 45 | return(vs); 46 | } 47 | 48 | if (x == 0.0) { 49 | if (y < 0.0) { 50 | v3SetAlpha(vs, -M_PI/2); 51 | } else if (y > 0.0) { 52 | v3SetAlpha(vs, M_PI/2); 53 | } 54 | } else { 55 | v3SetAlpha(vs, atan2(y, x)); 56 | } 57 | 58 | v3SetDelta(vs, atan2(z, sqrt(x*x + y*y))); 59 | 60 | return(vs); 61 | } 62 | -------------------------------------------------------------------------------- /src/tpm/trapzd.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: trapzd.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: trapzd.c,v $ - trapezoidal quadrature 18 | ** from Numerical Recipes (1987), section 4.2, p. 111 19 | ** ******************************************************************* 20 | */ 21 | 22 | #include "misc.h" 23 | 24 | #undef DEBUG 25 | 26 | double 27 | trapzd(double (*func)(double), double a, double b, int n) 28 | { 29 | double del; 30 | double sum; 31 | double tnm; 32 | double x; 33 | int j; 34 | static double s; 35 | static int it; 36 | 37 | if (n <= 0) { 38 | s = 0.5 * (b-a) * ((*func)(a) + (*func)(b)); 39 | it = 1; 40 | } else { 41 | tnm = it; 42 | del = (b - a) / tnm; 43 | x = a + 0.5 * del; 44 | sum = 0; 45 | for (j = 0; j < it; j++) { 46 | sum += (*func)(x); 47 | x += del; 48 | } 49 | s = 0.5 * (s + (b-a)*sum/tnm); 50 | it *= 2; 51 | } 52 | #ifdef DEBUG 53 | (void)fprintf(stdout, "trapzd: a %f b %f n %d s %f it %d\n", 54 | a, b, n, s, it); 55 | #endif 56 | 57 | return(s); 58 | } 59 | -------------------------------------------------------------------------------- /src/tpm/fmt_delta.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: fmt_delta.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: fmt_delta.c,v $ - format a scalar angle as angle from -90 to 90 degrees 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | char * 24 | fmt_delta(double delta) 25 | { 26 | DMS dms; 27 | 28 | if (delta <= -M_PI) { 29 | delta += ceil(delta / (-2*M_PI)) * 2*M_PI; 30 | } 31 | 32 | if (delta > M_PI) { 33 | delta -= floor(delta / (2*M_PI)) * 2*M_PI; 34 | } 35 | 36 | if (delta > M_PI/2) { 37 | delta = M_PI - delta; 38 | } 39 | 40 | if (delta < -M_PI/2) { 41 | delta = -M_PI - delta; 42 | } 43 | 44 | #ifdef DEBUG 45 | (void)fprintf(stdout, "fmt_delta: delta = %g\n", delta); 46 | #endif 47 | 48 | dms = r2dms(delta); 49 | 50 | #ifdef DEBUG 51 | (void)fprintf(stdout, "fmt_delta: dms.dd = %g\n", dmsGetDegrees(dms)); 52 | (void)fprintf(stdout, "fmt_delta: dms.mm = %g\n", dmsGetMinutes(dms)); 53 | (void)fprintf(stdout, "fmt_delta: dms.ss = %g\n", dmsGetSeconds(dms)); 54 | #endif 55 | 56 | return(fmt_dms(dms)); 57 | } 58 | -------------------------------------------------------------------------------- /src/tpm/ymd2ymd.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: ymd2ymd.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: ymd2ymd.c,v $ - normalize a ymd time 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "times.h" 22 | 23 | YMD 24 | ymd2ymd(YMD ymd) 25 | { 26 | double j; /* julian day number */ 27 | double x; 28 | int y, m, d; 29 | 30 | j = ymd2j(ymd); 31 | 32 | j2gcal(&y, &m, &d, j); 33 | ymdSetYear(ymd, y); 34 | ymdSetMonth(ymd, m); 35 | ymdSetDay(ymd, d); 36 | 37 | x = j - floor(j); 38 | /* 39 | ** we do this next step because the rounding of j in j2gcal() 40 | ** either credits or debits us with 12 hours 41 | */ 42 | if (x < 0.5) { 43 | x += 0.5; 44 | } else { 45 | x -= 0.5; 46 | } 47 | 48 | /* promote the hours */ 49 | x = (x - floor(x)) * 24.0; 50 | ymdSetHours(ymd, floor(x)); 51 | 52 | /* promote the minutes */ 53 | x = (x - floor(x)) * 60.0; 54 | ymdSetMinutes(ymd, floor(x)); 55 | 56 | /* promote the seconds */ 57 | x = (x - floor(x)) * 60.0; 58 | ymdSetSeconds(ymd, x); 59 | 60 | return(ymd); 61 | } 62 | -------------------------------------------------------------------------------- /lib/astrolib/coords/pytpm_wrapper.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | 3 | """ 4 | This routine wraps the `pytpm.blackbox` routine in order to apply 5 | the longitude convention preferred in coords. All `astrolib.coords` 6 | routines should call `~astrolib.coords.pytpm_wrapper.blackbox` 7 | instead of `pytpm.blackbox`. 8 | 9 | Since pytpm is itself a wrapper for the TPM library, the change 10 | could have been made there; but the modulo operator in C only 11 | works on integers, so it was simpler to do it in python. Also, 12 | this leaves pytpm itself as a more transparent wrapper for TPM. 13 | 14 | """ 15 | from . import pytpm 16 | from . import astrodate 17 | import datetime 18 | 19 | def blackbox(x,y,instate,outstate,epoch,equinox,timetag=None): 20 | """ 21 | Parameters 22 | ---------- 23 | x, y : float 24 | Position in decimal degrees. 25 | 26 | instate, outstate : int 27 | The TPM states of the position. 28 | 29 | epoch : float 30 | Epoch of the position. 31 | 32 | equinox : float 33 | Equinox of the position. 34 | 35 | timetag : `~astrolib.coords.astrodate.AstroDate` 36 | Timetag of returned coordinate. 37 | 38 | Returns 39 | ------- 40 | r, d : float 41 | Converted coordinate. 42 | 43 | """ 44 | if timetag == None: 45 | timetag=astrodate.AstroDate() 46 | try: 47 | r,d=pytpm.blackbox(x,y,instate,outstate,epoch,equinox,timetag.jd) 48 | except AttributeError: #support forgetful users 49 | astrotag=astrodate.AstroDate(timetag) 50 | r,d=pytpm.blackbox(x,y,instate,outstate,epoch,equinox,astrotag.jd) 51 | 52 | #Convert longitude to astrolib/coords convention 53 | r=r%360.0 54 | return r,d 55 | -------------------------------------------------------------------------------- /src/tpm/geod2geoc.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: geod2geoc.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: geod2geoc.c,v $ 18 | ** geodetic to geocentric position 19 | ** see Exp. Supp. AA (1992), p 162. 20 | ** ******************************************************************* 21 | */ 22 | 23 | #include "astro.h" 24 | 25 | V6 26 | geod2geoc(double lon, double lat, double alt) 27 | { 28 | double C; 29 | double S; 30 | double x; 31 | double xdot; 32 | double y; 33 | double ydot; 34 | double z; 35 | double zdot; 36 | V6 g; /* the equatorial rectangular state vector */ 37 | 38 | C = 1 / sqrt(cos(lat)*cos(lat) + (1-IAU_F)*(1-IAU_F)*sin(lat)*sin(lat)); 39 | 40 | S = (1-IAU_F) * (1-IAU_F) * C; 41 | 42 | x = ((IAU_RE * C) + alt) * cos(lat) * cos(lon); 43 | y = ((IAU_RE * C) + alt) * cos(lat) * sin(lon); 44 | z = ((IAU_RE * S) + alt) * sin(lat); 45 | 46 | /* the velocity vector is the cross product wk^g */ 47 | xdot = -IAU_W * y; 48 | ydot = IAU_W * x; 49 | zdot = 0.0; 50 | 51 | g = v6init(CARTESIAN); 52 | v6SetX(g, x); 53 | v6SetY(g, y); 54 | v6SetZ(g, z); 55 | v6SetXDot(g, xdot); 56 | v6SetYDot(g, ydot); 57 | v6SetZDot(g, zdot); 58 | 59 | return(g); 60 | } 61 | -------------------------------------------------------------------------------- /src/tpm/precess_m.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: precess_m.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: precess_m.c,v $ 18 | ** compute the precession matrix for a given time span 19 | ** the pflag argument indicates which precession angles to use 20 | ** (see astro.h for definitions). 21 | ** the sflag argument indicates whether the precession is between 22 | ** inertial frames (e.g. FK5 -> FK5) or not 23 | ** (see astro.h for definitions). 24 | ** this routine returns the full 6x6 precession matrix appropriate 25 | ** for precessing proper motions along with positions. 26 | ** see yallop (AJ,97,274) for details. 27 | ** ******************************************************************* 28 | */ 29 | 30 | #include "astro.h" 31 | 32 | M6 33 | precess_m(double j1, double j2, int pflag, int sflag) 34 | { 35 | M6 m6; /* the precession matrix */ 36 | M6 qtheta; 37 | M6 qzee; 38 | M6 qzeta; 39 | 40 | qzeta = m6Qz(-zeta(j1, j2, pflag), -zetadot(j1, j2, pflag)); 41 | qtheta = m6Qy(theta(j1, j2, pflag), thetadot(j1, j2, pflag)); 42 | qzee = m6Qz(-zee(j1, j2, pflag), -zeedot(j1, j2, pflag)); 43 | 44 | m6 = m6m6(qzee, m6m6(qtheta, qzeta)); 45 | 46 | if (sflag != PRECESS_ROTATING) { 47 | /* zero out the non-inertial "P-dot" term */ 48 | m6GetVP(m6) = m3O(); 49 | } 50 | 51 | return(m6); 52 | } 53 | -------------------------------------------------------------------------------- /src/tpm/ldeflect.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: ldeflect.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: ldeflect.c,v $ 18 | ** apply GR deflection of light to a state vector. 19 | ** this is from Kaplan et al. AJ 97, 1197, eq. 14. 20 | ** ******************************************************************* 21 | */ 22 | 23 | #include "astro.h" 24 | 25 | V6 26 | ldeflect(V6 s, V6 e, int flag) 27 | { 28 | double cprime; 29 | double g1; 30 | double g2; 31 | V3 ehat; 32 | V3 p; 33 | V3 qhat; 34 | V3 x; /* the deflection vector */ 35 | V3 x1; /* scratch */ 36 | V3 x2; /* scratch */ 37 | 38 | p = v6GetPos(s); 39 | 40 | { 41 | V6 v6; 42 | v6 = v6sum(e, s); 43 | qhat = v3unit(v6GetPos(v6)); 44 | } 45 | ehat = v3unit(v6GetPos(e)); 46 | 47 | cprime = 86400.0 * (IAU_C / IAU_AU); 48 | g1 = (2.0 * IAU_K * IAU_K) / (cprime * cprime * v6mod(e)); 49 | g2 = 1 + v3dot(qhat, ehat); 50 | 51 | /* limit the value of g2 as Patrick Wallace does: 52 | ** clip it at 1.0e-5 radians (~922 arcseconds) 53 | */ 54 | if (g2 < 1.0e-5) { 55 | g2 = 1.0e-5; 56 | } 57 | 58 | x1 = v3scale(ehat, v3dot(p, qhat)); 59 | x2 = v3scale(qhat, v3dot(p, ehat)); 60 | x = v3scale(v3diff(x1, x2), g1/g2); 61 | 62 | if (flag > 0) { 63 | p = v3sum(p, x); 64 | } else if (flag < 0) { 65 | p = v3diff(p, x); 66 | } 67 | 68 | v6SetPos(s, p); 69 | 70 | return(s); 71 | } 72 | -------------------------------------------------------------------------------- /src/tpm/refco.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: refco.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: refco.c,v $ 18 | ** compute the refraction coefficients A and B. 19 | ** this is the same as Pat Wallace's slalib routine sla_refco(). 20 | ** 21 | ** lat: observer's astronomical latitude 22 | ** alt: observer's altitude above sea level in meters 23 | ** T: ambient temperature in Kelvins 24 | ** P: ambient pressure in millibars 25 | ** rh: relative humidity (fractional, 0-1) 26 | ** lambda: wavelength in micrometers 27 | ** eps: fractional accuracy 28 | ** ******************************************************************* 29 | */ 30 | 31 | #include "astro.h" 32 | 33 | #undef DEBUG 34 | 35 | void 36 | refco(double lat, double alt, double T, double P, double rh, double lambda, double eps, double *refa, double *refb) 37 | { 38 | double dz1; 39 | double dz2; 40 | double z1 = atan(1.0); 41 | double z2 = atan(4.0); 42 | 43 | dz1 = refraction(z1, lat, alt, T, P, rh, lambda, eps); 44 | dz2 = refraction(z2, lat, alt, T, P, rh, lambda, eps); 45 | 46 | #ifdef DEBUG 47 | (void)fprintf(stdout, "refco: dz1 %.15e\n", dz1); 48 | (void)fprintf(stdout, "refco: dz2 %.15e\n", dz2); 49 | #endif 50 | 51 | *refa = (64*dz1 - dz2)/60; 52 | *refb = (dz2 - 4*dz1)/60; 53 | 54 | #ifdef DEBUG 55 | (void)fprintf(stdout, "refco: refa %.15e\n", *refa); 56 | (void)fprintf(stdout, "refco: refb %.15e\n", *refb); 57 | #endif 58 | 59 | return; 60 | } 61 | -------------------------------------------------------------------------------- /src/tpm/eterms.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: eterms.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: eterms.c,v $ 18 | ** compute the e-terms of elliptic aberration. 19 | ** see yallop (AJ, 97, 274) and smith (AJ, 97, 265). 20 | ** ******************************************************************* 21 | */ 22 | 23 | #include "astro.h" 24 | 25 | V6 26 | eterms(double ep) 27 | { 28 | double dC; 29 | double dD; 30 | double ecc; /* eccentricity */ 31 | double lon; /* mean longitude of solar perigee */ 32 | double obl; /* obliquity */ 33 | V6 B; 34 | 35 | ecc = eccentricity(ep); 36 | obl = obliquity(ep); 37 | lon = solar_perigee(ep); 38 | 39 | dC = -as2r(IAU_KAPPA) * ecc * cos(lon) * cos(obl); 40 | dD = -as2r(IAU_KAPPA) * ecc * sin(lon); 41 | 42 | #ifdef DEBUG 43 | (void)fprintf(stdout, "dC %20.14f\n", r2as(dC)); 44 | (void)fprintf(stdout, "dD %20.14f\n", r2as(dD)); 45 | #endif 46 | 47 | B = v6init(CARTESIAN); 48 | v6SetX(B, -dD); 49 | v6SetY(B, dC); 50 | v6SetZ(B, dC * tan(obl)); 51 | 52 | #ifdef DEBUG 53 | (void)fprintf(stdout, "B %20.14f\n", r2as(v6GetX(B))); 54 | (void)fprintf(stdout, "B %20.14f\n", r2as(v6GetY(B))); 55 | (void)fprintf(stdout, "B %20.14f\n", r2as(v6GetZ(B))); 56 | (void)fprintf(stdout, "B %20.14f\n", r2as(v6GetXDot(B))); 57 | (void)fprintf(stdout, "B %20.14f\n", r2as(v6GetYDot(B))); 58 | (void)fprintf(stdout, "B %20.14f\n", r2as(v6GetZDot(B))); 59 | #endif 60 | 61 | return(B); 62 | } 63 | -------------------------------------------------------------------------------- /src/tpm/v6s2c.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v6s2c.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v6s2c.c,v $ - 6-vector spherical to cartesian 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | /* some convenience macros */ 24 | #define X (v6GetX(vc)) 25 | #define Y (v6GetY(vc)) 26 | #define Z (v6GetZ(vc)) 27 | #define XDOT (v6GetXDot(vc)) 28 | #define YDOT (v6GetYDot(vc)) 29 | #define ZDOT (v6GetZDot(vc)) 30 | #define R (v6GetR(vs)) 31 | #define A (v6GetAlpha(vs)) 32 | #define D (v6GetDelta(vs)) 33 | #define RDOT (v6GetRDot(vs)) 34 | #define ADOT (v6GetAlphaDot(vs)) 35 | #define DDOT (v6GetDeltaDot(vs)) 36 | 37 | V6 38 | v6s2c(V6 vs) 39 | { 40 | double cos_a; 41 | double cos_d; 42 | double sin_a; 43 | double sin_d; 44 | V6 vc; 45 | 46 | if (v6GetType(vs) == CARTESIAN) { 47 | return(vs); 48 | } 49 | 50 | vc = v6init(CARTESIAN); 51 | 52 | cos_a = cos(A); 53 | cos_d = cos(D); 54 | sin_a = sin(A); 55 | sin_d = sin(D); 56 | 57 | /* the standard transformation */ 58 | v6SetX(vc, R*cos_d*cos_a); 59 | v6SetY(vc, R*cos_d*sin_a); 60 | v6SetZ(vc, R*sin_d); 61 | 62 | /* the first derivative of the standard transformation */ 63 | v6SetXDot(vc, -R*(cos_d*sin_a*ADOT + sin_d*cos_a*DDOT) + RDOT*cos_d*cos_a); 64 | v6SetYDot(vc, R*(cos_d*cos_a*ADOT - sin_d*sin_a*DDOT) + RDOT*cos_d*sin_a); 65 | v6SetZDot(vc, R*cos_d*DDOT + RDOT*sin_d); 66 | 67 | return(vc); 68 | } 69 | -------------------------------------------------------------------------------- /src/tpm/tpm_state.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: tpm_state.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: tpm_state.c,v $ 18 | ** map telescope pointing machine states onto state names 19 | ** ******************************************************************* 20 | */ 21 | 22 | #include "astro.h" 23 | 24 | static char *statenames[N_TPM_STATES] = { 25 | "null", /* TPM_S00 */ 26 | "Helio. mean FK4", /* TPM_S01 */ 27 | "Helio. mean FK5", /* TPM_S02 */ 28 | "IAU 1980 Ecliptic", /* TPM_S03 */ 29 | "IAU 1958 Galactic", /* TPM_S04 */ 30 | "Helio. mean FK4", /* TPM_S05 */ 31 | "Helio. mean FK5", /* TPM_S06 */ 32 | "Geoc. mean FK5", /* TPM_S07 */ 33 | "S07 + Light Defl.", /* TPM_S08 */ 34 | "S08 + Aberration", /* TPM_S09 */ 35 | "S09 + Precession", /* TPM_S10 */ 36 | "Geoc. app. FK5", /* TPM_S11 */ 37 | "Topo. mean FK5", /* TPM_S12 */ 38 | "S12 + Light Defl.", /* TPM_S13 */ 39 | "S13 + Aberration", /* TPM_S14 */ 40 | "S14 + Precession", /* TPM_S15 */ 41 | "Topo. app. FK5", /* TPM_S16 */ 42 | "Topo. app. HA/Dec", /* TPM_S17 */ 43 | "Topo. app. Az/El", /* TPM_S18 */ 44 | "Topo. obs. Az/El", /* TPM_S19 */ 45 | "Topo. obs. HA/Dec", /* TPM_S20 */ 46 | "Topo. obs. WHAM" /* TPM_S21 */ 47 | }; 48 | 49 | char * 50 | tpm_state(int state) 51 | { 52 | char *name; 53 | static char buf[BUFSIZ]; 54 | 55 | if ((state < 0) || (state >= N_TPM_STATES)) { 56 | (void)sprintf(buf, "%s (S%02d)", "unknown", state); 57 | name = &buf[0]; 58 | } else { 59 | name = statenames[state]; 60 | } 61 | 62 | return(name); 63 | } 64 | -------------------------------------------------------------------------------- /src/tpm/qromb.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: qromb.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: qromb.c,v $ - romberg rule integration 18 | ** from Numerical Recipes (1987), section 4.3, p. 114 19 | ** ******************************************************************* 20 | */ 21 | 22 | #include 23 | #include 24 | #include "misc.h" 25 | 26 | #undef DEBUG 27 | 28 | #define K (5) 29 | 30 | static double *h = NULL; 31 | static double *s = NULL; 32 | static int nmax = 0; 33 | 34 | double 35 | qromb(double (*func)(double), double a, double b, double eps, int imax) 36 | { 37 | double ss = 0; 38 | double dss; 39 | int i; 40 | 41 | /* allocate enough storage */ 42 | if (imax+1 > nmax) { 43 | #ifdef DEBUG 44 | (void)fprintf(stdout, "qromb: malloc %d cells %d bytes\n", 45 | imax+1, (imax+1) * sizeof(double)); 46 | #endif 47 | if (h != NULL) { 48 | free(h); 49 | } 50 | h = (double *)malloc((imax+1) * sizeof(double)); 51 | if (s != NULL) { 52 | free(s); 53 | } 54 | s = (double *)malloc((imax+1) * sizeof(double)); 55 | 56 | nmax = imax+1; 57 | } 58 | 59 | h[0] = 1; 60 | 61 | for (i = 0; i < imax; i++) { 62 | s[i] = trapzd(func, a, b, i); 63 | if (i >= K-1) { 64 | ss = polint(&h[i-(K-1)], &s[i-(K-1)], K, 0.0, &dss); 65 | #ifdef DEBUG 66 | (void)fprintf(stdout, "qromb: a %.15e b %.15e i %d ss %.15e dss %.15e eps %.15e\n", 67 | a, b, i, ss, dss, eps); 68 | #endif 69 | if (fabs(dss) < eps * fabs(ss)) { 70 | return(ss); 71 | } 72 | } 73 | h[i+1] = 0.25 * h[i]; 74 | s[i+1] = s[i]; 75 | } 76 | 77 | #ifdef DEBUG 78 | (void)fprintf(stdout, "qromb: a %.15e b %.15e i %d ss %.15e\n", a, b, i, ss); 79 | #endif 80 | 81 | return(ss); 82 | } 83 | -------------------------------------------------------------------------------- /src/tpm/fmt_ymd.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: fmt_ymd.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: fmt_ymd.c,v $ - format a ymd time 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include 22 | #include 23 | #include "times.h" 24 | 25 | static char *dow[] = { 26 | "Sun", 27 | "Mon", 28 | "Tue", 29 | "Wed", 30 | "Thu", 31 | "Fri", 32 | "Sat", 33 | }; 34 | 35 | static char *moy[] = { 36 | "Jan", 37 | "Feb", 38 | "Mar", 39 | "Apr", 40 | "May", 41 | "Jun", 42 | "Jul", 43 | "Aug", 44 | "Sep", 45 | "Oct", 46 | "Nov", 47 | "Dec", 48 | }; 49 | 50 | #define NYMDBUF 5 51 | static char ymdbuf[NYMDBUF][32]; 52 | static int nxtymdbuf = 0; 53 | 54 | char * 55 | fmt_ymd(YMD ymd) 56 | { 57 | char *p; 58 | double j; /* julian day number of target time */ 59 | int fpart; 60 | int ipart; 61 | int today; 62 | 63 | /* get a buffer */ 64 | p = ymdbuf[nxtymdbuf++]; 65 | nxtymdbuf %= NYMDBUF; 66 | 67 | /* normalize the time */ 68 | ymd = ymd2ymd(ymd); 69 | 70 | /* get the julian day number */ 71 | j = ymd2j(ymd); 72 | 73 | /* get the day of the week */ 74 | today = j2dow(j); 75 | 76 | ipart = (int)ymdGetSeconds(ymd); 77 | fpart = 1e3 * (ymdGetSeconds(ymd) - ipart); 78 | 79 | (void)sprintf(p, "%3.3s %3.3s %2d %02d:%02d:%02d.%03d %4d", 80 | dow[today], 81 | moy[ymdGetMonth(ymd)-1], 82 | (int)ymdGetDay(ymd), 83 | (int)ymdGetHours(ymd), 84 | (int)ymdGetMinutes(ymd), 85 | ipart, fpart, 86 | ((ymdGetYear(ymd) > 0) ? ymdGetYear(ymd) : (1-ymdGetYear(ymd)))); 87 | 88 | if (ymdGetYear(ymd) <= 0) { 89 | (void)strcat(p, " BC"); 90 | } 91 | 92 | return(p); 93 | } 94 | -------------------------------------------------------------------------------- /src/tpm/v6c2s.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v6c2s.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: v6c2s.c,v $ - 6-vector cartesian to spherical 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include "vec.h" 22 | 23 | /* some convenience macros */ 24 | #define XDOT (v6GetXDot(vc)) 25 | #define YDOT (v6GetYDot(vc)) 26 | #define ZDOT (v6GetZDot(vc)) 27 | #define R (v6GetR(vs)) 28 | #define A (v6GetAlpha(vs)) 29 | #define D (v6GetDelta(vs)) 30 | #define RDOT (v6GetRDot(vs)) 31 | #define ADOT (v6GetAlphaDot(vs)) 32 | #define DDOT (v6GetDeltaDot(vs)) 33 | 34 | V6 35 | v6c2s(V6 vc) 36 | { 37 | V6 vs; 38 | double r_cos_d; 39 | double sin_d; 40 | double x = v6GetX(vc); 41 | double y = v6GetY(vc); 42 | double z = v6GetZ(vc); 43 | 44 | if (v6GetType(vc) == SPHERICAL) { 45 | return(vc); 46 | } 47 | 48 | vs = v6init(SPHERICAL); 49 | 50 | v6SetR(vs, v6mod(vc)); 51 | 52 | if (R == 0.0) { 53 | v6SetRDot(vs, XDOT); 54 | return(vs); 55 | } 56 | 57 | if (x == 0.0) { 58 | if (y < 0.0) { 59 | v6SetAlpha(vs, -M_PI/2); 60 | } else if (y > 0.0) { 61 | v6SetAlpha(vs, M_PI/2); 62 | } 63 | } else { 64 | v6SetAlpha(vs, atan2(y, x)); 65 | } 66 | 67 | v6SetDelta(vs, atan2(z, sqrt(x*x + y*y))); 68 | 69 | sin_d = sin(D); 70 | 71 | if (cos(D) == 0.0) { 72 | v6SetRDot(vs, ZDOT / sin_d); 73 | if (cos(A) == 0.0) { 74 | v6SetDeltaDot(vs, -YDOT/(R*sin_d*sin(A))); 75 | } else { 76 | v6SetDeltaDot(vs, -XDOT/(R*sin_d*cos(A))); 77 | } 78 | return(vs); 79 | } 80 | 81 | r_cos_d = R*cos(D); 82 | 83 | v6SetRDot(vs, (x*XDOT + y*YDOT + z*ZDOT) / R); 84 | 85 | v6SetAlphaDot(vs, (x*YDOT - y*XDOT) / (r_cos_d*r_cos_d)); 86 | 87 | v6SetDeltaDot(vs, ((ZDOT - RDOT*sin_d) / r_cos_d)); 88 | 89 | return(vs); 90 | } 91 | -------------------------------------------------------------------------------- /src/tpm/m6fmt.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m6fmt.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: m6fmt.c,v $ - format a 6-matrix 18 | ** ******************************************************************* 19 | */ 20 | 21 | #include 22 | #include "vec.h" 23 | 24 | #define NM6BUF (5) 25 | static char m6buf[NM6BUF][BUFSIZ]; 26 | static int nxtm6buf = 0; 27 | 28 | char * 29 | m6fmt(M6 m) 30 | { 31 | char *p; 32 | 33 | /* get a buffer */ 34 | p = m6buf[nxtm6buf++]; 35 | nxtm6buf %= NM6BUF; 36 | 37 | (void)sprintf(p, "%22.15e %22.15e %22.15e %22.15e %22.15e %22.15e", 38 | m3GetXX(m6GetPP(m)), m3GetXY(m6GetPP(m)), m3GetXZ(m6GetPP(m)), 39 | m3GetXX(m6GetPV(m)), m3GetXY(m6GetPV(m)), m3GetXZ(m6GetPV(m))); 40 | (void)sprintf(p, "%s\n%22.15e %22.15e %22.15e %22.15e %22.15e %22.15e", p, 41 | m3GetYX(m6GetPP(m)), m3GetYY(m6GetPP(m)), m3GetYZ(m6GetPP(m)), 42 | m3GetYX(m6GetPV(m)), m3GetYY(m6GetPV(m)), m3GetYZ(m6GetPV(m))); 43 | (void)sprintf(p, "%s\n%22.15e %22.15e %22.15e %22.15e %22.15e %22.15e", p, 44 | m3GetZX(m6GetPP(m)), m3GetZY(m6GetPP(m)), m3GetZZ(m6GetPP(m)), 45 | m3GetZX(m6GetPV(m)), m3GetZY(m6GetPV(m)), m3GetZZ(m6GetPV(m))); 46 | (void)sprintf(p, "%s\n%22.15e %22.15e %22.15e %22.15e %22.15e %22.15e", p, 47 | m3GetXX(m6GetVP(m)), m3GetXY(m6GetVP(m)), m3GetXZ(m6GetVP(m)), 48 | m3GetXX(m6GetVV(m)), m3GetXY(m6GetVV(m)), m3GetXZ(m6GetVV(m))); 49 | (void)sprintf(p, "%s\n%22.15e %22.15e %22.15e %22.15e %22.15e %22.15e", p, 50 | m3GetYX(m6GetVP(m)), m3GetYY(m6GetVP(m)), m3GetYZ(m6GetVP(m)), 51 | m3GetYX(m6GetVV(m)), m3GetYY(m6GetVV(m)), m3GetYZ(m6GetVV(m))); 52 | (void)sprintf(p, "%s\n%22.15e %22.15e %22.15e %22.15e %22.15e %22.15e", p, 53 | m3GetZX(m6GetVP(m)), m3GetZY(m6GetVP(m)), m3GetZZ(m6GetVP(m)), 54 | m3GetZX(m6GetVV(m)), m3GetZY(m6GetVV(m)), m3GetZZ(m6GetVV(m))); 55 | 56 | return(p); 57 | } 58 | -------------------------------------------------------------------------------- /src/tpm/refract.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: refract.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: refract.c,v $ 18 | ** compute refraction using refraction coefficients 19 | ** for zenith distances greater than 87 degrees, 20 | ** the refraction for 87 degrees is applied. 21 | ** ******************************************************************* 22 | */ 23 | 24 | #include "astro.h" 25 | 26 | #undef DEBUG 27 | 28 | #define Z_LIMIT (87) 29 | 30 | #define ITERATIONS (2) 31 | 32 | double 33 | refract(double z, double refa, double refb, int flag) 34 | { 35 | double dz; /* refraction */ 36 | double err; /* iteration error */ 37 | double tz0; /* tangent value */ 38 | double z0; /* refracted (observed) zenith distance */ 39 | double z0_last; /* previous value */ 40 | int i; 41 | 42 | /* limit the given zenith angle */ 43 | if (z < 0) { 44 | z = 0; 45 | } else if (z > d2r(Z_LIMIT)) { 46 | z = d2r(Z_LIMIT); 47 | } 48 | 49 | if (flag > 0) { 50 | /* apply refraction */ 51 | 52 | /* we have to iterate the refraction equation to get z0 */ 53 | 54 | /* first guess */ 55 | z0 = z; 56 | 57 | /* use newton's method to find z0 */ 58 | for (i = 0; i < ITERATIONS; i++) { 59 | z0_last = z0; 60 | tz0 = tan(z0); 61 | dz = tz0 * (refa + tz0 * (tz0 * refb)); 62 | z0 -= ((z0-z) + dz) / (1 + (refa+3*refb*tz0*tz0)/(cos(z0)*cos(z0))); 63 | err = fabs(z0-z0_last); 64 | 65 | #ifdef DEBUG 66 | (void)fprintf(stdout, "refract: z0 %.15g dz %.15g z %.15g err %.15g\n", 67 | z0, dz, z, err); 68 | #endif 69 | } 70 | dz *= -1.0; 71 | 72 | } else { 73 | /* remove refraction */ 74 | z0 = z; 75 | tz0 = tan(z0); 76 | dz = tz0 * (refa + tz0 * (tz0 * refb)); 77 | z = z0 + dz; 78 | 79 | #ifdef DEBUG 80 | (void)fprintf(stdout, "refract: z0 %.15g tz0 %.15g dz %.15g z %.15g\n", 81 | z0, tz0, dz, z); 82 | #endif 83 | 84 | } 85 | return(dz); 86 | } 87 | -------------------------------------------------------------------------------- /src/tpm/argvParse.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: argvParse.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: argvParse.c,v $ - parse time structures out of argv lists 18 | 19 | the "cooked" argument determines how negative signs are handled for inputs 20 | like "-45 30 30". in raw mode, each field keeps its own sign. in 21 | cooked mode, the sign of the 1st item is applied to the 2nd and 3rd as 22 | is expected with traditional usage. So in cooked mode, the example 23 | above would be -45 -30 -30, while in raw mode it would be -45 30 30. 24 | 25 | Note that in cooked mode, -45 -30 -30 will be returned as -45 30 30. 26 | 27 | ** ******************************************************************* 28 | */ 29 | 30 | #include 31 | #include "times.h" 32 | 33 | int 34 | argv2dms(DMS *dms, char *argv[], int argnum, int cooked) 35 | { 36 | DMS x; 37 | int sign = 1; 38 | 39 | if (*argv[argnum+1] == '-') { 40 | sign = -1; 41 | } 42 | x.dd = atof(argv[++argnum]); 43 | x.mm = atof(argv[++argnum]); 44 | x.ss = atof(argv[++argnum]); 45 | 46 | if (cooked) { 47 | x.mm *= sign; 48 | x.ss *= sign; 49 | } 50 | 51 | *dms = x; 52 | 53 | return(argnum); 54 | } 55 | 56 | int 57 | argv2hms(HMS *hms, char *argv[], int argnum, int cooked) 58 | { 59 | int sign = 1; 60 | HMS x; 61 | 62 | if (*argv[argnum+1] == '-') { 63 | sign = -1; 64 | } 65 | x.hh = atof(argv[++argnum]); 66 | x.mm = atof(argv[++argnum]); 67 | x.ss = atof(argv[++argnum]); 68 | 69 | if (cooked) { 70 | x.mm *= sign; 71 | x.ss *= sign; 72 | } 73 | 74 | *hms = x; 75 | 76 | return(argnum); 77 | } 78 | 79 | int 80 | argv2ymd(YMD *ymd, char *argv[], int argnum, int cooked) 81 | { 82 | YMD x; 83 | 84 | x.y = atoi(argv[++argnum]); 85 | x.m = atoi(argv[++argnum]); 86 | x.dd = atof(argv[++argnum]); 87 | argnum = argv2hms(&x.hms, argv, argnum, cooked); 88 | 89 | *ymd = x; 90 | 91 | return(argnum); 92 | } 93 | -------------------------------------------------------------------------------- /src/blackbox.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "tpm/astro.h" 4 | 5 | void blackbox(double x1, double y1, int s1, int s2, 6 | double epoch, double equinox, double timetag, 7 | double *x2, double *y2) 8 | 9 | { 10 | struct s_tstate tstate; 11 | struct s_v6 pvec[N_TPM_STATES]; 12 | struct s_v6 v6; 13 | 14 | // double epoch = J2000; 15 | // double equinox = J2000; 16 | 17 | // Input params are in degrees. Convert them to radians & set things up. 18 | // **NB: Always call d2r(x1),d2r(y1) before using them. 19 | 20 | v6=v6init(SPHERICAL); // v6=Spherical(lon,lat) #r=FarAway 21 | v6SetAlpha(v6,d2r(x1)); 22 | v6SetDelta(v6,d2r(y1)); 23 | v6SetR(v6,1e9); 24 | 25 | tpm_data(&tstate, TPM_INIT); 26 | tstate.utc = timetag; 27 | tpm_data(&tstate, TPM_ALL); 28 | 29 | pvec[s1]=v6; 30 | 31 | (void)tpm(pvec,s1,s2,epoch,equinox,&tstate); 32 | 33 | v6=pvec[s2]; 34 | v6 = v6c2s(v6); 35 | *x2 = r2d(v6GetAlpha(v6)); 36 | *y2 = r2d(v6GetDelta(v6)); 37 | 38 | return; 39 | } 40 | 41 | 42 | /* 43 | * here begins the python interface 44 | */ 45 | 46 | static PyObject * 47 | blackbox_shim(PyObject *self, PyObject *args) 48 | { 49 | double x1; 50 | double y1; 51 | int s1; 52 | int s2; 53 | double epoch; 54 | double equinox; 55 | double timetag; 56 | double x2; 57 | double y2; 58 | 59 | PyObject *rval; 60 | 61 | if (! PyArg_ParseTuple(args, "ddiiddd", 62 | &x1,&y1,&s1,&s2,&epoch,&equinox,&timetag) ) 63 | return NULL; 64 | 65 | blackbox(x1, y1, s1, s2, epoch, equinox, timetag, &x2, &y2); 66 | rval = Py_BuildValue("dd",x2,y2); 67 | return rval; 68 | } 69 | 70 | 71 | static char *module_documentation = ""; 72 | 73 | static struct PyMethodDef methods[] = { 74 | {"blackbox", blackbox_shim, 1, "" }, 75 | {NULL, NULL} /* sentinel */ 76 | }; 77 | 78 | #if PY_MAJOR_VERSION >= 3 79 | static struct PyModuleDef moduledef = { 80 | PyModuleDef_HEAD_INIT, 81 | "_pytpm", 82 | NULL, 83 | -1, 84 | methods, 85 | NULL, 86 | NULL, 87 | NULL, 88 | NULL 89 | }; 90 | 91 | PyObject *PyInit__pytpm(void) 92 | { 93 | PyObject *m; 94 | m = PyModule_Create(&moduledef); 95 | 96 | /* Check for errors */ 97 | if (PyErr_Occurred()) 98 | Py_FatalError("can't initialize module _pytpm"); 99 | 100 | return m; 101 | } 102 | 103 | #else 104 | PyMODINIT_FUNC 105 | init_pytpm(void) 106 | { 107 | /* Create the module and add the functions */ 108 | (void) Py_InitModule("_pytpm", methods); 109 | 110 | /* Check for errors */ 111 | if (PyErr_Occurred()) 112 | Py_FatalError("can't initialize module _pytpm"); 113 | } 114 | #endif 115 | -------------------------------------------------------------------------------- /src/tpm/delta_AT.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: delta_AT.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: delta_AT.c,v $ 18 | ** return the difference (TAI - UTC) in seconds. 19 | ** before 1972 Jan 1, a fixed value of 10 seconds is returned. 20 | ** THIS FILE MUST BE UPDATED WHENEVER A LEAP SECOND IS ADDED. 21 | ** Compute the MJD of the first date to which the leap second applies 22 | ** and use that as the comparison in the code below. 23 | ** 24 | ** this is modelled after sla_DAT by P. T. Wallace 25 | ** ******************************************************************* 26 | */ 27 | 28 | #include "astro.h" 29 | 30 | double 31 | delta_AT(double utc) 32 | { 33 | double dt = 10.0; 34 | 35 | /* make it an MJD */ 36 | utc -= MJD_0; 37 | 38 | if (utc >= 41499.0) dt = 11.0; /* 1972 Jul 1 */ 39 | 40 | if (utc >= 41683.0) dt = 12.0; /* 1973 Jan 1 */ 41 | 42 | if (utc >= 42048.0) dt = 13.0; /* 1974 Jan 1 */ 43 | 44 | if (utc >= 42413.0) dt = 14.0; /* 1975 Jan 1 */ 45 | 46 | if (utc >= 42778.0) dt = 15.0; /* 1976 Jan 1 */ 47 | 48 | if (utc >= 43144.0) dt = 16.0; /* 1977 Jan 1 */ 49 | 50 | if (utc >= 43509.0) dt = 17.0; /* 1978 Jan 1 */ 51 | 52 | if (utc >= 43874.0) dt = 18.0; /* 1979 Jan 1 */ 53 | 54 | if (utc >= 44239.0) dt = 19.0; /* 1980 Jan 1 */ 55 | 56 | if (utc >= 44786.0) dt = 20.0; /* 1981 Jul 1 */ 57 | 58 | if (utc >= 45151.0) dt = 21.0; /* 1982 Jul 1 */ 59 | 60 | if (utc >= 45516.0) dt = 22.0; /* 1983 Jul 1 */ 61 | 62 | if (utc >= 46247.0) dt = 23.0; /* 1985 Jul 1 */ 63 | 64 | if (utc >= 47161.0) dt = 24.0; /* 1988 Jan 1 */ 65 | 66 | if (utc >= 47892.0) dt = 25.0; /* 1990 Jan 1 */ 67 | 68 | if (utc >= 48257.0) dt = 26.0; /* 1991 Jan 1 */ 69 | 70 | if (utc >= 48804.0) dt = 27.0; /* 1992 July 1 */ 71 | 72 | if (utc >= 49169.0) dt = 28.0; /* 1993 July 1 */ 73 | 74 | if (utc >= 49534.0) dt = 29.0; /* 1994 July 1 */ 75 | 76 | if (utc >= 50083.0) dt = 30.0; /* 1996 Jan 1 */ 77 | 78 | if (utc >= 50630.0) dt = 31.0; /* 1997 Jul 1 */ 79 | 80 | if (utc >= 51179.0) dt = 32.0; /* 1999 Jan 1 */ 81 | 82 | if (utc >= 53736.0) dt = 33.0; /* 2006 Jan 1 */ 83 | 84 | if (utc >= 54832.0) dt = 33.0; /* 2009 Jan 1 */ 85 | 86 | return(dt); 87 | } 88 | -------------------------------------------------------------------------------- /src/tpm/polint.c: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: polint.c,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ** ******************************************************************* 17 | ** $RCSfile: polint.c,v $ - polynomial interpolation 18 | ** from Numerical Recipes (1987), section 3.1, p. 82 19 | ** ******************************************************************* 20 | */ 21 | 22 | #include 23 | #include 24 | #include "misc.h" 25 | 26 | static double *c = NULL; 27 | static double *d = NULL; 28 | static int nmax = 0; 29 | 30 | double 31 | polint(double *xa, double *ya, int n, double x, double *dy) 32 | { 33 | double den; 34 | double dif; 35 | double dift; 36 | double ho; 37 | double hp; 38 | double w; 39 | double y; 40 | int i; 41 | int m; 42 | int ns; 43 | 44 | /* allocate enough storage */ 45 | if (n > nmax) { 46 | #ifdef DEBUG 47 | (void)fprintf(stdout, "polint: malloc %d cells\n", n); 48 | #endif 49 | if (c != NULL) { 50 | free(c); 51 | } 52 | c = (double *)malloc(n * sizeof(double)); 53 | if (d != NULL) { 54 | free(d); 55 | } 56 | d = (double *)malloc(n * sizeof(double)); 57 | nmax = n; 58 | } 59 | 60 | #ifdef DEBUG 61 | (void)fprintf(stdout, "polint: n %d x %.15e\n", n, x); 62 | #endif 63 | 64 | /* find the index of the closest table entry */ 65 | ns = 0; 66 | dif = fabs(x - xa[ns]); 67 | for (i = 0; i < n; i++) { 68 | dift = fabs(x - xa[i]); 69 | if (dift < dif) { 70 | ns = i; 71 | dif = dift; 72 | } 73 | c[i] = ya[i]; 74 | d[i] = ya[i]; 75 | } 76 | 77 | /* first guess */ 78 | y = ya[ns--]; 79 | #ifdef DEBUG 80 | (void)fprintf(stdout, "polint: y %.15e ns %d\n", y, ns); 81 | #endif 82 | 83 | for (m = 0; m < n-1; m++) { 84 | #ifdef DEBUG 85 | (void)fprintf(stdout, "polint: m %d\n", m); 86 | #endif 87 | for (i = 0; i < n-m-1; i++) { 88 | #ifdef DEBUG 89 | (void)fprintf(stdout, "polint: i %d\n", i); 90 | #endif 91 | ho = xa[i] - x; 92 | hp = xa[i+m+1] - x; 93 | w = c[i+1] - d[i]; 94 | den = ho - hp; 95 | den = w / den; 96 | c[i] = ho * den; 97 | d[i] = hp * den; 98 | } 99 | if (2*ns + 1 < n-m-2) { 100 | *dy = c[ns+1]; 101 | #ifdef DEBUG 102 | (void)fprintf(stdout, "polint: c ns %d dy %.15e\n", ns, *dy); 103 | #endif 104 | } else { 105 | *dy = d[ns--]; 106 | #ifdef DEBUG 107 | (void)fprintf(stdout, "polint: d ns %d dy %.15e\n", ns, *dy); 108 | #endif 109 | } 110 | y += *dy; 111 | } 112 | 113 | #ifdef DEBUG 114 | (void)fprintf(stdout, "polint: n %d x %.15e y %.15e dy %.15e\n", n, x, y, *dy); 115 | #endif 116 | 117 | return(y); 118 | } 119 | -------------------------------------------------------------------------------- /src/tpm/v3.h: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: v3.h,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ********************************************************************** 17 | ** $RCSfile: v3.h,v $ - 18 | ********************************************************************** 19 | */ 20 | 21 | #ifndef V3_INCLUDE 22 | #define V3_INCLUDE 23 | 24 | typedef struct s_v3 { 25 | int type; /* vector type, cartesian or spherical */ 26 | double v[3]; 27 | } V3; 28 | 29 | #define v3DecX(v3,x) (v3.v[0] -= (x)) 30 | #define v3DecY(v3,x) (v3.v[1] -= (x)) 31 | #define v3DecZ(v3,x) (v3.v[2] -= (x)) 32 | #define v3DecR(v3,x) (v3.v[0] -= (x)) 33 | #define v3DecAlpha(v3,x) (v3.v[1] -= (x)) 34 | #define v3DecDelta(v3,x) (v3.v[2] -= (x)) 35 | 36 | #define v3DivX(v3,x) (v3.v[0] /= (x)) 37 | #define v3DivY(v3,x) (v3.v[1] /= (x)) 38 | #define v3DivZ(v3,x) (v3.v[2] /= (x)) 39 | #define v3DivR(v3,x) (v3.v[0] /= (x)) 40 | #define v3DivAlpha(v3,x) (v3.v[1] /= (x)) 41 | #define v3DivDelta(v3,x) (v3.v[2] /= (x)) 42 | 43 | #define v3GetType(v3) (v3.type) 44 | #define v3GetX(v3) (v3.v[0]) 45 | #define v3GetY(v3) (v3.v[1]) 46 | #define v3GetZ(v3) (v3.v[2]) 47 | #define v3GetR(v3) (v3.v[0]) 48 | #define v3GetAlpha(v3) (v3.v[1]) 49 | #define v3GetDelta(v3) (v3.v[2]) 50 | 51 | #define v3IncX(v3,x) (v3.v[0] += (x)) 52 | #define v3IncY(v3,x) (v3.v[1] += (x)) 53 | #define v3IncZ(v3,x) (v3.v[2] += (x)) 54 | #define v3IncR(v3,x) (v3.v[0] += (x)) 55 | #define v3IncAlpha(v3,x) (v3.v[1] += (x)) 56 | #define v3IncDelta(v3,x) (v3.v[2] += (x)) 57 | 58 | #define v3MulX(v3,x) (v3.v[0] *= (x)) 59 | #define v3MulY(v3,x) (v3.v[1] *= (x)) 60 | #define v3MulZ(v3,x) (v3.v[2] *= (x)) 61 | #define v3MulR(v3,x) (v3.v[0] *= (x)) 62 | #define v3MulAlpha(v3,x) (v3.v[1] *= (x)) 63 | #define v3MulDelta(v3,x) (v3.v[2] *= (x)) 64 | 65 | #define v3SetType(v3,x) (v3.type = (x)) 66 | #define v3SetX(v3,x) (v3.v[0] = (x)) 67 | #define v3SetY(v3,x) (v3.v[1] = (x)) 68 | #define v3SetZ(v3,x) (v3.v[2] = (x)) 69 | #define v3SetR(v3,x) (v3.v[0] = (x)) 70 | #define v3SetAlpha(v3,x) (v3.v[1] = (x)) 71 | #define v3SetDelta(v3,x) (v3.v[2] = (x)) 72 | 73 | /* some astro convenience macros */ 74 | 75 | #define v3DecRA(f,x) (v3DecAlpha(f,x)) 76 | #define v3DecDec(f,x) (v3DecDelta(f,x)) 77 | 78 | #define v3DivRA(f,x) (v3DivAlpha(f,x)) 79 | #define v3DivDec(f,x) (v3DivDelta(f,x)) 80 | 81 | #define v3GetRA(f) (v3GetAlpha(f)) 82 | #define v3GetDec(f) (v3GetDelta(f)) 83 | 84 | #define v3IncRA(f,x) (v3IncAlpha(f,x)) 85 | #define v3IncDec(f,x) (v3IncDelta(f,x)) 86 | 87 | #define v3MulRA(f,x) (v3MulAlpha(f,x)) 88 | #define v3MulDec(f,x) (v3MulDelta(f,x)) 89 | 90 | #define v3SetRA(f,x) (v3SetAlpha(f,x)) 91 | #define v3SetDec(f,x) (v3SetDelta(f,x)) 92 | 93 | /* EXTERN_START */ 94 | /* EXTERN_STOP */ 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /src/tpm/m3.h: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: m3.h,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ********************************************************************** 17 | ** $RCSfile: m3.h,v $ - 18 | ********************************************************************** 19 | */ 20 | 21 | #ifndef M3_INCLUDE 22 | #define M3_INCLUDE 23 | 24 | typedef struct s_m3 { 25 | double m[3][3]; 26 | } M3; 27 | 28 | #define m3DecXX(m3,x) (m3.m[0][0] -= (x)) 29 | #define m3DecXY(m3,x) (m3.m[0][1] -= (x)) 30 | #define m3DecXZ(m3,x) (m3.m[0][2] -= (x)) 31 | #define m3DecYX(m3,x) (m3.m[1][0] -= (x)) 32 | #define m3DecYY(m3,x) (m3.m[1][1] -= (x)) 33 | #define m3DecYZ(m3,x) (m3.m[1][2] -= (x)) 34 | #define m3DecZX(m3,x) (m3.m[2][0] -= (x)) 35 | #define m3DecZY(m3,x) (m3.m[2][1] -= (x)) 36 | #define m3DecZZ(m3,x) (m3.m[2][2] -= (x)) 37 | 38 | #define m3DivXX(m3,x) (m3.m[0][0] /= (x)) 39 | #define m3DivXY(m3,x) (m3.m[0][1] /= (x)) 40 | #define m3DivXZ(m3,x) (m3.m[0][2] /= (x)) 41 | #define m3DivYX(m3,x) (m3.m[1][0] /= (x)) 42 | #define m3DivYY(m3,x) (m3.m[1][1] /= (x)) 43 | #define m3DivYZ(m3,x) (m3.m[1][2] /= (x)) 44 | #define m3DivZX(m3,x) (m3.m[2][0] /= (x)) 45 | #define m3DivZY(m3,x) (m3.m[2][1] /= (x)) 46 | #define m3DivZZ(m3,x) (m3.m[2][2] /= (x)) 47 | 48 | #define m3GetXX(m3) (m3.m[0][0]) 49 | #define m3GetXY(m3) (m3.m[0][1]) 50 | #define m3GetXZ(m3) (m3.m[0][2]) 51 | #define m3GetYX(m3) (m3.m[1][0]) 52 | #define m3GetYY(m3) (m3.m[1][1]) 53 | #define m3GetYZ(m3) (m3.m[1][2]) 54 | #define m3GetZX(m3) (m3.m[2][0]) 55 | #define m3GetZY(m3) (m3.m[2][1]) 56 | #define m3GetZZ(m3) (m3.m[2][2]) 57 | 58 | #define m3IncXX(m3,x) (m3.m[0][0] += (x)) 59 | #define m3IncXY(m3,x) (m3.m[0][1] += (x)) 60 | #define m3IncXZ(m3,x) (m3.m[0][2] += (x)) 61 | #define m3IncYX(m3,x) (m3.m[1][0] += (x)) 62 | #define m3IncYY(m3,x) (m3.m[1][1] += (x)) 63 | #define m3IncYZ(m3,x) (m3.m[1][2] += (x)) 64 | #define m3IncZX(m3,x) (m3.m[2][0] += (x)) 65 | #define m3IncZY(m3,x) (m3.m[2][1] += (x)) 66 | #define m3IncZZ(m3,x) (m3.m[2][2] += (x)) 67 | 68 | #define m3MulXX(m3,x) (m3.m[0][0] *= (x)) 69 | #define m3MulXY(m3,x) (m3.m[0][1] *= (x)) 70 | #define m3MulXZ(m3,x) (m3.m[0][2] *= (x)) 71 | #define m3MulYX(m3,x) (m3.m[1][0] *= (x)) 72 | #define m3MulYY(m3,x) (m3.m[1][1] *= (x)) 73 | #define m3MulYZ(m3,x) (m3.m[1][2] *= (x)) 74 | #define m3MulZX(m3,x) (m3.m[2][0] *= (x)) 75 | #define m3MulZY(m3,x) (m3.m[2][1] *= (x)) 76 | #define m3MulZZ(m3,x) (m3.m[2][2] *= (x)) 77 | 78 | #define m3SetXX(m3,x) (m3.m[0][0] = (x)) 79 | #define m3SetXY(m3,x) (m3.m[0][1] = (x)) 80 | #define m3SetXZ(m3,x) (m3.m[0][2] = (x)) 81 | #define m3SetYX(m3,x) (m3.m[1][0] = (x)) 82 | #define m3SetYY(m3,x) (m3.m[1][1] = (x)) 83 | #define m3SetYZ(m3,x) (m3.m[1][2] = (x)) 84 | #define m3SetZX(m3,x) (m3.m[2][0] = (x)) 85 | #define m3SetZY(m3,x) (m3.m[2][1] = (x)) 86 | #define m3SetZZ(m3,x) (m3.m[2][2] = (x)) 87 | 88 | /* EXTERN_START */ 89 | /* EXTERN_STOP */ 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /ReleaseNotes.txt: -------------------------------------------------------------------------------- 1 | Version 0.37 adds the leap second for dates after 1 Jan 2009. 2 | 3 | ------------------------------------------------------------ 4 | Prior release notes are included below 5 | ------------------------------------------------------------ 6 | 7 | Version 0.36 is a bugfix build: 8 | 9 | - Some not-really-extraneous declarations were restored to 10 | misc.h. Thanks to Dr. Jae-Joon Lee for submitting the patch. 11 | 12 | 13 | Version 0.35 converts to numpy and cleans up some build issues. 14 | 15 | The following changes have been made: 16 | - Coords now uses numpy instead of numarray. Associated 17 | documentation has been changed. 18 | - Extraneous declarations were stripped from the misc.h file, which 19 | were causing build problems on Fedora 7. 20 | - Unused variables were stripped from src/blackbox.c and most files 21 | in src/tpm. 22 | - Files in src/tpm now include. the Subversion $Id$ keyword expansion. 23 | 24 | 25 | Version 0.3 expands support for time specification in AstroDate and Position. 26 | 27 | The following changes have been made: 28 | - timetag specification is now supported for TPM-related methods of 29 | Position objects. (See "An explanatory note about time", in the 30 | v0.25 release notes below, for more discussion.) 31 | 32 | - the AstroDate factory function was enhanced to accept a 33 | datetime.datetime object (assumed to be in UTC) as a time 34 | specification, and to produce a JulianDate of "utc now" when no 35 | argument is supplied. 36 | 37 | - tests were refactored; coords._test() now runs a doctest that 38 | matches the set of (now expanded) examples given to demonstrate 39 | package functionality. Unit tests were removed from the 40 | distribution and documentation. The package import statements were 41 | also trimmed down to avoid unnecessarily cluttering the namespace. 42 | 43 | ------------------------------------------------------------ 44 | 45 | Version 0.25 is a bugfix release of the coords package. 46 | 47 | The following issues have been addressed: 48 | - Negative degrees in sexagesimal specification is now handled 49 | - Longitude/RA convention for TPM-based method calls is now 50 | consistent with the rest of the package 51 | - Example text has been updated 52 | 53 | 54 | 55 | An explanatory note about time: 56 | 57 | There are three times of interest associated with a celestial 58 | coordinate. TPM calls these 59 | - the equinox == time at which precession is zero 60 | - the epoch == time at which proper motion is zero 61 | - the timetag of the coordinate 62 | 63 | At present (v0.25), the Coords package enforces equinox=B1950 for 64 | galactic coordinates and J1984 for ecliptic coordinates; celestial 65 | coordinates may be specified at J2000 or B1950, or at an arbitary 66 | Julian (decimal) year. For all coordinate systems, it enforces 67 | epoch=J2000 and timetag="time now" -- that is, it uses the current 68 | system time. 69 | 70 | Galactic and celestial coordinate systems are very insensitive to 71 | changes in "time now", but due to the nature of the ecliptic reference 72 | frame, ecliptic coordinates are quite sensitive. 73 | 74 | The v0.3 release of the Coords package is planned to include the 75 | ability to specify the timetag of the coordinate. 76 | 77 | 78 | Release history: 79 | - v0.2: included TPM capability to handle precession 80 | - v0.1: initial release 81 | -------------------------------------------------------------------------------- /doc/source/intro.rst: -------------------------------------------------------------------------------- 1 | ****** 2 | README 3 | ****** 4 | 5 | Purpose 6 | ======= 7 | 8 | This package aims to provide much of the IDL "astron" functionality that 9 | pertains to coordinate manipulations in an OO framework. Our target user is 10 | a typical astronomer who needs to analyze data, work with catalogs, prepare 11 | observing proposals, and prepare for observing runs. 12 | 13 | The initial version will provide simple functionality for working with 14 | positions in the same reference frame, without having to worry about units. 15 | 16 | 17 | Dependencies 18 | ============ 19 | numpy 20 | 21 | pytpm -- a Python wrapper for the TPM library graciously contributed 22 | by Jeff Percival 23 | 24 | 25 | Examples 26 | ======== 27 | >>> import astrolib.coords as C 28 | >>> print C.__version__ 29 | 0.39 30 | 31 | Unit conversions 32 | 33 | >>> ob = C.Position('12:34:45.34 -23:42:32.6') 34 | >>> ob.hmsdms() 35 | '12:34:45.340 -23:42:32.600' 36 | >>> ob.dd() 37 | (188.68891666666667, -23.709055555555555) 38 | >>> ob.rad() 39 | (3.2932428578545374, -0.41380108198269777) 40 | 41 | Angular separations 42 | 43 | >>> p1 = C.Position("01:23:45.300 +65:43:31.240") 44 | >>> p2 = C.Position("01:23:45.62 +65:43:31.20") 45 | >>> p1.angsep(p2) 46 | 0.000548 degrees 47 | >>> delta = p1.angsep(p2) 48 | >>> delta.arcsec() 49 | 1.973739377865491 50 | >>> p1.within(p2, 3.0, units='arcsec') 51 | True 52 | >>> epsilon = C.AngSep(5.0) 53 | >>> epsilon 54 | 5.000000 arcsec 55 | >>> delta > epsilon 56 | False 57 | 58 | Astronomical Date specifications 59 | 60 | >>> d = C.AstroDate('1997.3') # Defaults to Julian year; J or B prefix also ok 61 | >>> d.year 62 | 1997.3 63 | >>> d.jd 64 | 2450558.8250000002 65 | >>> d.mjd 66 | 50558.325000000186 67 | >>> d2 = C.AstroDate('MJD50658.25') # JD also ok for plain Julian Date 68 | >>> d2.year 69 | 1997.5735797399041 70 | >>> d2 < d 71 | False 72 | 73 | Coordinate conversions 74 | 75 | >>> ob.j2000() 76 | (188.68891666666667, -23.709055555555555) 77 | >>> ob.b1950() 78 | (188.03056480942405, -23.433637283819877) 79 | >>> ob.galactic() 80 | (298.01638938748795, 39.003358150874568) 81 | >>> ob.ecliptic(timetag=C.AstroDate('J2000')) 82 | (197.5848634558852, -18.293964120804738) 83 | >>> p3 = C.Position("01:23:45 -65:43:21.4",equinox='J2000') 84 | >>> p4 = C.Position("01:23:45 -65:43:21.4",equinox='B1950') 85 | >>> p3.j2000() 86 | (20.9375, -65.722611111111107) 87 | >>> p4.j2000() 88 | (21.356870704681981, -65.462921080444147) 89 | >>> p3.angsep(p4) 90 | 0.312199 degrees 91 | >>> p5 = C.Position((0.0,0.0),system='galactic') 92 | >>> p5.j2000() 93 | (266.40499571858879, -28.936169261309555) 94 | 95 | Specify position in hmsdms 96 | 97 | >>> polaris = C.Position("02:31:49.08 +89:15:50.8") 98 | >>> polaris.dd() 99 | (37.954500000000003, 89.264111111111106) 100 | >>> polaris.hmsdms() 101 | '02:31:49.080 +89:15:50.800' 102 | >>> print polaris.details() 103 | System: celestial 104 | Equinox: j2000 105 | 106 | Specify position in decimal degrees 107 | 108 | >>> ob = C.Position((52.9860209, -27.7510006)) 109 | >>> ob.hmsdms() 110 | '03:31:56.645 -27:45:03.602' 111 | >>> ob.dd() 112 | (52.9860209, -27.751000600000001) 113 | 114 | Use as calculator without saving the intermediate object 115 | 116 | >>> C.Position("12:34:45.4 -22:21:45.4").dd() 117 | (188.68916666666667, -22.362611111111111) 118 | 119 | 120 | TPM Citation 121 | ============ 122 | Investigators using this software for their research are requested to 123 | explicitly acknowledge "use of the TPM software library, by Jeffrey W. 124 | Percival" in any appropriate publications. 125 | 126 | 127 | See Also 128 | ======== 129 | http://www.scipy.org/AstroLibCoordsHome 130 | -------------------------------------------------------------------------------- /src/tpm/vec.h: -------------------------------------------------------------------------------- 1 | /* file: $RCSfile: vec.h,v $ 2 | ** rcsid: $Id$ 3 | ** Copyright Jeffrey W Percival 4 | ** ******************************************************************* 5 | ** Space Astronomy Laboratory 6 | ** University of Wisconsin 7 | ** 1150 University Avenue 8 | ** Madison, WI 53706 USA 9 | ** ******************************************************************* 10 | ** Do not use this software without attribution. 11 | ** Do not remove or alter any of the lines above. 12 | ** ******************************************************************* 13 | */ 14 | 15 | /* 16 | ********************************************************************** 17 | ** $RCSfile: vec.h,v $ - 18 | ********************************************************************** 19 | */ 20 | 21 | #ifndef VEC_H 22 | #define VEC_H 23 | 24 | #include 25 | #ifndef M_PI 26 | #define M_PI (3.14159265358979323846) 27 | #endif 28 | 29 | #define CARTESIAN (0) 30 | #define SPHERICAL (1) 31 | #define POLAR (SPHERICAL) 32 | 33 | /* define some short-cut macros */ 34 | 35 | /* these are repeated in times.h */ 36 | #ifndef TIMES_H 37 | #define d2h(d) ((d)/15.0) 38 | #define h2d(h) ((h)*15.0) 39 | #define d2r(d) ((d)*(M_PI/180.0)) 40 | #define r2d(r) ((r)*(180.0/M_PI)) 41 | #define h2r(h) ((h)*(M_PI/12.0)) 42 | #define r2h(r) ((r)*(12.0/M_PI)) 43 | #define d2as(d) ((d)*3600.0) 44 | #define as2d(x) ((x)/3600.0) 45 | #define as2h(x) (d2h(as2d(x))) 46 | #define h2as(h) (d2as(h2d(h))) 47 | #define r2as(r) (d2as(r2d(r))) 48 | #define as2r(x) (d2r(as2d(x))) 49 | #endif 50 | 51 | /* define 3-vectors */ 52 | #include "v3.h" 53 | 54 | /* define 6-vectors */ 55 | #include "v6.h" 56 | 57 | /* define 3-matrices */ 58 | #include "m3.h" 59 | 60 | /* define 6-matrices */ 61 | #include "m6.h" 62 | 63 | /* EXTERN_START */ 64 | extern M3 m3I(double x); 65 | extern M3 m3O(void); 66 | extern M3 m3Rx(double x); 67 | extern M3 m3RxDot(double x, double xdot); 68 | extern M3 m3Ry(double y); 69 | extern M3 m3RyDot(double y, double ydot); 70 | extern M3 m3Rz(double z); 71 | extern M3 m3RzDot(double z, double zdot); 72 | extern M3 m3diff(M3 m1, M3 m2); 73 | extern M3 m3inv(M3 m); 74 | extern M3 m3m3(M3 m1, M3 m2); 75 | extern M3 m3scale(M3 m, double s); 76 | extern M3 m3sum(M3 m1, M3 m2); 77 | extern M6 m6I(double x); 78 | extern M6 m6O(void); 79 | extern M6 m6Qx(double x, double xdot); 80 | extern M6 m6Qy(double y, double ydot); 81 | extern M6 m6Qz(double z, double zdot); 82 | extern M6 m6diff(M6 m1, M6 m2); 83 | extern M6 m6inv(M6 m); 84 | extern M6 m6m6(M6 m1, M6 m2); 85 | extern M6 m6scale(M6 m, double s); 86 | extern M6 m6sum(M6 m1, M6 m2); 87 | extern V3 m3v3(M3 m, V3 v1); 88 | extern V3 m6v3(M6 m, V3 v); 89 | extern V3 v3c2s(V3 vc); 90 | extern V3 v3cross(V3 v1, V3 v2); 91 | extern V3 v3diff(V3 v1, V3 v2); 92 | extern V3 v3init(int type); 93 | extern V3 v3s2c(V3 vs); 94 | extern V3 v3scale(V3 v, double s); 95 | extern V3 v3sum(V3 v1, V3 v2); 96 | extern V3 v3unit(V3 v); 97 | extern V3 v62v3(V6 v6, double dt); 98 | extern V6 m3v6(M3 m, V6 v1); 99 | extern V6 m6v6(M6 m, V6 v1); 100 | extern V6 v32v6(V3 v3); 101 | extern V6 v6c2s(V6 vc); 102 | extern V6 v6cross(V6 v1, V6 v2); 103 | extern V6 v6diff(V6 v1, V6 v2); 104 | extern V6 v6init(int type); 105 | extern V6 v6s2c(V6 vs); 106 | extern V6 v6scale(V6 v, double s); 107 | extern V6 v6sum(V6 v1, V6 v2); 108 | extern V6 v6unit(V6 v); 109 | extern char *m3fmt(M3 m); 110 | extern char *m6fmt(M6 m); 111 | extern char *v3fmt(V3 v); 112 | extern char *v6fmt(V6 v); 113 | extern double v3alpha(V3 v); 114 | extern double v3delta(V3 v); 115 | extern double v3dot(V3 v1, V3 v2); 116 | extern double v3mod(V3 v); 117 | extern double v6alpha(V6 v); 118 | extern double v6delta(V6 v); 119 | extern double v6dot(V6 v1, V6 v2); 120 | extern double v6mod(V6 v); 121 | /* EXTERN_STOP */ 122 | 123 | #endif 124 | --------------------------------------------------------------------------------