<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi David,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
What Thierry wrote about the BITPIX keyword is correct. It is merely telling you the size needed in storing the pixels in the image file. However CFITSIO provides a function fits_get_img_equivtype described here:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<a href="https://heasarc.gsfc.nasa.gov/docs/software/fitsio/c/c_user/node40.html#ffgidt" id="LPNoLP868737">https://heasarc.gsfc.nasa.gov/docs/software/fitsio/c/c_user/node40.html#ffgidt</a><br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
which will perform the conversion in your example below. That is, it takes into account the BITPIX, BZERO, and BSCALE values and then reports the equivalent type of the array for receiving the data. In your example that would be USHORT_IMG.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
-Craig<br>
</div>
<div id="appendonsend"></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b> THIERRY FORVEILLE <thierry.forveille@univ-grenoble-alpes.fr><br>
<b>Sent:</b> Friday, February 28, 2020 7:08 AM<br>
<b>To:</b> David C. Partridge <david.partridge@perdrix.co.uk><br>
<b>Cc:</b> William Pence <wdpence2000@yahoo.com>; CCFITS Help Desk <ccfits@heasarc.gsfc.nasa.gov>; fitsbits@listmgr.nrao.edu <fitsbits@listmgr.nrao.edu><br>
<b>Subject:</b> Re: [fitsbits] Possible bug in CFITSIO</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText"><br>
> So for clarity:<br>
> <br>
> <br>
> <br>
> Are you saying that if the headers of a 16 bit FITS file say:<br>
> <br>
> <br>
> <br>
> SIMPLE = T / file does conform to FITS standard<br>
> <br>
> BITPIX = 16 / number of bits per data pixel<br>
> <br>
> BZERO = 32768 / offset data range to that of unsigned short<br>
> <br>
> BSCALE = 1 / default scaling factor<br>
> <br>
> <br>
> <br>
> that I should ignore the fact the BITPIX is telling me to use signed short, <br>
><br>
BITPIX is not telling you what to use in your code, just what's stored in the <br>
file. _That_ is signed shorts, but what you convert it to is totally up to you. <br>
I'd use floats (because I'll promptly do things like averaging multiple images,<br>
and those of course step out of the integer space), but you are welcome to use <br>
unsigned shorts if you like, or signed longs, or even complex doubles for the <br>
matter.<br>
</div>
</span></font></div>
</body>
</html>