;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Lance Simms, Stanford University 2009
;function return_pixel_masks
;
;PURPOSE:
;	To return arrays that hold the pixel masks
;KEYWORDS:
;	STANDALONE:
;	0-the function was called from an external program where the 
;	  common block of KeyParams was already initialized
;	1-the function is being called from the command line, so the
;	  common block of KeyParams will be initialized within the function
;
;OUTPUTS:
;	Masks - A structure with the following fields
;	 Masks.DeadMask    - The mask containing the values of the dead pixels
;	 Masks.DeadInd     - The indices of the dead pixels
;	 Masks.DeadNum     - The number of dead pixels
;	 Masks.LeakyMask   - The mask showing the locations of the leaky pixels
;	 Masks.LeakyInd    - The indices of the leaky pixels
;	 Masks.LeakyNum    - The number of Leaky Pixels
;	 Masks.LeakyNNMask - The mask of leaky pixels and nearest neighbors
;	 Masks.LeakyNNInd  - The indices of leaky pixels and nearest neighbors
;	 Masks.LeakyNNNum  - The number of Leaky Pixels and nearest neighbors
;        Masks.HotMask     - The mask containing the values of the hot pixels
;        Masks.HotInd      - The indices of the hot pixels
;        Masks.HotNum      - The number of hot pixels
;	 Masks.GoodPixels  - The indices of the pixels that look good for use
function return_pixel_masks_xrg, StandAlone=StandAlone

  Common KeyParams, KeyStr

  ;Get the DEAD pixels
  Fits_Read, KeyStr.MasterDeadMapPath, DeadMask, DeadHeader
  DeadInd = where(DeadMask eq 1, DeadNum)

  ;Get the LEAKY pixels
  Fits_Read, KeyStr.MasterLeakyMapPath, LeakyMask, LeakyHeader
  ;Make sure they're not dead
  LeakyAndDead = LeakyMask and DeadMask
  LeakyAndDeadLocs = where(LeakyAndDead eq 1)
  if LeakyAndDeadLocs(0) ne -1 then LeakyMask(where(LeakyAndDead eq 1)) = 0
  LeakyInd   = where(LeakyMask eq 1, LeakyNum)

  ;Form the structure that will be returned
  Masks = { $
	DeadMask    : DeadMask, $
	DeadInd     : DeadInd, $
	DeadNum     : DeadNum, $
        LeakyMask   : LeakyMask, $
	LeakyInd    : LeakyInd, $
	LeakyNum    : LeakyNum $
	}

  return, Masks

end
