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

83.33
/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)
5×
10
    ncols >= 1 || error("No columns")
11×
11
    nrows = length(cols[1])
7×
12
    length(names) == ncols || error("length of cols and names must match")
11×
13
    for i=1:ncols
37×
14
        length(cols[i]) == nrows || error("column length mismatch")
39×
15
    end
16

17
    lengths = [max(maximum(length, cols[i]), length(names[i])) + spaces
15×
18
               for i=1:ncols]
19
    for i = 1:ncols
37×
20
        print(io, rpad(names[i], lengths[i]))
33×
21
    end
22
    print(io, "\n")
7×
23
    for j = 1:nrows
29×
24
        print(io, " "^indent)
14×
25
        for i=1:ncols
74×
26
            print(io, rpad(cols[i][j], lengths[i]))
66×
27
        end
28
        print(io, "\n")
24×
29
    end
30
end
31

32
function length(f::FITS)
33
    fits_assert_open(f.fitsfile)
645×
34
    Int(fits_get_num_hdus(f.fitsfile))
903×
35
end
36

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

39
# Iteration
40
start(f::FITS) = 1
all except 166.1 and 166.4 - 3×
41
next(f::FITS, state) = (f[state], state + 1)
45×
42
done(f::FITS, state) = state > length(f)
50×
43

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

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

51
    nhdu = length(f)
14×
52

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

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

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

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

84
        show_ascii_table(io, dispnames, dispcols, 2, 6)
7×
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)
725×
91

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

96
    if i > length(f)
126×
UNCOV
97
        error("index out of bounds")
!
98
    end
99
    hdutype = fits_movabs_hdu(f.fitsfile, i)
126×
100
    f.hdus[i] = (hdutype == :image_hdu ? ImageHDU(f.fitsfile, i) :
489×
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]
126×
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)
40×
141
    fits_close_file(f.fitsfile)
56×
142
    f.filename = ""
56×
143
    f.mode = ""
56×
144
    empty!(f.hdus)
56×
145
    nothing
56×
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