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

JuliaAstro / FITSIO.jl / 168

29 Jul 2017 - 5:44 coverage: 75.425% (+3.007%) from 72.418%
168

Pull #77

travis-ci

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

87 of 102 new or added lines in 5 files covered. (85.29%)

61 existing lines in 4 files now uncovered.

577 of 765 relevant lines covered (75.42%)

169.76 hits per line

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

84.85
/src/fits.jl
1
# FITS methods
2

3
const VERBOSE_MODE = Dict("r"=>"read-only",
4
                          "w"=>"read-write",
5
                          "r+"=>"append")
6

7
# helper function for show()
8
function show_ascii_table(io, names, cols, spaces=2, indent=0)
9
    ncols = length(cols)
6×
10
    ncols >= 1 || error("No columns")
12×
11
    nrows = length(cols[1])
8×
12
    length(names) == ncols || error("length of cols and names must match")
12×
13
    for i=1:ncols
38×
14
        length(cols[i]) == nrows || error("column length mismatch")
42×
15
    end
16

17
    lengths = [max(maximum(length, cols[i]), length(names[i])) + spaces
16×
18
               for i=1:ncols]
19
    for i = 1:ncols
38×
20
        print(io, rpad(names[i], lengths[i]))
36×
21
    end
22
    print(io, "\n")
8×
23
    for j = 1:nrows
30×
24
        print(io, " "^indent)
16×
25
        for i=1:ncols
76×
26
            print(io, rpad(cols[i][j], lengths[i]))
72×
27
        end
28
        print(io, "\n")
26×
29
    end
30
end
31

32
function length(f::FITS)
33
    fits_assert_open(f.fitsfile)
780×
34
    Int(fits_get_num_hdus(f.fitsfile))
1,040×
35
end
36

37
endof(f::FITS) = length(f)
594×
38

39
# Iteration
40
start(f::FITS) = 1
all except 168.1 and 168.4 - 4×
41
next(f::FITS, state) = (f[state], state + 1)
54×
42
done(f::FITS, state) = state > length(f)
60×
43

44
function show(io::IO, f::FITS)
45
    fits_assert_open(f.fitsfile)
12×
46

47
    print(io, """File: $(f.filename)
16×
48
    Mode: $(repr(f.mode)) ($(VERBOSE_MODE[f.mode]))
49
    """)
50

51
    nhdu = length(f)
16×
52

53
    if nhdu == 0
16×
54
        print(io, "No HDUs.")
8×
55
    else
56
        print(io, "HDUs: ")
8×
57

58
        names = Vector{String}(nhdu)
8×
59
        vers = Vector{String}(nhdu)
8×
60
        types = Vector{String}(nhdu)
8×
61
        for i = 1:nhdu
38×
62
            t = fits_movabs_hdu(f.fitsfile, i)
16×
63
            types[i] = (t == :image_hdu ? "Image" :
32×
64
                        t == :binary_table ? "Table" :
65
                        t == :ascii_table ? "ASCIITable" :
66
                        error("unknown HDU type"))
67
            nname = fits_try_read_extname(f.fitsfile)
16×
68
            names[i] = get(nname, "")
20×
69
            nver = fits_try_read_extver(f.fitsfile)
16×
70
            vers[i] = isnull(nver) ? "" : string(get(nver))
40×
71
        end
72

73
        nums = [string(i) for i=1:nhdu]
8×
74

75
        # only display version info if present
76
        if maximum(length, vers) > 0
8×
UNCOV
77
            dispnames = ["Num", "Name", "Ver", "Type"]
!
UNCOV
78
            dispcols = Vector{String}[nums, names, vers, types]
!
79
        else
80
            dispnames = ["Num", "Name", "Type"]
8×
81
            dispcols = Vector{String}[nums, names, types]
10×
82
        end
83

84
        show_ascii_table(io, dispnames, dispcols, 2, 6)
8×
85
    end
86
end
87

88
# Returns HDU object based on extension number
89
function getindex(f::FITS, i::Integer)
90
    fits_assert_open(f.fitsfile)
876×
91

92
    if haskey(f.hdus, i)
1,168×
93
        return f.hdus[i]
1,016×
94
    end
95

96
    if i > length(f)
152×
97
        error("index out of bounds")
8×
98
    end
99
    hdutype = fits_movabs_hdu(f.fitsfile, i)
144×
100
    f.hdus[i] = (hdutype == :image_hdu ? ImageHDU(f.fitsfile, i) :
522×
101
                 hdutype == :binary_table ? TableHDU(f.fitsfile, i) :
102
                 hdutype == :ascii_table ? ASCIITableHDU(f.fitsfile, i) :
103
                 error("bad HDU type"))
104
    return f.hdus[i]
144×
105
end
106

107
# Returns HDU based on hduname, version
108
function getindex(f::FITS, name::AbstractString, ver::Int=0)
UNCOV
109
    fits_assert_open(f.fitsfile)
!
UNCOV
110
    fits_movnam_hdu(f.fitsfile, name, ver)
!
UNCOV
111
    i = fits_get_hdu_num(f.fitsfile)
!
112

UNCOV
113
    if haskey(f.hdus, i)
!
114
        return f.hdus[i]
!
115
    end
116

UNCOV
117
    hdutype = fits_get_hdu_type(f.fitsfile)
!
118
    f.hdus[i] = (hdutype == :image_hdu ? ImageHDU(f.fitsfile, i) :
!
119
                 hdutype == :binary_table ? TableHDU(f.fitsfile, i) :
120
                 hdutype == :ascii_table ? ASCIITableHDU(f.fitsfile, i) :
121
                 error("bad HDU type"))
122
    return f.hdus[i]
!
123
end
124

125
"""
126
    close(f::FITS)
127

128
### Purpose ###
129

130
Close the file. Subsequent attempts to operate on `f` will result in an error.
131
`FITS` objects are also automatically closed when they are garbage collected.
132

133
### Example ###
134

135
```julia
136

137
```
138
"""
139
function close(f::FITS)
140
    fits_assert_open(f.fitsfile)
48×
141
    fits_close_file(f.fitsfile)
64×
142
    f.filename = ""
64×
143
    f.mode = ""
64×
144
    empty!(f.hdus)
64×
145
    nothing
64×
146
end
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