home *** CD-ROM | disk | FTP | other *** search
/ DTP Toolbox / DTPToolbox.iso / utilities / propage_pdraw / donsgenies / adproscripts.lha / FITSload.adpro < prev    next >
Encoding:
Text File  |  1995-08-13  |  3.7 KB  |  134 lines

  1. /* Program to load FITS image files - an astronomers' format.
  2. 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. 
  3. Best to do Crop Visual, followed by Dynamic Range. 
  4. Written by Don Cox, Feb. 94 Bug fix, Aug 95.  Copyright. */
  5.  
  6. /* $VER:FITSload Aug 95 */
  7. /*call open("STDERR","ram:traceFL","W")
  8. trace r*/
  9.  
  10. options results
  11. numeric digits 14
  12.  
  13. /* Screen type definitions - do not alter */
  14. hires = 1
  15. interlace = 2
  16. pal = 4  /* NTSC if off */
  17. hoverscan = 8
  18. voverscan = 16
  19. vga = 32
  20. superhires = 64
  21. super72 = 128
  22. default = 256
  23.  
  24.  
  25. address "ADPro"
  26.  
  27. lformat "SCULPT" /* loads raw data */
  28. sformat "IFF"
  29.  
  30. render_type
  31. colours = ADPro_result
  32. screen_type
  33. stype = ADPro_result
  34. gamma
  35. gammasetting = ADPro_result
  36.  
  37. imagewidth = 512 /* defaults */
  38. imageheight = 512
  39. bitpix = 16
  40.  
  41. getfile '"Select file to load..."' "df0:"
  42. if rc~=0 then do
  43.     okay1 "No file selected"
  44.     exit
  45.     end
  46.  
  47. filename = ADPro_result
  48. justname = getname(filename)
  49.  
  50. getdir '"Select directory for output files"'
  51. if rc=10 then exit
  52. directory = ADPro_Result
  53. filestring1 = "/"justname".text"
  54. filestring2 = "/FITS.temp.raw"
  55. filestring3 = "/"justname".ilbm"
  56. if right(directory,1)=":" then filestring1 = justname".text"
  57. if right(directory,1)=":" then filestring2 = "FITS.temp.raw"
  58. if right(directory,1)=":" then filestring3 = justname".ilbm"
  59. tempfile1 = directory||filestring1
  60. tempfile2 = directory||filestring2
  61. tempfile3 = directory||filestring3
  62.  
  63. call open(input,filename,"r")
  64. call open(output1,tempfile1,"w")
  65. call open(output2,tempfile2,"w")
  66.  
  67. /* Read in the text header */
  68. do i = 1 to 200  /* safety limit */
  69.     inline = readch(input,80)
  70.     if inline = "" then break
  71.     inline = inline||"0a"x
  72.     success = writech(output1,inline)
  73.     if upper(word(inline,1))="END" then break
  74.     if upper(word(inline,1)) = "BITPIX" then do
  75.         epos = pos("=",inline)
  76.         inline = substr(inline,epos+1)
  77.         bitpix = word(inline,1) /* bits per pixel */
  78.         end
  79.     if upper(word(inline,1)) = "NAXIS1" then do
  80.         epos = pos("=",inline)
  81.         inline = substr(inline,epos+1)
  82.         naxis1 = word(inline,1) /* image width */
  83.         end
  84.     if upper(word(inline,1)) = "NAXIS2" then do
  85.         epos = pos("=",inline)
  86.         inline = substr(inline,epos+1)
  87.         naxis2 = word(inline,1) /* image height */
  88.         end
  89.     end
  90. call close(output1)
  91.  
  92. bytepix = bitpix/8  /* bytes per pixel */
  93.  
  94. /* deal with blank lines full of spaces in header after "END" line */
  95. do until eof(input)
  96.     inline = readch(input,8)
  97.     if inline ~="2020202020202020"x then break /* look for end of block of spaces */
  98.     end
  99. inline = strip(inline,'L') /* allow for odd spaces at end */
  100. inlinelength = length(inline) /* usually zero */
  101.  
  102. bytelength = bytepix*naxis1 /* length of a line in bytes */
  103. linelength = bytelength-inlinelength
  104. inline2 = readch(input,linelength)
  105. inline = inline||inline2  /* make up first line from shortened read plus any odd bits */
  106. success = writech(output2,inline)
  107.  
  108. linelength = bytelength
  109. do i = 2 to naxis2 
  110.     inline = readch(input,linelength)
  111.     if inline = "" then break
  112.     success = writech(output2,inline)
  113.     end
  114. call close(output2)
  115.  
  116. /* 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 */
  117. ORIENTATION LANDSCAPE
  118. LOAD '"'tempfile2'"' linelength naxis2 "GRAY"
  119. OPERATOR "DEINTERLACE"
  120. SAVE '"'tempfile3'"' "RAW"
  121. EXECUTE
  122. ADPRO_DISPLAY
  123.  
  124. exit
  125. end
  126.  
  127. /* +++++++++++++++++++++++++++++++++++  ++++++++++++++++++++++++++++++ */
  128.  
  129. getname:
  130. arg allname
  131. pos1 = lastpos("/",allname)
  132. if pos1 = 0 then pos1 = lastpos(":",allname)
  133. justname = substr(allname,pos1+1)
  134. return justname