#include <stdinc.h>#include <fits.h>int fts_zero(fh)int fts_rhead (fh, instr)int fts_whead (fh, outstr)int fts_rdata(fh, instr, size, buf)int fts_wdata(fh, outstr, size, buf)int fts_rrow(fh, instr, size, buf)int fts_wrow(fh, instr, size, buf)int fts_sdata(fh, instr)int fts_cdata(fh, instr, outstr, trailer)int fts_dsize(fh)int fts_setiblk(factor)int fts_setoblk(factor) stream instr;stream outstr;struct fits_header *fh;char *buf;int size, factor;bool trailer other miscellanious, not yet documented, routines: fts_buf fts_chead, fts_dhead, fts_fhead, fts_ihead, fts_khead, fts_lhead, fts_phead, fts_thead fts_wvar, fts_wvarb, fts_wvarb_a, fts_wvarc, fts_wvarc_a, fts_wvard, fts_wvard_a, fts_wvarf, fts_wvarf_a, fts_wvari, fts_wvari_a ftp_read_img_coord DescriptionThese routines provide a low-level I/O interface to the FITS data structure. For most programs the fitsio(3NEMO) interface will be sufficient; that package however does not call the fits(3NEMO) package but has it’s own I/O routines. The amount of checking and correction/conversion done in the fits(3NEMO) routines makes it a more flexible setup. The amount of work to be done by the application programmer is often however greater. After a file has been opened with stropen, fts_rhead must be called to read in the FITS header information into the struct fits_header *fh; this structure needs to be cleared with fts_zero before reading is attempted. Most essential FITS keywords are placed in this structure, unknown keywords are skipped, although they can be retrieved using the exact binary image of the header, of which there is always an exact memory image available to the application programmer. It is the programmers responsibility to keep track of the position of the file pointer. The FITS headers are always read/written in one call (fts_rhead, fts_whead), but it is possible to either skip the data completely (fts_sdata) or read/write (portions of) the data (fts_rdata, fts_wdata, fts_rrow, fts_wrow). No buffering is done on the fits-I/O routines, since system calls fread(3) and fwrite(3) are used. It is possible to read and write with different FITS blocking factors using fts_setiblk and fts_setoblk. ExampleIt is the programmers responsiblity to read in the data correctly. The following example shows, without any bells, whistles and error checking, how a simple data matrix can be read in: instr = stropen(getparam("in"),"r"); fts_zero(&fh); /* zero the fits header */ fts_rhead(instr,&fh); /* read fits header */ n = fts_dsize(&fh); /* get size of data portion */ if (fh.bitpix == -32) { /* IEEE single precision */ fbuf = (float *) malloc(n/sizeof(float)); /* allocate */ fts_rdata(instr,&fh,fbuf,n); /* read in as single prec. */ } else if (fh.bitpix == -64) { /* IEEE double precision */ dbuf = (double *) malloc(n/sizeof(double)); /* allocate */ fts_rdata(instr,&fh,dbuf,n); /* read in as double precision */ } else error("Cannot handle non-IEEE data format0); /* too bad */
The program scanfits(1NEMO) provides an excellent example how this package can be used. The program ccdfits(1NEMO) is a more common example where fitsio(3NEMO) is sufficient.
~/src/image/fits fits.[ch]
No support for machines whos native format is not floating point IEEE and integer twos complement, although some byte-swapping is supported.
xx-mar-90 created PJT 19-jun-90 more comments PJT 16-mar-91 upgraded plus warnings that fits(3NEMO) should be used PJT 25-jul-91 various blocking factor I/O now done properly PJT 7-aug-92 fixed ctype/ttype reading bugs; more output fts_phead PJT 24-sep-92 fixed more bugs PJT 18-jan-93 added fts_ihead PJT 29-jun-94 added fts_rrow/wrow and keep track of all I/O PJT 7-oct-94 added argument to fts_cdata PJT 23-may-95 added argument to fts_chead and fts_thead PJT 29-sep-01 experimental 64 bitpix, removed some lies PJT