/* Program to load FITS image files - an astronomers' format.
FITS images are 16-bit and this splits the image into 2 8-bit images. The resulting image is in two halves: the top half (which will look like noise) is the LSBs and the bottom half is the MSBs.
Best to do Crop Visual, followed by Dynamic Range.
Written by Don Cox, Feb. 94 Bug fix, Aug 95. Copyright. */
/* $VER:FITSload Aug 95 */
/*call open("STDERR","ram:traceFL","W")
trace r*/
options results
numeric digits 14
/* Screen type definitions - do not alter */
hires = 1
interlace = 2
pal = 4 /* NTSC if off */
hoverscan = 8
voverscan = 16
vga = 32
superhires = 64
super72 = 128
default = 256
address "ADPro"
lformat "SCULPT" /* loads raw data */
sformat "IFF"
render_type
colours = ADPro_result
screen_type
stype = ADPro_result
gamma
gammasetting = ADPro_result
imagewidth = 512 /* defaults */
imageheight = 512
bitpix = 16
getfile '"Select file to load..."' "df0:"
if rc~=0 then do
okay1 "No file selected"
exit
end
filename = ADPro_result
justname = getname(filename)
getdir '"Select directory for output files"'
if rc=10 then exit
directory = ADPro_Result
filestring1 = "/"justname".text"
filestring2 = "/FITS.temp.raw"
filestring3 = "/"justname".ilbm"
if right(directory,1)=":" then filestring1 = justname".text"
if right(directory,1)=":" then filestring2 = "FITS.temp.raw"
if right(directory,1)=":" then filestring3 = justname".ilbm"
tempfile1 = directory||filestring1
tempfile2 = directory||filestring2
tempfile3 = directory||filestring3
call open(input,filename,"r")
call open(output1,tempfile1,"w")
call open(output2,tempfile2,"w")
/* Read in the text header */
do i = 1 to 200 /* safety limit */
inline = readch(input,80)
if inline = "" then break
inline = inline||"0a"x
success = writech(output1,inline)
if upper(word(inline,1))="END" then break
if upper(word(inline,1)) = "BITPIX" then do
epos = pos("=",inline)
inline = substr(inline,epos+1)
bitpix = word(inline,1) /* bits per pixel */
end
if upper(word(inline,1)) = "NAXIS1" then do
epos = pos("=",inline)
inline = substr(inline,epos+1)
naxis1 = word(inline,1) /* image width */
end
if upper(word(inline,1)) = "NAXIS2" then do
epos = pos("=",inline)
inline = substr(inline,epos+1)
naxis2 = word(inline,1) /* image height */
end
end
call close(output1)
bytepix = bitpix/8 /* bytes per pixel */
/* deal with blank lines full of spaces in header after "END" line */
do until eof(input)
inline = readch(input,8)
if inline ~="2020202020202020"x then break /* look for end of block of spaces */
end
inline = strip(inline,'L') /* allow for odd spaces at end */
inlinelength = length(inline) /* usually zero */
bytelength = bytepix*naxis1 /* length of a line in bytes */
linelength = bytelength-inlinelength
inline2 = readch(input,linelength)
inline = inline||inline2 /* make up first line from shortened read plus any odd bits */
success = writech(output2,inline)
linelength = bytelength
do i = 2 to naxis2
inline = readch(input,linelength)
if inline = "" then break
success = writech(output2,inline)
end
call close(output2)
/* The trick is to load in a 2-bytes-per-pixel image in sideways, and then use de-interlace to separate the odd and even bytes (rows), giving 2 images */