
; CNA_BIASCORR -- Correct for 16-bit wrap-around effect in a
; NICMOS image. SCI image pixel values below the wrap threshold
; assumed to have wrapped around and are corrected by adding
; +65536 to them to force them positive again. The pixel values
; are modified in-place in the input SCI image. The ERR, DQ, SAMP,
; and TIME images are not modified.

; Revision history:
; I. Barg 10-Jan-2000 Modified structure names (and tag names) to match 
;             "/iraf/stsdas/lib/hstio.h".

function cna_biascorr, nic, input

  ; Arguments:
  ;	nic	 i: NICMOS info structure
  ;	input	io: image to be bias subtracted
  ;

  nwrppix = 0
  wrap_thresh = -23500.0

  idata = input.sci.data.data

  for j = 0,255 do begin
    for i = 0, 255 do begin
      if (idata(i,j) lt wrap_thresh) then begin
	idata(i,j) = idata(i,j) + 65536.0
	nwrppix = nwrppix + 1
      endif
    endfor
  endfor

  input.sci.data.data = idata

  print, 'BIASCORR detected ',nwrppix,' wrapped pixels;'

  ; Successful return 
  return, 0

end

