
; CNA_CKIMGSIZE -- Check the size of all images in a group to make sure that
; they're the right size for a NICMOS image.

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

function cna_ckImgSize, in

@calnica_common

  ; Arguments:
  ;	in	i: input image group (SingleNicmosGroup)

  status = 0

  ; Check the science image size.
  if (in.sci.data.tot_nx ne SZ_NICIMG or $
      in.sci.data.tot_ny ne SZ_NICIMG) then begin
      print, in.filename,' SCI image not correct size.', $
	in.sci.data.tot_nx,in.sci.data.tot_ny
      status = 1
  endif

  ; Check the error image size.
  if (in.err.data.tot_nx ne SZ_NICIMG or $
      in.err.data.tot_ny ne SZ_NICIMG) then begin
      print, in.filename,' ERR image not correct size.'
      status = 1
  endif

  ; Check the data quality image size.
  if (in.dq.data.tot_nx ne SZ_NICIMG or $
      in.dq.data.tot_ny ne SZ_NICIMG) then begin
      print, in.filename,' DQ image not correct size.'
      status = 1
  endif

  ; Check the number of samples image size.
  if (in.smpl.data.tot_nx ne SZ_NICIMG or $
      in.smpl.data.tot_ny ne SZ_NICIMG) then begin
      print, in.filename,' SAMP image not correct size.'
      status = 1
  endif

  ; Check the integration time image size.
  if (in.intg.data.tot_nx ne SZ_NICIMG or $
      in.intg.data.tot_ny ne SZ_NICIMG) then begin
      print, in.filename,' INTGTIME image not correct size.'
      status = 1
  endif

  return, status
  
end


; CNA_GETRAWDATA -- Read raw data from input file. One group is read.

function cna_getRawData, nic, in, infcb, infname

  ; Arguments:
  ;     nic       i: NICMOS info structure
  ;     in        o: input image data (either a SingleNicmosGroup or MultiNicmosGroup)
  ;     infcb     i: input FITS Control Block (file opened in calnica.pro)
  ;     infname   i: input FITS file name

  ; Initialize the input data structure.
  ; initMultiNicmosGroup (in);

  ; Allocate the group data structures.
  ; if (allocMultiNicmosGroup (in, nic.ngroups) ne 0) then begin
  ;   return, 1
  ; endif

  status = 0

  ; Read the input data groups.
  if (nic.ngroups eq 1) then begin
    if (getSingleNicmosGroup (infname,1,in) ne 0) then begin
      status = 1
    endif
    ; Check the image sizes.
    if (cna_ckImgSize (in) ne 0) then begin
     return, 8
    endif
    status = cna_getGroupInfo(nic,in)
  endif else begin
    for i = 1, nic.ngroups do begin
      nic.group = i

      ngroup = in.group[i-1]
      if (getSingleNicmosGroup (infname,i,ngroup) ne 0) then begin
        status = 1
      endif

      ; Check the image sizes.
      if (cna_ckImgSize (ngroup) ne 0) then begin
        return, 8
      endif
      in.group[i-1] = ngroup
      status = cna_getGroupInfo(nic,in.group[i-1])
    endfor
  endelse

  return, status

end
