github.com/astrogo/cfitsio@v0.1.0/README.md (about)

     1  cfitsio
     2  =======
     3  
     4  [![GitHub release](https://img.shields.io/github/release/astrogo/cfitsio.svg)](https://github.com/astrogo/cfitsio/releases)
     5  [![CI](https://github.com/astrogo/cfitsio/workflows/CI/badge.svg)](https://github.com/astrogo/cfitsio/actions)
     6  [![codecov](https://codecov.io/gh/astrogo/cfitsio/branch/master/graph/badge.svg)](https://codecov.io/gh/astrogo/cfitsio)
     7  [![GoDoc](https://godoc.org/github.com/astrogo/cfitsio?status.svg)](https://godoc.org/github.com/astrogo/cfitsio)
     8  
     9  Naive CGo bindings for ``FITSIO``.
    10  
    11  ## Installation
    12  
    13  ```sh
    14  $ go get github.com/astrogo/cfitsio
    15  ```
    16  
    17  You, of course, need the ``C`` library ``CFITSIO`` installed and available through ``pkg-config``.
    18  
    19  ## Documentation
    20  
    21  http://godoc.org/github.com/astrogo/cfitsio
    22  
    23  ## Example
    24  
    25  ```go
    26  import fits "github.com/astrogo/cfitsio"
    27  
    28  func dumpFitsTable(fname string) {
    29  	f, err := fits.Open(fname, fits.ReadOnly)
    30  	if err != nil {
    31  		panic(err)
    32  	}
    33  	defer f.Close()
    34  
    35  	// get the second HDU
    36  	table := f.HDU(1).(*fits.Table)
    37  	nrows := table.NumRows()
    38      rows, err := table.Read(0, nrows)
    39      if err != nil {
    40          panic(err)
    41      }
    42      defer rows.Close()
    43  	for rows.Next() {
    44          var x, y float64
    45          var id int64
    46          err = rows.Scan(&id, &x, &y)
    47          if err != nil {
    48              panic(err)
    49          }
    50          fmt.Printf(">>> %v %v %v\n", id, x, y)
    51  	}
    52      err = rows.Err()
    53      if err != nil { panic(err) }
    54      
    55      // using a struct
    56      xx := struct{
    57          Id int     `fits:"ID"`
    58          X  float64 `fits:"x"`
    59          Y  float64 `fits:"y"`
    60      }{}
    61      // using a map
    62      yy := make(map[string]interface{})
    63      
    64      rows, err = table.Read(0, nrows)
    65      if err != nil {
    66          panic(err)
    67      }
    68      defer rows.Close()
    69  	for rows.Next() {
    70          err = rows.Scan(&xx)
    71          if err != nil {
    72              panic(err)
    73          }
    74          fmt.Printf(">>> %v\n", xx)
    75  
    76          err = rows.Scan(&yy)
    77          if err != nil {
    78              panic(err)
    79          }
    80          fmt.Printf(">>> %v\n", yy)
    81  	}
    82      err = rows.Err()
    83      if err != nil { panic(err) }
    84      
    85  }
    86  
    87  ```
    88  
    89  ## TODO
    90  
    91  - ``[DONE]`` add support for writing tables from structs
    92  - ``[DONE]`` add support for writing tables from maps
    93  - ``[DONE]`` add support for variable length array
    94  - provide benchmarks _wrt_ ``CFITSIO``
    95  
    96  ## Contribute
    97  
    98  `astrogo/cfitsio` is released under the `BSD-3` license.
    99  Please send a pull request to [astrogo/license](https://github.com/astrogo/license), adding
   100  yourself to the `AUTHORS` and/or `CONTRIBUTORS` files.