项目作者: jhunkeler

项目描述 :
Split FITS files
高级语言: C
项目地址: git://github.com/jhunkeler/splitfits.git
创建时间: 2020-06-10T05:33:00Z
项目社区:https://github.com/jhunkeler/splitfits

开源协议:BSD 3-Clause "New" or "Revised" License

下载


splitfits

splitfits extracts headers and data from a FITS file. Extracted chunks are written sequentially (*.part_{0,1,2,3,...}). The *.part_map produced by this program during the extraction process can also be used to recombine the exploded file segments.

Why didn’t you use CFITSIO?

CFITSIO is a full-featured library and has quite a few system dependencies. splitfits extracts raw FITS data at logical boundaries within the file. Basic fread() and fwrite() calls are sufficient for this task.

Compiling

With cmake

  1. $ mkdir build
  2. $ cd build
  3. $ cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local
  4. $ make
  5. $ make check
  6. $ make install

Without cmake

  1. $ sed "s/@GIT_VERSION@/$(git describe --always --long --tags)/" version.h.in > version.h
  2. $ cc -o splitfits splitfits.c
  3. $ ./test.sh
  4. $ install -m 755 splitfits /usr/local/bin

Usage

  1. usage: splitfits [-o DIR] [-c] {FILE(s)}
  2. Options:
  3. -h --help This message
  4. -c --combine Reconstruct original file using .part_map data
  5. -o --outdir Path where output files are stored
  6. -V --version Display version

Examples

Splitting a FITS file

  1. $ splitfits sample.fits
  2. Map: ./sample.fits.part_map
  3. Writing: ./sample.part_0
  4. Writing: ./sample.part_1
  5. Writing: ./sample.part_2
  6. Writing: ./sample.part_3

Recombining a FITS file

  1. $ splitfits -c sample.fits.part_map
  2. Map: sample.fits.part_map
  3. Reading: sample.part_0
  4. Reading: sample.part_1
  5. Reading: sample.part_2
  6. Reading: sample.part_3
  7. Writing: ./sample.fits

Realistic example

  1. $ ls -lrSF
  2. total 4816
  3. drwxr-xr-x 2 human human 4096 Jun 16 13:45 split/
  4. drwxr-xr-x 2 human human 4096 Jun 16 13:45 combine/
  5. -rw-r--r-- 1 human human 699840 Jun 16 13:45 sample1.fits
  6. -rw-r--r-- 1 human human 4219200 Jun 16 13:45 sample2.fits
  7. # Split files and store the results in the "split" directory
  8. $ splitfits -o split sample*.fits
  9. Map: split/sample1.fits.part_map
  10. Writing: split/sample1.part_0
  11. Writing: split/sample1.part_1
  12. Writing: split/sample1.part_2
  13. Writing: split/sample1.part_3
  14. Map: split/sample2.fits.part_map
  15. Writing: split/sample2.part_0
  16. Writing: split/sample2.part_1
  17. Writing: split/sample2.part_2
  18. Writing: split/sample2.part_3
  19. # Examine the split data
  20. $ ls -l split/
  21. total 4828
  22. -rw-r--r-- 1 human human 109 Jun 16 13:46 sample1.fits.part_map
  23. -rw-r--r-- 1 human human 23040 Jun 16 13:46 sample1.part_0
  24. -rw-r--r-- 1 human human 642240 Jun 16 13:46 sample1.part_1
  25. -rw-r--r-- 1 human human 28800 Jun 16 13:46 sample1.part_2
  26. -rw-r--r-- 1 human human 5760 Jun 16 13:46 sample1.part_3
  27. -rw-r--r-- 1 human human 114 Jun 16 13:46 sample2.fits.part_map
  28. -rw-r--r-- 1 human human 11520 Jun 16 13:46 sample2.part_0
  29. -rw-r--r-- 1 human human 4196160 Jun 16 13:46 sample2.part_1
  30. -rw-r--r-- 1 human human 8640 Jun 16 13:46 sample2.part_2
  31. -rw-r--r-- 1 human human 2880 Jun 16 13:46 sample2.part_3
  32. # Reconstruct the files using -c and store them in the "combine" directory
  33. $ splitfits -o combine -c split/*.part_map
  34. Map: split/sample1.fits.part_map
  35. Reading: split/sample1.part_0
  36. Reading: split/sample1.part_1
  37. Reading: split/sample1.part_2
  38. Reading: split/sample1.part_3
  39. Writing: combine/sample1.fits
  40. Map: split/sample2.fits.part_map
  41. Reading: split/sample2.part_0
  42. Reading: split/sample2.part_1
  43. Reading: split/sample2.part_2
  44. Reading: split/sample2.part_3
  45. Writing: combine/sample2.fits
  46. # Examine the combined data
  47. $ ls -l combine
  48. total 4808
  49. -rw-r--r-- 1 human human 699840 Jun 16 13:47 sample1.fits
  50. -rw-r--r-- 1 human human 4219200 Jun 16 13:47 sample2.fits
  51. # Check the results
  52. $ (diff sample1.fits combine/sample1.fits && echo SAME) || echo DIFFERENT
  53. SAME
  54. $ (diff sample2.fits combine/sample2.fits && echo SAME) || echo DIFFERENT
  55. SAME

Known issues

“identical begin/end offset”

When the primary header borders an XTENSION header with no data separating them, the loop responsible for setting the next .part_N file generates a zero-length file. This behavior is mitigated by automatically skipping over such segments as they are detected. Do not be alarmed, however, if you observe a gap in the .part_N file names (.part_0, …, .part_2, .part_3). The correct number of files and their names are recorded in the .part_map.