JuliaAstro / FITSIO.jl

Flexible Image Transport System (FITS) file support for Julia
http://juliaastro.org/FITSIO.jl/
MIT License
55 stars 29 forks source link

New functions to create/read/write tables #4

Closed ziotom78 closed 10 years ago

ziotom78 commented 10 years ago

A set of new functions to deal with ASCII and binary tables. Most of them are thin bindings to CFITSIO, but in a few cases I modified a bit the API:

  1. Instead of one function which creates a table HDU, I implemented two of them: fits_create_ascii_table and fits_create_binary_table. I feel this is much clearer to read. Moreover, using the Tab key from the Julia REPL allows one to easily pick the right function name. This would not have been true if the binding had required to specify some string (like ASCII or BINARY) as its second parameter.
  2. The way columns are specified in a call to fits_create_ascii_table/fits_create_binary_table is through the type ColumnDef. I believe this is significantly easier and less error-prone than CFITSIO's approach of asking three string arrays. See an example here: https://github.com/ziotom78/adafits#differences-from-cfitsio

The Sphinx documentation has been updated accordingly with a section named "Table routines".

nolta commented 10 years ago

Thanks, this looks great! I will suggest one change, which is to define ColumnDef as

typealias ColumnDef (ASCIIString,ASCIIString,ASCIIString)

That way you can write

coldefs = [("SPEED", "1D", "m/s"),
            ("MASS", "1E", "kg"),
            ("PARTICLE", "20A", "Name")]

and you don't need to export ColumnDef.

ziotom78 commented 10 years ago

I must admit that I find quite confusing to use a tuple instead of a struct, as one does not have a way to name the elements in it — for instance, I am always fearing the risk of mistakenly mix up ttype with tform. Moreover, having an explanation of ttype, tform, and tunit in the documentation that was kept separate from the docs offits_create_ascii_table (the place where I have moved this explanation) would have allowed a more elegant way to refer to it from other functions (yet to be implemented) that will refer to ColumnDef, like fits_insert_atbl, fits_insert_btbl, and fits_insert_col.

Anyway, these are minor issues. I've updated the script with the changes suggested. The documentation has been updated as well. (As said above, I needed to change the flow of the text a bit, as now the meaning of ttype, tform, and tunit is explained in the documentation of fits_create_ascii_table.)