Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JuliaAstro / FITSIO.jl / 166

26 Jul 2017 - 19:32 coverage: 72.418%. Remained the same
166

Pull #77

travis-ci

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
Minor change
Pull Request #77: [WIP] Add Documenter to build documentation

83 of 102 new or added lines in 5 files covered. (81.37%)

68 existing lines in 5 files now uncovered.

554 of 765 relevant lines covered (72.42%)

149.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.65
/src/FITSIO.jl
1
isdefined(Base, :__precompile__) && __precompile__()
2

3
module FITSIO
4

5
using Compat
6

7
export FITS,
8
       HDU,
9
       ImageHDU,
10
       TableHDU,
11
       ASCIITableHDU,
12
       FITSHeader,
13
       read_key,
14
       read_header,
15
       get_comment,
16
       set_comment!,
17
       copy_section
18

19
import Base: getindex,
20
             setindex!,
21
             length,
22
             show,
23
             read,
24
             write,
25
             close,
26
             ndims,
27
             size,
28
             endof,
29
             haskey,
30
             keys,
31
             values,
32
             start,
33
             next,
34
             done
35

36
# Libcfitsio submodule
37
include("libcfitsio.jl")
38

39
using .Libcfitsio
40

41
# There are a few direct `ccall`s to libcfitsio in this module. For this, we
42
# need a few non-exported things from Libcfitsio: the shared library handle,
43
# and a helper function for raising errors. TYPE_FROM_BITPIX is awkwardly
44
# defined in Libcfitsio, even though it is not used there.
45
import .Libcfitsio: libcfitsio,
46
                    fits_assert_ok,
47
                    TYPE_FROM_BITPIX
48

49
# HDU Types
50
@compat abstract type HDU end
51

52
type ImageHDU <: HDU
53
    fitsfile::FITSFile
80×
54
    ext::Int
55
end
56

57
type TableHDU <: HDU
58
    fitsfile::FITSFile
5×
59
    ext::Int
60
end
61

62
type ASCIITableHDU <: HDU
63
    fitsfile::FITSFile
5×
64
    ext::Int
65
end
66

67
# FITS
68
#
69
# The FITS type represents a FITS file. It holds a reference to a
70
# FITSFile object (basically the low-level CFITSIO pointer). It also
71
# holds a reference to all of the previously accessed HDU
72
# objects. This is so that only a single HDU object is created for
73
# each extension in the file. It also allows a FITS object to tell
74
# previously created HDUs about events that happen to the file, such
75
# as deleting extensions. This could be done by, e.g., setting ext=-1
76
# in the HDU object.
77
type FITS
78
    fitsfile::FITSFile
79
    filename::AbstractString
80
    mode::AbstractString
81
    hdus::Dict{Int, HDU}
82

83
    # Hold on to memory if backed by a julia buffer
84
    memhandle::FITSMemoryHandle
85
    hidden::Any
86

87
    function FITS(filename::AbstractString, mode::AbstractString="r")
88
        f = (mode == "r"                      ? fits_open_file(filename, 0)    :
40×
89
             mode == "r+" && isfile(filename) ? fits_open_file(filename, 1)    :
90
             mode == "r+"                     ? fits_create_file(filename)     :
91
             mode == "w"                      ? fits_create_file("!"*filename) :
92
             error("invalid open mode: $mode"))
93

94
        new(f, filename, mode, Dict{Int, HDU}(), FITSMemoryHandle(), nothing)
49×
95
    end
96

97
    function FITS(data::Vector{UInt8}, mode::AbstractString="r", filename = "")
98
        @assert mode == "r"
10×
99
        f, handle = fits_open_memfile(data, 0)
21×
100
        new(f, filename, mode, Dict{Int, HDU}(), handle, data)
7×
101
    end
102
end
103

104
"""
105
    FITS(f::Function, args...)
106

107
Apply the function `f` to the result of `FITS(args...)` and close the resulting file
108
descriptor upon completion.
109
"""
110
function FITS(f::Function, args...)
111
    io = FITS(args...)
5×
112
    try
11×
113
        f(io)
13×
114
    finally
115
        close(io)
11×
116
    end
117
end
118

119
# FITSHeader
120
#
121
# An in-memory representation of the header of an HDU. It stores the
122
# (key, value, comment) information for each card in a header. We
123
# could almost just use an OrderedDict for this, but we need to store
124
# comments.
125
type FITSHeader
126
    keys::Vector{String}
127
    values::Vector{Any}
128
    comments::Vector{String}
129
    map::Dict{String, Int}
130

131
    function FITSHeader(keys::Vector{String}, values::Vector,
132
                        comments::Vector{String})
133
        if ((length(keys) != length(values)) ||
30×
134
            (length(keys) != length(comments)))
UNCOV
135
            error("keys, values, comments must be same length")
!
136
        end
137
        map = Dict{String, Int64}()
42×
138
        for i in 1:length(keys)
582×
139
          map[keys[i]] = i
693×
140
        end
141
        new(keys, Vector{Any}(values), comments, map)
42×
142
    end
143
end
144

145
include("fits.jl")  # FITS methods
146
include("header.jl")  # FITSHeader methods
147
include("image.jl")  # ImageHDU methods
148
include("table.jl")  # TableHDU & ASCIITableHDU methods
149

150
"""
151
    libcfitsio_version() -> VersionNumber
152

153
Return the version of the underlying CFITSIO library
154

155
### Example ###
156

157
```julia
158
julia> FITSIO.libcfitsio_version()
159
v"3.37.0"
160
```
161

162
"""
163
function libcfitsio_version(version=fits_get_version())
164
    # fits_get_version returns a float. e.g., 3.341f0. We parse that
165
    # into a proper version number. E.g., 3.341 -> v"3.34.1"
166
    v = Int(round(1000 * version))
20×
167
    x = div(v, 1000)
21×
168
    y = div(rem(v, 1000), 10)
21×
169
    z = rem(v, 10)
21×
170
    VersionNumber(x, y, z)
21×
171
end
172

173
end # module
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc