How to make a simple, 16-bit integer FITS file Michael Richmond Nov 27, 1996 Here's the prescription for making a minimal FITS file. I hope that it gives enough of the details for you to implement it. 1. The file must be a multiple of 2880 bytes long. If necessary, pad with NULLs at the end of the file. 2. The first 2880 bytes are called the "header". This header is arranged (conceptually) into 36 lines, each of which is 80 characters long. The kicker is that there are NO end-of-line characters, just spaces. Thus, character 80 might be a space, and character 81 might be a 'E' and 82 'N' and 83 'D' if the keyword in (conceptual) line 2 of the were to be "END". If you want to store more than 36 header lines, just extend the header to another multiple of 36 lines, and make sure that the data starts at the next 2880-byte boundary after the last header line. 3. The basic form of lines in the header is KEYWORD = value where "KEYWORD" must be <= 8 characters long, starting in (conceptual) position 1, the equals sign must be in (conceptual) position 9, and value can be a number: GAIN = 12 EXPTIME = 100.3 CAMTEMP = -23.3e+00 a string: OBJECT = 'Ring Nebula' OBSERVER= 'Richmond' a 'T' or 'F': SIMPLE = T REDUCED = F Comments can be placed after the "value", separated from the value by a slash character: OBJECT = 'Ring' / aka M57 4. One can make a whole line a comment by using the special COMMENT keyword, which requires no equals sign or value, like so: COMMENT This is a comment line COMMENT You can start here COMMENT or have plenty of spaces 5. The last (conceptual) line of the header must be END 6. The typical minimal header gives just enough information to allow someone to decode it: it tells the data type, and the number of rows and columns in the image. For 16-bit signed integers, which are pretty widely used, the minimal header of a 200x100 image would look like this: SIMPLE = T / this must be the first line BITPIX = 16 / 16-bit signed integers NAXIS = 2 / a 2-d image NAXIS1 = 100 / 100 columns of data NAXIS2 = 200 / 200 rows of data END 7. Okay, that was the header. Now, starting with the 2881'th byte in the file, you put the data. Use 2 bytes per pixel, placing the high-order byte first. Thus, if the first pixel value in the first row is 259, then byte 2881 = 0x01 byte 2882 = 0x03 Just keep writing row after row, placing data values one after the other. Don't skip any space at the end of a row; begin placing the value from the first column in the next row immediately afterwards. 8. When done with all the data, write out enough NULLs (zeros) to pad the length of the entire file to a multiple of 2880 bytes. There! You're done. The tricky part is remembering NOT to place an end-of-line character at the end of each (conceptual) line of the header. For the REAL definition of FITS, read the FITS archive at NRAO: http://fits.cv.nrao.edu/www/fits.html