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

77.99
/src/libcfitsio.jl
1
# cfitsio.jl - C-style interface to CFITSIO functions:
2
#
3
# - Function names closely mirror the C interface (e.g., `fits_open_file()`).
4
# - Functions operate on `FITSFile`, a thin wrapper for `fitsfile` C struct
5
#   (`FITSFile` has concept of "current HDU", as in CFITSIO).
6
# - Note that the wrapper functions *do* check the return status from CFITSIO
7
#   and throw an error with the appropriate message.
8
#
9
#
10
# The following table gives the correspondances between CFITSIO "types",
11
# the BITPIX keyword and Julia types.
12
#
13
#     -------------------------------------------------
14
#     CODE  CFISTIO         Julia     Comments
15
#     -------------------------------------------------
16
#           int             Cint
17
#           long            Clong
18
#           LONGLONG        Int64     64-bit integer
19
#     -------------------------------------------------
20
#     -------- FITS BITPIX ----------------------------
21
#        8  BYTE_IMG        Uint8
22
#       16  SHORT_IMG       Int16
23
#       32  LONG_IMG        Int32
24
#       64  LONGLONG_IMG    Int64
25
#      -32  FLOAT_IMG       Float32
26
#      -64  DOUBLE_IMG      Float64
27
#      -------- cfitsio "aliases" ---------------------
28
#       10  SBYTE_IMG       Int8     written as: BITPIX = 8, BSCALE = 1,
29
#                                                BZERO = -128
30
#       20  USHORT_IMG      Uint16   written as: BITPIX = 16, BSCALE = 1,
31
#                                                BZERO = 32768
32
#       40  LONG_IMG        Uint32   written as: BITPIX = 32, BSCALE = 1,
33
#                                                BZERO = 2147483648
34
#     -------------------------------------------------
35
#     -------- FITS TABLE DATA TYPES ------------------
36
#        1  TBIT
37
#       11  TBYTE           Cuchar = Uint8
38
#       12  TSBYTE          Cchar = Int8
39
#       14  TLOGICAL        Bool
40
#       16  TSTRING         String
41
#       20  TUSHORT         Cushort
42
#       21  TSHORT          Cshort
43
#       30  TUINT           Cuint
44
#       31  TINT            Cint
45
#       40  TULONG          Culong
46
#       41  TLONG           Clong
47
#       42  TFLOAT          Cfloat
48
#       81  TLONGLONG       Int64
49
#       82  TDOUBLE         Cdouble
50
#       83  TCOMPLEX        Complex{Cfloat}
51
#      163  TDBLCOMPLEX     Complex{Cdouble}
52
#     -------------------------------------------------
53
#
54

55
isdefined(Base, :__precompile__) && __precompile__()
56

57
module Libcfitsio
58

59
export FITSFile,
60
       FITSMemoryHandle,
61
       fits_assert_open,
62
       fits_clobber_file,
63
       fits_close_file,
64
       fits_copy_image_section,
65
       fits_create_ascii_tbl,
66
       fits_create_binary_tbl,
67
       fits_create_file,
68
       fits_create_img,
69
       fits_delete_file,
70
       fits_delete_key,
71
       fits_delete_record,
72
       fits_delete_rows,
73
       fits_file_mode,
74
       fits_file_name,
75
       fits_get_hdrspace,
76
       fits_get_hdu_num,
77
       fits_get_hdu_type,
78
       fits_get_img_dim,
79
       fits_get_img_equivtype,
80
       fits_get_img_size,
81
       fits_get_img_type,
82
       fits_get_num_cols,
83
       fits_get_num_hdus,
84
       fits_get_num_rows,
85
       fits_get_rowsize,
86
       fits_get_colnum,
87
       fits_get_coltype,
88
       fits_get_eqcoltype,
89
       fits_get_version,
90
       fits_read_tdim,
91
       fits_hdr2str,
92
       fits_insert_rows,
93
       fits_movabs_hdu,
94
       fits_movrel_hdu,
95
       fits_movnam_hdu,
96
       fits_open_data,
97
       fits_open_file,
98
       fits_open_image,
99
       fits_open_table,
100
       fits_open_memfile,
101
       fits_read_col,
102
       fits_read_descript,
103
       fits_read_keyn,
104
       fits_read_key_str,
105
       fits_read_key_lng,
106
       fits_read_keys_lng,
107
       fits_read_keyword,
108
       fits_read_pix,
109
       fits_read_record,
110
       fits_read_subset,
111
       fits_update_key,
112
       fits_write_col,
113
       fits_write_date,
114
       fits_write_comment,
115
       fits_write_history,
116
       fits_write_key,
117
       fits_write_pix,
118
       fits_write_record,
119
       fits_write_tdim
120

121
if isfile(joinpath(dirname(@__FILE__),"..","deps","deps.jl"))
122
    include("../deps/deps.jl")
123
else
124
    error("FITSIO not properly installed. Please run Pkg.build(\"FITSIO\")")
125
end
126

127
const TYPE_FROM_BITPIX = Dict{Cint, DataType}()
128
for (T, code) in ((UInt8,     8), # BYTE_IMG
129
                  (Int16,    16), # SHORT_IMG
130
                  (Int32,    32), # LONG_IMG
131
                  (Int64,    64), # LONGLONG_IMG
132
                  (Float32, -32), # FLOAT_IMG
133
                  (Float64, -64), # DOUBLE_IMG
134
                  (Int8,     10), # SBYTE_IMG
135
                  (UInt16,   20), # USHORT_IMG
136
                  (UInt32,   40)) # ULONG_IMG
137
    local value = Cint(code)
138
    @eval begin
139
        TYPE_FROM_BITPIX[$value] = $T
140
        bitpix_from_type(::Type{$T}) = $value
all except 168.1 and 168.4 - 60×
141
    end
142
end
143

144
for (T, code) in ((UInt8,       11),
145
                  (Int8,        12),
146
                  (Bool,        14),
147
                  (String,      16),
148
                  (Cushort,     20),
149
                  (Cshort,      21),
150
                  (Cuint,       30),
151
                  (Cint,        31),
152
                  (Int64,       81),
153
                  (Float32,     42),
154
                  (Float64,     82),
155
                  (Complex64,   83),
156
                  (Complex128, 163))
157
    @eval cfitsio_typecode(::Type{$T}) = Cint($code)
996×
158
end
159

160
# Above, we don't define a method for Clong because it is either Cint (Int32)
161
# or Int64 depending on the platform, and those methods are already defined.
162
# Culong is either UInt64 or Cuint depending on platform. Only define it if
163
# not already defined.
164
if Culong !== Cuint
165
    cfitsio_typecode(::Type{Culong}) = Cint(40)
!
166
end
167

168
# -----------------------------------------------------------------------------
169
# FITSFile type
170

171
type FITSFile
172
    ptr::Ptr{Void}
173

174
    function FITSFile(ptr::Ptr{Void})
175
        f = new(ptr)
72×
176
        finalizer(f, fits_close_file)
96×
177
        f
96×
178
    end
179
end
180

181
# FITS wants to be able to update the ptr, so keep them
182
# in a mutable struct
183
type FITSMemoryHandle
184
    ptr::Ptr{Void}
48×
185
    size::Csize_t
186
end
187
FITSMemoryHandle() = FITSMemoryHandle(C_NULL, 0)
42×
188

189
# -----------------------------------------------------------------------------
190
# error messaging
191

192
function fits_assert_open(f::FITSFile)
193
    if f.ptr == C_NULL
2,688×
194
        error("attempt to access closed FITS file")
only 168.1 and 168.4 - 896×
195
    end
196
end
197

198
function fits_get_errstatus(status::Cint)
199
    msg = Vector{UInt8}(31)
!
200
    ccall((:ffgerr,libcfitsio), Void, (Cint,Ptr{UInt8}), status, msg)
!
201
    unsafe_string(pointer(msg))
!
202
end
203

204
function fits_assert_ok(status::Cint, filename = nothing)
205
    if status != 0
12,174×
206
        prefix = filename == nothing ? "" : "While processing file `$filename`: "
!
207
        error(string(prefix, fits_get_errstatus(status)))
only 168.1 and 168.4 - 2,040×
208
    end
209
end
210

211
fits_get_version() = ccall((:ffvers, libcfitsio), Cfloat, (Ptr{Cfloat},), &0.)
6×
212

213
# -----------------------------------------------------------------------------
214
# file access & info functions
215

216
function fits_create_file(filename::AbstractString)
217
    ptr = Ref{Ptr{Void}}()
48×
218
    status = Ref{Cint}(0)
64×
219
    ccall((:ffinit,libcfitsio), Cint, (Ref{Ptr{Void}},Ptr{UInt8},Ref{Cint}),
112×
220
          ptr, filename, status)
221
    fits_assert_ok(status[], filename)
64×
222
    FITSFile(ptr[])
64×
223
end
224

UNCOV
225
fits_clobber_file(filename::AbstractString) = fits_create_file("!"*filename)
!
226

227
for (a,b) in ((:fits_open_data, "ffdopn"),
228
              (:fits_open_file, "ffopen"),
229
              (:fits_open_image,"ffiopn"),
230
              (:fits_open_table,"fftopn"))
231
    @eval begin
232
        function ($a)(filename::AbstractString, mode::Integer=0)
233
            ptr = Ref{Ptr{Void}}()
30×
234
            status = Ref{Cint}(0)
24×
235
            ccall(($b,libcfitsio), Cint,
48×
236
                  (Ref{Ptr{Void}},Ptr{UInt8},Cint,Ref{Cint}),
237
                  ptr, filename, mode, status)
238
            fits_assert_ok(status[], filename)
24×
239
            FITSFile(ptr[])
24×
240
        end
241
    end
242
end
243

244
# filename is ignored by the C library
245
function fits_open_memfile(data::Vector{UInt8}, mode::Integer=0, filename="")
246
    # Only reading is supported right now
247
    @assert mode == 0
12×
248
    ptr = Ref{Ptr{Void}}(C_NULL)
8×
249
    status = Ref{Cint}(0)
8×
250
    handle = FITSMemoryHandle(pointer(data),length(data))
8×
251
    dataptr = Ptr{Ptr{Void}}(pointer_from_objref(handle))
8×
252
    sizeptr = Ptr{Csize_t}(dataptr+sizeof(Ptr{Void}))
8×
253
    ccall(("ffomem",libcfitsio), Cint,
24×
254
      (Ptr{Ptr{Void}},Ptr{UInt8},Cint,Ptr{Ptr{UInt8}},
255
       Ptr{Csize_t}, Csize_t, Ptr{Void}, Ptr{Cint}),
256
       ptr, filename, mode, dataptr, sizeptr, 2880, C_NULL, status)
257
    fits_assert_ok(status[])
8×
258
    FITSFile(ptr[]), handle
8×
259
end
260

261
for (a,b) in ((:fits_close_file, "ffclos"),
262
              (:fits_delete_file,"ffdelt"))
263
    @eval begin
264
        function ($a)(f::FITSFile)
265

266
            # fits_close_file() is called during garbage collection, but file
267
            # may already be closed by user, so we need to check if it is open.
268
            if f.ptr != C_NULL
98×
269
                status = Ref{Cint}(0)
96×
270
                ccall(($b,libcfitsio), Cint,
144×
271
                      (Ptr{Void},Ref{Cint}),
272
                      f.ptr, status)
273
                fits_assert_ok(status[])
96×
274
                f.ptr = C_NULL
126×
275
            end
276
        end
277
    end
278
end
279

UNCOV
280
close(f::FITSFile) = fits_close_file(f)
!
281

282
function fits_file_name(f::FITSFile)
UNCOV
283
    value = Vector{UInt8}(1025)
!
UNCOV
284
    status = Ref{Cint}(0)
!
UNCOV
285
    ccall((:ffflnm,libcfitsio), Cint,
!
286
          (Ptr{Void},Ptr{UInt8},Ref{Cint}),
287
          f.ptr, value, status)
UNCOV
288
    fits_assert_ok(status[])
!
UNCOV
289
    unsafe_string(pointer(value))
!
290
end
291

292
function fits_file_mode(f::FITSFile)
UNCOV
293
    result = Ref{Cint}(0)
!
UNCOV
294
    status = Ref{Cint}(0)
!
UNCOV
295
    ccall(("ffflmd", libcfitsio), Cint, (Ptr{Void}, Ref{Cint}, Ref{Cint}),
!
296
          f.ptr, result, status)
UNCOV
297
    fits_assert_ok(status[])
!
UNCOV
298
    result[]
!
299
end
300

301

302
# -----------------------------------------------------------------------------
303
# header access functions
304

305
function fits_get_hdrspace(f::FITSFile)
306
    keysexist = Ref{Cint}(0)
30×
307
    morekeys = Ref{Cint}(0)
40×
308
    status = Ref{Cint}(0)
40×
309
    ccall((:ffghsp,libcfitsio), Cint,
80×
310
        (Ptr{Void},Ref{Cint},Ref{Cint},Ref{Cint}),
311
        f.ptr, keysexist, morekeys, status)
312
    fits_assert_ok(status[])
40×
313
    (keysexist[], morekeys[])
40×
314
end
315

316
function fits_read_key_str(f::FITSFile, keyname::String)
317
    value = Vector{UInt8}(71)
36×
318
    comment = Vector{UInt8}(71)
48×
319
    status = Ref{Cint}(0)
48×
320
    ccall((:ffgkys, libcfitsio), Cint,
108×
321
          (Ptr{Void}, Ptr{UInt8}, Ptr{UInt8}, Ptr{UInt8}, Ref{Cint}),
322
          f.ptr, keyname, value, comment, status)
323
    fits_assert_ok(status[])
48×
324
    unsafe_string(pointer(value)), unsafe_string(pointer(comment))
48×
325
end
326

327
function fits_read_key_lng(f::FITSFile, keyname::String)
328
    value = Ref{Clong}(0)
24×
329
    comment = Vector{UInt8}(71)
32×
330
    status = Ref{Cint}(0)
32×
331
    ccall((:ffgkyj, libcfitsio), Cint,
72×
332
          (Ptr{Void}, Ptr{UInt8}, Ref{Clong}, Ptr{UInt8}, Ref{Cint}),
333
          f.ptr, keyname, value, comment, status)
334
    fits_assert_ok(status[])
32×
335
    value[], unsafe_string(pointer(comment))
32×
336
end
337

338
function fits_read_keys_lng(f::FITSFile, keyname::String,
339
                            nstart::Integer, nmax::Integer)
340
    value = Vector{Clong}(nmax - nstart + 1)
12×
341
    nfound = Ref{Cint}(0)
16×
342
    status = Ref{Cint}(0)
16×
343
    ccall((:ffgknj, libcfitsio), Cint,
44×
344
          (Ptr{Void}, Ptr{UInt8}, Cint, Cint, Ptr{Clong}, Ref{Cint}, Ref{Cint}),
345
          f.ptr, keyname, nstart, nmax, value, nfound, status)
346
    fits_assert_ok(status[])
16×
347
    value, nfound[]
16×
348
end
349

350
function fits_read_keyword(f::FITSFile, keyname::String)
351
    value = Vector{UInt8}(71)
6×
352
    comment = Vector{UInt8}(71)
8×
353
    status = Ref{Cint}(0)
8×
354
    ccall((:ffgkey,libcfitsio), Cint,
18×
355
        (Ptr{Void},Ptr{UInt8},Ptr{UInt8},Ptr{UInt8},Ref{Cint}),
356
        f.ptr, keyname, value, comment, status)
357
    fits_assert_ok(status[])
8×
358
    unsafe_string(pointer(value)), unsafe_string(pointer(comment))
8×
359
end
360

361
function fits_read_record(f::FITSFile, keynum::Integer)
UNCOV
362
    card = Vector{UInt8}(81)
!
UNCOV
363
    status = Ref{Cint}(0)
!
NEW
364
    ccall((:ffgrec,libcfitsio), Cint,
!
365
        (Ptr{Void},Cint,Ptr{UInt8},Ref{Cint}),
366
        f.ptr, keynum, card, status)
NEW
367
    fits_assert_ok(status[])
!
NEW
368
    unsafe_string(pointer(card))
!
369
end
370

371
function fits_read_keyn(f::FITSFile, keynum::Integer)
372
    keyname = Vector{UInt8}(9)
6×
373
    value = Vector{UInt8}(71)
8×
374
    comment = Vector{UInt8}(71)
8×
375
    status = Ref{Cint}(0)
8×
376
    ccall((:ffgkyn,libcfitsio), Cint,
20×
377
        (Ptr{Void},Cint,Ptr{UInt8},Ptr{UInt8},Ptr{UInt8},Ref{Cint}),
378
        f.ptr, keynum, keyname, value, comment, status)
379
    fits_assert_ok(status[])
8×
380
    (unsafe_string(pointer(keyname)), unsafe_string(pointer(value)),
8×
381
     unsafe_string(pointer(comment)))
382
end
383

384
function fits_write_key(f::FITSFile, keyname::String,
385
                        value::Union{Real,String}, comment::String)
386
    cvalue = isa(value,String) ?  value :
48×
387
             isa(value,Bool) ? Cint[value] : reinterpret(UInt8, [value])
388
    status = Ref{Cint}(0)
64×
389
    ccall((:ffpky,libcfitsio), Cint,
160×
390
        (Ptr{Void},Cint,Ptr{UInt8},Ptr{UInt8},Ptr{UInt8},Ref{Cint}),
391
        f.ptr, cfitsio_typecode(typeof(value)), keyname,
392
        cvalue, comment, status)
393
    fits_assert_ok(status[])
64×
394
end
395

396
function fits_write_date(f::FITSFile)
397
    status = Ref{Cint}(0)
12×
398
    ccall((:ffpdat, libcfitsio), Cint, (Ptr{Void}, Ref{Cint}), f.ptr, status)
24×
399
    fits_assert_ok(status[])
16×
400
end
401

402
function fits_write_comment(f::FITSFile, comment::String)
403
    status = Ref{Cint}(0)
24×
404
    ccall((:ffpcom, libcfitsio), Cint, (Ptr{Void}, Ptr{UInt8}, Ref{Cint}),
56×
405
          f.ptr, comment, status)
406
    fits_assert_ok(status[])
32×
407
end
408

409
function fits_write_history(f::FITSFile, history::String)
410
    status = Ref{Cint}(0)
12×
411
    ccall((:ffphis, libcfitsio), Cint, (Ptr{Void}, Ptr{UInt8}, Ref{Cint}),
28×
412
          f.ptr, history, status)
413
    fits_assert_ok(status[])
16×
414
end
415

416
# update key: if already present, update it, otherwise add it.
417
for (a,T,S) in (("ffukys", :(String), :(Ptr{UInt8})),
418
                ("ffukyl", :Bool,        :Cint),
419
                ("ffukyj", :Integer,     :Int64))
420
    @eval begin
421
        function fits_update_key(f::FITSFile, key::String, value::$T,
422
                                 comment::Union{String, Ptr{Void}}=C_NULL)
423
            status = Ref{Cint}(0)
42×
424
            ccall(($a, libcfitsio), Cint,
126×
425
                  (Ptr{Void}, Ptr{UInt8}, $S, Ptr{UInt8}, Ref{Cint}),
426
                  f.ptr, key, value, comment, status)
427
            fits_assert_ok(status[])
56×
428
        end
429
    end
430
end
431

432
function fits_update_key(f::FITSFile, key::String, value::AbstractFloat,
433
                         comment::Union{String, Ptr{Void}}=C_NULL)
434
    status = Ref{Cint}(0)
12×
435
    ccall(("ffukyd", libcfitsio), Cint,
40×
436
          (Ptr{Void}, Ptr{UInt8}, Cdouble, Cint, Ptr{UInt8}, Ref{Cint}),
437
          f.ptr, key, value, -15, comment, status)
438
    fits_assert_ok(status[])
16×
439
end
440

441
function fits_update_key(f::FITSFile, key::String, value::Void,
442
                         comment::Union{String, Ptr{Void}}=C_NULL)
443
    status = Ref{Cint}(0)
6×
444
    ccall(("ffukyu", libcfitsio), Cint,
16×
445
          (Ptr{Void}, Ptr{UInt8}, Ptr{UInt8}, Ref{Cint}),
446
          f.ptr, key, comment, status)
447
    fits_assert_ok(status[])
8×
448
end
449

450
function fits_write_record(f::FITSFile, card::String)
UNCOV
451
    status = Ref{Cint}(0)
!
UNCOV
452
    ccall((:ffprec,libcfitsio), Cint,
!
453
        (Ptr{Void},Ptr{UInt8},Ref{Cint}),
454
        f.ptr, card, status)
UNCOV
455
    fits_assert_ok(status[])
!
456
end
457

458
function fits_delete_record(f::FITSFile, keynum::Integer)
UNCOV
459
    status = Ref{Cint}(0)
!
UNCOV
460
    ccall((:ffdrec,libcfitsio), Cint,
!
461
        (Ptr{Void},Cint,Ref{Cint}),
462
        f.ptr, keynum, status)
UNCOV
463
    fits_assert_ok(status[])
!
464
end
465

466
function fits_delete_key(f::FITSFile, keyname::String)
NEW
467
    status = Ref{Cint}(0)
!
NEW
468
    ccall((:ffdkey,libcfitsio), Cint,
!
469
        (Ptr{Void},Ptr{UInt8},Ref{Cint}),
470
        f.ptr, keyname, status)
UNCOV
471
    fits_assert_ok(status[])
!
472
end
473

474
"""
475
    fits_hdr2str(f::FITSFile, nocomments::Bool=false)
476

477
Return the header of the CHDU as a string. If `nocomments` is `true`, comment
478
cards are stripped from the output.
479

480
### Example ###
481

482
```julia
483

484
```
485
"""
486
function fits_hdr2str(f::FITSFile, nocomments::Bool=false)
487
    status = Ref{Cint}(0)
24×
488
    header = Ref{Ptr{UInt8}}()
16×
489
    nkeys = Ref{Cint}(0)
16×
490
    ccall((:ffhdr2str, libcfitsio), Cint,
44×
491
          (Ptr{Void}, Cint, Ptr{Ptr{UInt8}}, Cint,
492
           Ptr{Ptr{UInt8}}, Ref{Cint}, Ref{Cint}),
493
          f.ptr, nocomments, &C_NULL, 0, header, nkeys, status)
494
    result = unsafe_string(header[])
16×
495

496
    # free header pointer allocated by cfitsio (result is a copy)
497
    ccall((:fffree, libcfitsio), Ref{Cint},
24×
498
          (Ptr{UInt8}, Ref{Cint}),
499
          header[], status)
500
    fits_assert_ok(status[])
16×
501
    result
16×
502
end
503

504

505
# -----------------------------------------------------------------------------
506
# HDU info functions and moving the current HDU
507

508
function hdu_int_to_type(hdu_type_int)
509
    if hdu_type_int == 0
1,020×
510
        return :image_hdu
1,144×
511
    elseif hdu_type_int == 1
216×
512
        return :ascii_table
48×
513
    elseif hdu_type_int == 2
168×
514
        return :binary_table
168×
515
    end
516

UNCOV
517
    :unknown
!
518
end
519

520
"""
521
    fits_movabs_hdu(f::FITSFile, hduNum::Integer)
522

523
Change the current HDU to the value specified by `hduNum`, and return a symbol
524
describing the type of the HDU.
525

526
Possible symbols are: `image_hdu`, `ascii_table`, or `binary_table`.
527
The value of `hduNum` must range between 1 and the value returned by
528
[`fits_get_num_hdus`](@ref).
529

530
### Example ###
531

532
```julia
533

534
```
535
"""
536
function fits_movabs_hdu end
537

538
"""
539
    fits_movrel_hdu(f::FITSFile, hduNum::Integer)
540

541
Change the current HDU by moving forward or backward by `hduNum` HDUs
542
(positive means forward), and return the same as [`fits_movabs_hdu`](@ref).
543

544
### Example ###
545

546
```julia
547

548
```
549
"""
550
function fits_movrel_hdu end
551
for (a,b) in ((:fits_movabs_hdu,"ffmahd"),
552
              (:fits_movrel_hdu,"ffmrhd"))
553
    @eval begin
554
        function ($a)(f::FITSFile, hduNum::Integer)
555
            hdu_type = Ref{Cint}(0)
1,020×
556
            status = Ref{Cint}(0)
1,360×
557
            ccall(($b,libcfitsio), Cint,
2,720×
558
                  (Ptr{Void}, Cint, Ref{Cint}, Ref{Cint}),
559
                  f.ptr, hduNum, hdu_type, status)
560
            fits_assert_ok(status[])
1,360×
561
            hdu_int_to_type(hdu_type[])
1,360×
562
        end
563
    end
564
end
565

566
"""
567
    fits_movnam_hdu(f::FITSFile, extname::String, extver::Integer=0,
568
                    hdu_type_int::Integer=-1)
569

570
Change the current HDU by moving to the (first) HDU which has the specified
571
extension type and EXTNAME and EXTVER keyword values (or HDUNAME and HDUVER keywords).
572

573
If `extver` is 0 (the default) then the EXTVER keyword is ignored and the first HDU
574
with a matching EXTNAME (or HDUNAME) keyword will be found. If `hdu_type_int`
575
is -1 (the default) only the extname and extver values will be used to locate the
576
correct extension. If no matching HDU is found in the file, the current HDU will
577
remain unchanged.
578

579
### Example ###
580

581
```julia
582

583
```
584
"""
585
function fits_movnam_hdu(f::FITSFile, extname::String, extver::Integer=0,
586
                         hdu_type::Integer=-1)
UNCOV
587
    status = Ref{Cint}(0)
!
UNCOV
588
    ccall((:ffmnhd,libcfitsio), Cint,
!
589
          (Ptr{Void}, Cint, Ptr{UInt8}, Cint, Ref{Cint}),
590
          f.ptr, hdu_type, extname, extver, status)
UNCOV
591
    fits_assert_ok(status[])
!
592
end
593

594
function fits_get_hdu_num(f::FITSFile)
UNCOV
595
    hdunum = Ref{Cint}(0)
!
UNCOV
596
    ccall((:ffghdn,libcfitsio), Cint,
!
597
          (Ptr{Void}, Ref{Cint}),
598
          f.ptr, hdunum)
UNCOV
599
    hdunum[]
!
600
end
601

602
function fits_get_hdu_type(f::FITSFile)
UNCOV
603
    hdutype = Ref{Cint}(0)
!
UNCOV
604
    status = Ref{Cint}(0)
!
UNCOV
605
    ccall((:ffghdt, libcfitsio), Cint,
!
606
          (Ptr{Void}, Ref{Cint}, Ref{Cint}),
607
          f.ptr, hdutype, status)
UNCOV
608
    fits_assert_ok(status[])
!
UNCOV
609
    hdu_int_to_type(hdutype[])
!
610
end
611

612
# -----------------------------------------------------------------------------
613
# image HDU functions
614

615
"""
616
    fits_get_img_size(f::FITSFile)
617

618
Get the dimensions of the image.
619

620
### Example ###
621

622
```julia
623

624
```
625
"""
626
function fits_get_img_size end
627
for (a, b) in ((:fits_get_img_type,      "ffgidt"),
628
               (:fits_get_img_equivtype, "ffgiet"),
629
               (:fits_get_img_dim,       "ffgidm"))
630
    @eval function ($a)(f::FITSFile)
631
        result = Ref{Cint}(0)
1,074×
632
        status = Ref{Cint}(0)
1,432×
633
        ccall(($b, libcfitsio), Cint, (Ptr{Void}, Ref{Cint}, Ref{Cint}),
2,506×
634
              f.ptr, result, status)
635
        fits_assert_ok(status[])
1,432×
636
        result[]
1,432×
637
    end
638
end
639

640
"""
641
    fits_create_img(f::FITSFile, t::Type, naxes::Vector{Int})
642

643
Create a new primary array or IMAGE extension with a specified data type and size.
644

645
### Example ###
646

647
```julia
648

649
```
650
"""
651
function fits_create_img{T, S<:Integer}(f::FITSFile, ::Type{T},
652
                                        naxes::Vector{S})
653
    status = Ref{Cint}(0)
90×
654
    ccall((:ffcrimll, libcfitsio), Cint,
270×
655
          (Ptr{Void}, Cint, Cint, Ptr{Int64}, Ref{Cint}),
656
          f.ptr, bitpix_from_type(T), length(naxes),
657
          Vector{Int64}(naxes), status)
658
    fits_assert_ok(status[])
120×
659
end
660

661
"""
662
    fits_write_pix(f::FITSFile, fpixel::Vector{Int}, nelements::Int, data::Array)
663

664
Write pixels from `data` into the FITS file.
665

666
### Example ###
667

668
```julia
669

670
```
671
"""
672
function fits_write_pix{S<:Integer,T}(f::FITSFile, fpixel::Vector{S},
673
                                      nelements::Integer, data::Array{T})
674
    status = Ref{Cint}(0)
78×
675
    ccall((:ffppxll, libcfitsio), Cint,
260×
676
          (Ptr{Void}, Cint, Ptr{Int64}, Int64, Ptr{Void}, Ref{Cint}),
677
          f.ptr, cfitsio_typecode(T), Vector{Int64}(fpixel),
678
          nelements, data, status)
679
    fits_assert_ok(status[])
104×
680
end
681

682
function fits_write_pix(f::FITSFile, data::Array)
UNCOV
683
    fits_write_pix(f, ones(Int64, length(size(data))), length(data), data)
!
684
end
685

686
function fits_read_pix{S<:Integer,T}(f::FITSFile, fpixel::Vector{S},
687
                                     nelements::Int, nullval::T,
688
                                     data::Array{T})
UNCOV
689
    anynull = Ref{Cint}(0)
!
UNCOV
690
    status = Ref{Cint}(0)
!
NEW
691
    ccall((:ffgpxvll, libcfitsio), Cint,
!
692
          (Ptr{Void}, Cint, Ptr{Int64}, Int64, Ptr{Void}, Ptr{Void},
693
           Ref{Cint}, Ref{Cint}),
694
          f.ptr, cfitsio_typecode(T), Vector{Int64}(fpixel),
695
          nelements, &nullval, data, anynull, status)
NEW
696
    fits_assert_ok(status[])
!
UNCOV
697
    anynull[]
!
698
end
699

700
"""
701
    fits_read_pix(f::FITSFile, fpixel::Vector{Int}, nelements::Int, data::Array)
702

703
Read pixels from the FITS file into `data`.
704

705
### Example ###
706

707
```julia
708

709
```
710
"""
711
function fits_read_pix{S<:Integer,T}(f::FITSFile, fpixel::Vector{S},
712
                                     nelements::Int, data::Array{T})
713
    anynull = Ref{Cint}(0)
78×
714
    status = Ref{Cint}(0)
104×
715
    ccall((:ffgpxvll, libcfitsio), Cint,
312×
716
          (Ptr{Void}, Cint, Ptr{Int64}, Int64, Ptr{Void}, Ptr{Void},
717
           Ref{Cint}, Ref{Cint}),
718
          f.ptr, cfitsio_typecode(T), Vector{Int64}(fpixel),
719
          nelements, C_NULL, data, anynull, status)
720
    fits_assert_ok(status[])
104×
721
    anynull[]
104×
722
end
723

724
function fits_read_pix(f::FITSFile, data::Array)
725
    fits_read_pix(f, ones(Int64,length(size(data))), length(data), data)
78×
726
end
727

728
function fits_read_subset{S1<:Integer,S2<:Integer,S3<:Integer,T}(
729
             f::FITSFile, fpixel::Vector{S1}, lpixel::Vector{S2},
730
             inc::Vector{S3}, data::Array{T})
731
    anynull = Ref{Cint}(0)
324×
732
    status = Ref{Cint}(0)
432×
733
    ccall((:ffgsv, libcfitsio), Cint,
1,404×
734
          (Ptr{Void}, Cint, Ptr{Clong}, Ptr{Clong}, Ptr{Clong}, Ptr{Void},
735
           Ptr{Void}, Ref{Cint}, Ref{Cint}),
736
          f.ptr, cfitsio_typecode(T),
737
          Vector{Clong}(fpixel),
738
          Vector{Clong}(lpixel),
739
          Vector{Clong}(inc),
740
          C_NULL, data, anynull, status)
741
    fits_assert_ok(status[])
432×
742
    anynull[]
432×
743
end
744

745
function fits_copy_image_section(fin::FITSFile, fout::FITSFile,
746
                                 section::String)
747
    status = Ref{Cint}(0)
12×
748
    ccall((:fits_copy_image_section,libcfitsio), Cint,
32×
749
          (Ptr{Void}, Ptr{Void}, Ptr{UInt8}, Ref{Cint}),
750
          fin.ptr, fout.ptr, section, status)
751
    fits_assert_ok(status[])
16×
752
end
753

754

755
# -----------------------------------------------------------------------------
756
# ASCII/binary table HDU functions
757

758
# The three fields are: ttype, tform, tunit (CFITSIO's terminology)
759
const ColumnDef = Tuple{String, String, String}
760

761
"""
762
    fits_create_binary_tbl(f::FITSFile, numrows::Integer, coldefs::Array{ColumnDef},
763
                           extname::String)
764

765
Append a new HDU containing a binary table. The meaning of the parameters is the same
766
as in a call to [`fits_create_ascii_tbl`](@ref).
767

768
In general, one should pick this function for creating tables in a new HDU, as binary tables
769
require less space on the disk and are more efficient to read and write.
770
(Moreover, a few datatypes are not supported in ASCII tables).
771

772
### Example ###
773

774
```julia
775

776
```
777
"""
778
function fits_create_binary_tbl end
779

780
"""
781
    fits_create_ascii_tbl(f::FITSFile, numrows::Integer, coldefs::Array{ColumnDef}, extname::String)
782

783
Append a new HDU containing an ASCII table.
784

785
The table will have `numrows` rows (this parameter can be set to zero), each
786
initialized with the default value. In order to create a table, the programmer
787
must specify the characteristics of each column. The columns are specified by the
788
`coldefs` variable, which is an array of tuples.
789
Each tuple must have three string fields:
790

791
1. The name of the column.
792
2. The data type and the repetition count. It must be a string made by a number
793
   (the repetition count) followed by a letter specifying the type (in the example
794
   above, `D` stands for `Float64`, `E` stands for `Float32`, `A` stands for `Char`).
795
   Refer to the CFITSIO documentation for more information about the syntax of this
796
   parameter.
797
3. The measure unit of this field. This is used only as a comment.
798

799
The value of `extname` sets the "extended name" of the table, i.e., a string
800
that in some situations can be used to refer to the HDU itself.
801

802
Note that, unlike for binary tables, CFITSIO puts some limitations to the
803
types that can be used in an ASCII table column. Refer to the CFITSIO manual
804
for further information.
805

806
See also [`fits_create_binary_tbl`](@ref) for a similar function which
807
creates binary tables.
808

809
### Example ###
810

811
```julia
812

813
```
814
"""
815
function fits_create_ascii_tbl end
816
for (a,b) in ((:fits_create_binary_tbl, 2),
817
              (:fits_create_ascii_tbl,  1))
818
    @eval begin
819
        function ($a)(f::FITSFile, numrows::Integer,
820
                      coldefs::Array{ColumnDef}, extname::String)
821

822
            # get length and convert coldefs to three arrays of Ptr{Uint8}
823
            ntype = length(coldefs)
12×
824
            ttype = [pointer(x[1]) for x in coldefs]
28×
825
            tform = [pointer(x[2]) for x in coldefs]
28×
826
            tunit = [pointer(x[3]) for x in coldefs]
28×
827
            status = Ref{Cint}(0)
16×
828

829
            ccall(("ffcrtb", libcfitsio), Cint,
52×
830
                  (Ptr{Void}, Cint, Int64, Cint,
831
                   Ptr{Ptr{UInt8}}, Ptr{Ptr{UInt8}},
832
                   Ptr{Ptr{UInt8}}, Ptr{UInt8}, Ref{Cint}),
833
                  f.ptr, $b, numrows, ntype,
834
                  ttype, tform, tunit, extname,
835
                  status)
836
            fits_assert_ok(status[])
16×
837
        end
838
    end
839
end
840

841
for (a,b,T) in ((:fits_get_num_cols,  "ffgncl",  :Cint),
842
                (:fits_get_num_hdus,  "ffthdu",  :Cint),
843
                (:fits_get_rowsize,   "ffgrsz",  :Clong))
844
    @eval begin
845
        function ($a)(f::FITSFile)
846
            result = Ref{$T}(0)
792×
847
            status = Ref{Cint}(0)
1,056×
848
            ccall(($b,libcfitsio), Cint,
1,848×
849
                  (Ptr{Void}, Ref{$T}, Ref{Cint}),
850
                  f.ptr, result, status)
851
            fits_assert_ok(status[])
1,056×
852
            result[]
1,056×
853
        end
854
    end
855
end
856

857
function fits_get_colnum(f::FITSFile, tmplt::String)
858
    result = Ref{Cint}(0)
132×
859
    status = Ref{Cint}(0)
176×
860

861
    # Second argument is case-sensitivity of search: 0 = case-insensitive
862
    #                                                1 = case-sensitive
863
    ccall(("ffgcno", libcfitsio), Cint,
396×
864
          (Ptr{Void}, Cint, Ptr{UInt8}, Ref{Cint}, Ref{Cint}),
865
          f.ptr, 0, tmplt, result, status)
866
    fits_assert_ok(status[])
176×
867
    return result[]
176×
868
end
869

870
# The following block are all functions that have separate variants for Clong
871
# and 64-bit integers in cfitsio. Rather than providing both of these, we
872
# provide only one according to the native integer type on the platform.
873
if  promote_type(Int, Clong) == Clong
874
    T = Clong
875
    ffgtdm = "ffgtdm"
876
    ffgnrw = "ffgnrw"
877
    ffptdm = "ffptdm"
878
    ffgtcl = "ffgtcl"
879
    ffeqty = "ffeqty"
880
    ffgdes = "ffgdes"
881
    ffgisz = "ffgisz"
882
else
883
    T = Int64
884
    ffgtdm = "ffgtdmll"
885
    ffgnrw = "ffgnrwll"
886
    ffptdm = "ffptdmll"
887
    ffgtcl = "ffgtclll"
888
    ffeqty = "ffeqtyll"
889
    ffgdes = "ffgdesll"
890
    ffgisz = "ffgiszll"
891
end
892

893
"""
894
    fits_get_coltype(f::FITSFile, colnum::Integer)
895

896
Provided that the current HDU contains either an ASCII or binary table, return
897
information about the column at position `colnum` (counting from 1).
898

899
Return is a tuple containing
900

901
- `typecode`: CFITSIO integer type code of the column.
902
- `repcount`: Repetition count for the column.
903
- `width`: Width of an individual element.
904

905
### Example ###
906

907
```julia
908

909
```
910
"""
911
function fits_get_coltype end
912
@eval begin
913
    function fits_get_coltype(ff::FITSFile, colnum::Integer)
UNCOV
914
        typecode = Ref{Cint}(0)
!
UNCOV
915
        repcnt = Ref{$T}(0)
!
UNCOV
916
        width = Ref{$T}(0)
!
UNCOV
917
        status = Ref{Cint}(0)
!
UNCOV
918
        ccall(($ffgtcl,libcfitsio), Cint,
!
919
              (Ptr{Void}, Cint, Ref{Cint}, Ref{$T}, Ref{$T}, Ref{Cint}),
920
              ff.ptr, colnum, typecode, repcnt, width, status)
UNCOV
921
        fits_assert_ok(status[])
!
UNCOV
922
        return Int(typecode[]), Int(repcnt[]), Int(width[])
!
923
    end
924

925
    function fits_get_eqcoltype(ff::FITSFile, colnum::Integer)
926
        typecode = Ref{Cint}(0)
150×
927
        repcnt = Ref{$T}(0)
200×
928
        width = Ref{$T}(0)
200×
929
        status = Ref{Cint}(0)
200×
930
        ccall(($ffeqty,libcfitsio), Cint,
500×
931
              (Ptr{Void}, Cint, Ref{Cint}, Ref{$T}, Ref{$T}, Ref{Cint}),
932
              ff.ptr, colnum, typecode, repcnt, width, status)
933
        fits_assert_ok(status[])
200×
934
        return Int(typecode[]), Int(repcnt[]), Int(width[])
200×
935
    end
936

937
    function fits_get_img_size(f::FITSFile)
938
        ndim = fits_get_img_dim(f)
672×
939
        naxes = Vector{$T}(ndim)
896×
940
        status = Ref{Cint}(0)
896×
941
        ccall(($ffgisz, libcfitsio), Cint,
1,792×
942
              (Ptr{Void}, Cint, Ptr{$T}, Ref{Cint}),
943
              f.ptr, ndim, naxes, status)
944
        fits_assert_ok(status[])
896×
945
        naxes
896×
946
    end
947

948
    function fits_get_num_rows(f::FITSFile)
949
        result = Ref{$T}(0)
132×
950
        status = Ref{Cint}(0)
176×
951
        ccall(($ffgnrw, libcfitsio), Cint,
308×
952
              (Ptr{Void}, Ref{$T}, Ref{Cint}),
953
              f.ptr, result, status)
954
        fits_assert_ok(status[])
176×
955
        return Int(result[])
176×
956
    end
957

958
    # `fits_read_tdim` returns the dimensions of a table column in a
959
    # binary table. Normally this information is given by the TDIMn
960
    # keyword, but if this keyword is not present then this routine
961
    # returns `[r]` with `r` equals to the repeat count in the TFORM
962
    # keyword.
963
    function fits_read_tdim(ff::FITSFile, colnum::Integer)
964
        naxes = Vector{$T}(99)  # 99 is the maximum allowed number of axes
12×
965
        naxis = Ref{Cint}(0)
16×
966
        status = Ref{Cint}(0)
16×
967
        ccall(($ffgtdm,libcfitsio), Cint,
40×
968
              (Ptr{Void}, Cint, Cint, Ref{Cint}, Ptr{$T}, Ref{Cint}),
969
              ff.ptr, colnum, length(naxes), naxis, naxes, status)
970
        fits_assert_ok(status[])
16×
971
        return naxes[1:naxis[]]
16×
972
    end
973

974
    function fits_write_tdim(ff::FITSFile, colnum::Integer,
975
                                 naxes::Array{$T})
976
        status = Ref{Cint}(0)
90×
977
        ccall(($ffptdm, libcfitsio), Cint,
270×
978
              (Ptr{Void}, Cint, Cint, Ptr{$T}, Ref{Cint}),
979
              ff.ptr, colnum, length(naxes), naxes, status)
980
        fits_assert_ok(status[])
120×
981
    end
982

983
    function fits_read_descript(f::FITSFile, colnum::Integer, rownum::Integer)
984
        repeat = Ref{$T}(0)
240×
985
        offset = Ref{$T}(0)
320×
986
        status = Ref{Cint}(0)
320×
987
        ccall(($ffgdes, libcfitsio), Cint,
800×
988
              (Ptr{Void}, Cint, Int64, Ref{$T}, Ref{$T}, Ref{Cint}),
989
              f.ptr, colnum, rownum, repeat, offset, status)
990
        fits_assert_ok(status[])
320×
991
        return Int(repeat[]), Int(offset[])
320×
992
    end
993
end
994

995
"""
996
    fits_read_col(f, colnum, firstrow, firstelem, data)
997

998
Read data from one column of an ASCII/binary table and convert the data into the
999
specified type `T`.
1000

1001
### Arguments ###
1002

1003
* `f::FITSFile`: the file to be read.
1004
* `colnum::Integer`: the column number, where the value of the first column is `1`.
1005
* `firstrow::Integer`: the elements to be read start from this row.
1006
* `firstelem::Integer`: specifies which is the first element to be read, when each
1007
  cell contains more than one element (i.e., the "repetition count" of the field is
1008
  greater than one).
1009
* `data::Array`: at the end of the call, this will be filled with the elements read
1010
  from the column. The length of the array gives the overall number of elements.
1011

1012
### Example ###
1013

1014
```julia
1015

1016
```
1017
"""
1018
function fits_read_col(f::FITSFile,
1019
                       colnum::Integer,
1020
                       firstrow::Integer,
1021
                       firstelem::Integer,
1022
                       data::Array{String})
1023

1024
    # get width: number of characters in each string
1025
    typecode, repcount, width = fits_get_eqcoltype(f, colnum)
18×
1026

1027
    # ensure that data are strings, otherwise cfitsio will try to write
1028
    # formatted strings, which have widths given by fits_get_col_display_width
1029
    # not by the repeat value from fits_get_coltype.
1030
    abs(typecode) == 16 || error("not a string column")
36×
1031

1032
    # create an array of character buffers of the correct width
1033
    buffers = [Vector{UInt8}(width) for i in 1:length(data)]
48×
1034

1035
    # Call the CFITSIO function
1036
    anynull = Ref{Cint}(0)
24×
1037
    status = Ref{Cint}(0)
24×
1038
    ccall((:ffgcvs, libcfitsio), Cint,
78×
1039
          (Ptr{Void}, Cint, Int64, Int64, Int64,
1040
           Ptr{UInt8}, Ptr{Ptr{UInt8}}, Ref{Cint}, Ref{Cint}),
1041
          f.ptr, colnum, firstrow, firstelem, length(data),
1042
          " ", buffers, anynull, status)
1043
    fits_assert_ok(status[])
24×
1044

1045
    # Create strings out of the buffers, terminating at null characters.
1046
    # Note that `String(x)` does not copy the buffer x.
1047
    for i in 1:length(data)
682×
1048
        zeropos = search(buffers[i], 0x00)
640×
1049
        data[i] = (zeropos >= 1) ? String(buffers[i][1:(zeropos-1)]) :
1,606×
1050
                                   String(buffers[i])
1051
    end
1052
end
1053

1054
function fits_read_col{T}(f::FITSFile,
1055
                          colnum::Integer,
1056
                          firstrow::Integer,
1057
                          firstelem::Integer,
1058
                          data::Array{T})
1059
    anynull = Ref{Cint}(0)
234×
1060
    status = Ref{Cint}(0)
312×
1061
    ccall((:ffgcv,libcfitsio), Cint,
1,092×
1062
          (Ptr{Void}, Cint, Cint, Int64, Int64, Int64,
1063
           Ptr{Void}, Ptr{Void}, Ref{Cint}, Ref{Cint}),
1064
          f.ptr, cfitsio_typecode(T), colnum,
1065
          firstrow, firstelem, length(data),
1066
          C_NULL, data, anynull, status)
1067
    fits_assert_ok(status[])
312×
1068
end
1069

1070
"""
1071
    fits_write_col(f, colnum, firstrow, firstelem, data)
1072

1073
Write some data in one column of a ASCII/binary table.
1074

1075
If there is no room for the elements, new rows will be created. (It is therefore
1076
useless to call [`fits_insert_rows`](@ref) if you only need to *append* elements
1077
to the end of a table.)
1078

1079
* `f::FITSFile`: the file in which data will be written.
1080
* `colnum::Integer`: the column number, where the value of the first column is `1`.
1081
* `firstrow::Integer`: the data wil be written from this row onwards.
1082
* `firstelem::Integer`: specifies the position in the row where the first element
1083
  will be written.
1084
* `data::Array`: contains the elements that are to be written to the column of the table.
1085

1086
### Example ###
1087

1088
```julia
1089

1090
```
1091
"""
1092
function fits_write_col(f::FITSFile,
1093
                        colnum::Integer,
1094
                        firstrow::Integer,
1095
                        firstelem::Integer,
1096
                        data::Array{String})
1097
    status = Ref{Cint}(0)
18×
1098
    ccall((:ffpcls, libcfitsio), Cint,
66×
1099
          (Ptr{Void}, Cint, Int64, Int64, Int64,
1100
           Ptr{Ptr{UInt8}}, Ref{Cint}),
1101
          f.ptr, colnum, firstrow, firstelem, length(data),
1102
          data, status)
1103
    fits_assert_ok(status[])
24×
1104
end
1105

1106
function fits_write_col{T}(f::FITSFile,
1107
                           colnum::Integer,
1108
                           firstrow::Integer,
1109
                           firstelem::Integer,
1110
                           data::Array{T})
1111
    status = Ref{Cint}(0)
234×
1112
    ccall((:ffpcl, libcfitsio), Cint,
936×
1113
          (Ptr{Void}, Cint, Cint, Int64, Int64, Int64,
1114
           Ptr{Void}, Ref{Cint}),
1115
          f.ptr, cfitsio_typecode(T), colnum,
1116
          firstrow, firstelem, length(data),
1117
          data, status)
1118
    fits_assert_ok(status[])
312×
1119
end
1120

1121
"""
1122
    fits_insert_rows(f::FITSFile, firstrow::Integer, nrows::Integer)
1123

1124
Insert a number of rows equal to `nrows` after the row number `firstrow`.
1125

1126
The elements in each row are initialized to their default value: you can
1127
modify them later using [`fits_write_col`](@ref).
1128

1129
Since the first row is at position 1, in order to insert rows *before*
1130
the first one `firstrow` must be equal to zero.
1131

1132
### Example ###
1133

1134
```julia
1135

1136
```
1137
"""
1138
function fits_insert_rows end
1139

1140
"""
1141
    fits_delete_rows(f::FITSFile, firstrow::integer, nrows::Integer)
1142

1143
Delete `nrows` rows, starting from the one at position `firstrow`. The index of
1144
the first row is 1.
1145

1146
### Example ###
1147

1148
```julia
1149

1150
```
1151
"""
1152
function fits_delete_rows end
1153
for (a,b) in ((:fits_insert_rows, "ffirow"),
1154
              (:fits_delete_rows, "ffdrow"))
1155
    @eval begin
1156
        function ($a)(f::FITSFile, firstrow::Integer, nrows::Integer)
NEW
1157
            status = Ref{Cint}(0)
!
NEW
1158
            ccall(($b,libcfitsio), Cint,
!
1159
                  (Ptr{Void}, Int64, Int64, Ref{Cint}),
1160
                  f.ptr, firstrow, nrows, status)
NEW
1161
            fits_assert_ok(status[])
!
1162
        end
1163
    end
1164
end
1165

1166
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