
; CNA_MACHECK -- Check MultiACCUM groups for decreasing counts..

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

pro cna_macheck, nic, input

@calnica_common

; Arguments:
;  nic    i: NICMOS image info structure
;  input  i: array of NICMOS structures (MultiNicmosGroup).

  macheck_thresh = 3.0

  ; Loop over groups.
  for k=0,nic.ngroups-2 do begin

    ; Initialize counter for this group.
    nlow = 0

    testdat1 = input.group[k].sci.data.data
    testdat2 = input.group[k+1].sci.data.data
    maskdq1 = cna_pixok(input.group[k].dq.data.data)
    maskdq2 = cna_pixok(input.group[k+1].dq.data.data)

    ; Pixels with grot or zerosig flags set are OK.
    ; The mask must reflect this.
    errs = input.group[k].err.data.data
    datamask = testdat1 lt (testdat2 - errs * macheck_thresh)
    tmp = where(datamask and (maskdq1 and maskdq2), nlow)

    ; Report the number of pixels with decreasing countrate.
    if (nlow gt 0) then begin
      print, ' Imset ',k+1,' has ',nlow, $
	     ' pixels with lower countrate than imset ',k+2
    endif
  endfor

end

