;+
; PROJECT:
;	HESSI
; NAME: 
;	HSI_IPHASE
;
; PURPOSE:
;	This function returns indices needed in the uni modpat phase structure.
;
; CATEGORY:
;	HESSI, UTIL
;
; CALLING SEQUENCE:
;	Bin_index  = hsi_iphase( select, /bin )
;	Coef_index = hsi_iphase( select, /coef)
;
; CALLS:
;	none
;
; INPUTS:
;       Select - Raw indices into the modpat phase structure array, *phase_ptr.
;
; OPTIONAL INPUTS:
;	none
;
; OUTPUTS:
;       none explicit, only through commons;
;
; OPTIONAL OUTPUTS:
;	none
;
; KEYWORDS:
;	One should be supplied.  Default is IBIN set.
;	IBIN - Return the index into the phase structure array.
;	ICOEF - Return the index into the specific element of the IBINned array.
; COMMON BLOCKS:
;	none
;
; SIDE EFFECTS:
;	none
;
; RESTRICTIONS:
;	none
;
; PROCEDURE:
;	The phase_ptr structure array is dimensioned 2 x N, e.g.:
;IDL> help,phz
;PHZ             STRUCT    = -> HSI_ANNSEC_PHASE_STR Array[4096]
;IDL> help,phz,/st
;** Structure HSI_ANNSEC_PHASE_STR, 5 tags, length=36:
;   MAP_INDEX       LONG      Array[2]
;   DPHASE          FLOAT     Array[2]
;   ISUM            LONG      Array[2]
;   WCOEF           FLOAT     Array[2]
;   SCOEF           INT       Array[2]
;
;  When the array is scanned (where) for structures satisfying ISUM eq Itest (0,1,..)
;  a Select array is returned.  To use these indices efficiently in PHZ, two vectors
;  are derived,
;	IBIN  = Select / 2
;	ICOEF = (Select mod 2) * lindgen(nselect) * 2
;  These vectors can be used to extract the needed values from phz corresponding to Select.
;  It is not efficient to first extract all the elements of the pointer.  That takes a 
;  surprising amount of processing time.
;
;
; MODIFICATION HISTORY:
;	Version 1, richard.schwartz@gsfc.nasa.gov, 17-jul-2000.
;
;-
function hsi_iphase, select, IBIN=ibin, ICOEF=icoef

icoef = keyword_set( icoef )
ibin  = 1 - icoef


case 1 of
    ibin: return, select / 2
    else: return, (select mod 2) + lindgen(n_elements(select))*2
    endcase

return, 0
end

