;+
; NAME	sqrtimg.pro
;
; PURPOSE	Perform square root scaling on images.
;
; SYNTAX	sqrootimg, list
;
; HISTORY	Andrew L. Stanger   HAO/NCAR   29 November 1999
;-

pro sqrtimg, cme_list

red = bindgen (256)
green = red
blue  = red
cme_name = ''
lct,'/home/stanger/color/bwy.lut'	; color table.
tvlct, red, green, blue, /get

;--- File list loop.

CLOSE, 1
OPENR, 1, cme_list
WHILE (NOT EOF (1)) DO	$
BEGIN	;{

   ;--- Read FITS image header & pixel data.

   READF, 1, cme_name				; Get file name.
print, 'cme_name: ', cme_name
   READ_GIF, cme_name, cme_img			; Read CME image.

   ;--- Extract information from header.

   cme_min = MIN (cme_img, max=cme_max)
   print, FORMAT = '("cme_min/max: ", E10.3, E10.3)', cme_min, cme_max

   ;--- Compute image difference.

   new_img = sqrt (cme_img)				; Compute square root.

   new_min = min (new_img, max=new_max)			; Get image min/max.
   print, FORMAT = '("new_min/max: ", E10.3, E10.3)', new_min, new_max
;   IF (new_min LT 0.0) THEN	$			; Symmetric about zero.
;      IF (-new_min LT new_max) THEN new_min = -new_max  ELSE new_max = -new_min
;   print, FORMAT = '("new_min/max: ", E10.3, E10.3)', new_min, new_max

;   new_min = -5.00e-8
;   new_max =  5.00e-8
;   print, FORMAT = '("new_min/max: ", E10.3, E10.3)', new_min, new_max

   ;--- Convert to byte pixels.
   ;--- Display image.

   byt_img = bytscl (new_img, min=new_min, max=new_max, top=249)
   tv, byt_img						; Display image.

   ;--- Write newference image to disk.

   new_name = "sqrt." + cme_name
   print, 'Write sqrt image : ', new_name
   write_gif, new_name, byt_img, red, green, blue	; Write new image.
END	;}

CLOSE, 1
END
