[ ESO ] [ ST-ECF ]

Science Archive
Stand-alone FITS Tools in ANSI C

Archive Facility HOME ESO HOME

replacekey

Replace cards in a FITS header, without rewriting the whole file.

Sometimes you just want to modify a FITS header because a card is declared wrong, or a value has wrong units, or whatever. Usually, that means going to a FITS processing package, loading the file, using the FITS edition facilities, and create a new file with a correct header around. That is tedious, and might become even more cumbersome if the file you are trying to modify is bulky.

A simple solution is to work in place. If you only want to modify a key, replacekey will do it by modifying the contents of the file's header in place, avoiding to re-write the whole data file at each modification step. Simply provide a character string that corresponds to the beginning of a line in your header, and another character string that provides the line that should replace it.

Example: your header looks like the following, and you want to modify the value of MYVALUE to set it to 32 instead of -1.

% dfits myfile.fits
====> file myfile.fits <====
SIMPLE  =                    T / Standard FITS format (NOST-100.0)
BITPIX  =                  -32 / Bits per pixel
NAXIS   =                    2 / Number of dimensions
NAXIS1  =                  901 / Pixels per row
NAXIS2  =                  513 / Pixels per col
MYVALUE =                   -1 /
END

Use replacekey by providing the name of the keyword you want to modify, but actually any character string will do as soon as it is on the beginning of a line. The first matching entry will be taken.

% replacekey myfile.fits "MYVALUE =                   32 /" "MYVALUE" 
%dfits myfile.fits
====> file myfile.fits <====
SIMPLE  =                    T / Standard FITS format (NOST-100.0)
BITPIX  =                  -32 / Bits per pixel
NAXIS   =                    2 / Number of dimensions
NAXIS1  =                  901 / Pixels per row
NAXIS2  =                  513 / Pixels per col
MYVALUE =                   32 /
END

replacekey was initially aimed at placing information in FITS headers where placeholders have been reserved. If during your processing you take care of leaving placeholders in the output FITS headers (something like the default COMMENT PLACEHOLDER), you can always add up new entries in the header by using replacekey. This is very useful if you want for example, to decouple the program doing processing on the pixels, from the program that has to update the output headers with correct entries in the header.

Download replacekey.c


 [ESO Web Site]  [Search]  [Help]  [News]