Skip to content

Commit

Permalink
Fail gracefully if file NP.xy is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano committed May 19, 2016
1 parent 2ea5070 commit 692255a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ julia> Pkg.add("AstroLib")
You may need to update your package list with `Pkg.update()` in order to get the
latest version of `AstroLib.jl`.

Note that, in order to work, a few functions require external files, which are
automatically downloaded when building the package. Should these files be
missing for some reason, you will be able to load the package but some functions
may not work properly. You can manually build the package with

```julia
julia> Pkg.build("AstroLib")
```

Usage
-----

Expand Down
27 changes: 18 additions & 9 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,28 @@ be installed with `Julia built-in package
manager <http://docs.julialang.org/en/stable/manual/packages/>`__. In a
Julia session run the command

.. code:: julia
.. code-block:: julia
julia> Pkg.add("AstroLib")
You may need to update your package list with ``Pkg.update()`` in order
to get the latest version of ``AstroLib.jl``.

Note that, in order to work, a few functions require external files, which are
automatically downloaded when building the package. Should these files be
missing for some reason, you will be able to load the package but some functions
may not work properly. You can manually build the package with

.. code-block:: julia
julia> Pkg.build("AstroLib")
Usage
-----

After installing the package, you can start using ``AstroLib.jl`` with

.. code:: julia
.. code-block:: julia
using AstroLib
Expand All @@ -66,7 +75,7 @@ fields are
The type constructor ``Observatory`` can be used to create a new
``Observatory`` object. Its syntax is

.. code:: julia
.. code-block:: julia
Observatory(name, lat, long, alt, tz)
Expand All @@ -79,7 +88,7 @@ A predefined list of some observing sites is provided with
abbreviated names of the observatories. For example, you can access information
of the European Southern Observatory with

.. code:: julia
.. code-block:: julia
julia> obs = AstroLib.observatories["eso"]
Observatory: European Southern Observatory
Expand All @@ -93,7 +102,7 @@ of the European Southern Observatory with
You can list all keys of the dictionary with

.. code:: julia
.. code-block:: julia
keys(AstroLib.observatories)
Expand Down Expand Up @@ -125,15 +134,15 @@ System planets. Its fields are

The constructor has this syntax:

.. code:: julia
.. code-block:: julia
Planet(name, radius, eqradius, polradius, mass, ecc, axis, period)
The list of Solar System planets, from Mercury to Pluto, is available
with ``AstroLib.planets`` dictionary. The keys of this dictionary are the
lowercase names of the planets. For example:

.. code:: julia
.. code-block:: julia
julia> AstroLib.planets["mercury"]
Planet: Mercury
Expand Down Expand Up @@ -182,13 +191,13 @@ Every function provided has detailed documentation that can be
`accessed <http://docs.julialang.org/en/stable/manual/documentation/#accessing-documentation>`__
at Julia REPL with

.. code:: julia
.. code-block:: julia
julia> ?FunctionName
or with

.. code:: julia
.. code-block:: julia
julia> @doc FunctionName
Expand Down
30 changes: 21 additions & 9 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,28 @@ List of locations of North Magnetic Pole since 1590.
This is provided by World Magnetic Model
(https://www.ngdc.noaa.gov/geomag/data/poles/NP.xy).
"""
POLELATLONG = Dict{AbstractFloat,Tuple{AbstractFloat,AbstractFloat}}()
let
local polelatlong, rows
polelatlong = readdlm(joinpath(dirname(@__FILE__), "..", "deps", "NP.xy"))
rows = size(polelatlong, 1)
for i = 1:rows
merge!(POLELATLONG, Dict(polelatlong[2rows + i]=>
(polelatlong[rows + i], polelatlong[i])))
const POLELATLONG =
try
let
local polelatlong, rows, floattype, temp
polelatlong = readdlm(joinpath(dirname(@__FILE__),
"..", "deps", "NP.xy"))
rows = size(polelatlong, 1)
floattype = typeof(polelatlong[1])
temp = Dict{floattype, Tuple{floattype, floattype}}()
for i = 1:rows
merge!(temp, Dict(polelatlong[2rows + i]=>
(polelatlong[rows + i],
polelatlong[i])))
end
temp
end
catch
warn("""Could not find file NP.xy, you will not be able to use
"geo2mag" and "mag2geo" functions. Build again the package with
Pkg.build("AstroLib")
then restart Julia session in order to fix this problem.""")
end
end

const AU = 1.495978707e11 # Astronomical unit in meters
const J2000 = jdcnv(2000, 01, 01, 12) # 2451545
Expand Down

0 comments on commit 692255a

Please sign in to comment.