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