function norp_gt_natti,npa,timej,dtatt

;+
; NAME:
;       NORP_GT_NATTI
;
; PURPOSE:
;       This fucntion is for getting the positions in 'timej'
;       specified by 'npa' with time margin 'dtatt'
;
; CALLING SEQUENCE:
;       natti=norp_gt_natti(npa,timej,dtatt)
;
; INPUTS:
;       npa: 1-dimensional integer array indicating the ATT mode
;       timej: structure array with 'time internal format'.
;       dtatt: 2-dimensional floating array indicating the time mergin
;              before and after the ATT
;
; OPTIONAL INPUT KEYWORDS:
;
; OUTPUTS:
;       natti: the positions in 'timej'
;               specified by 'npa' with time margin 'dtatt'
;
; HISTORY:
;       programmed by T. Kosugi in 1984 May as Fortran program 
;       for old NoRP data format
;       re-programmed by H.Sekiguchi 1987 July - 1988 Dec.
;
;       1995 July,20    N,Shinox for new format NoRP data
;       95.04.19   ed.  add ATT correction for pol data ,correction data type
;                    changed intarr() to fltarr().,
;       95.09.04 Ver.2.0  M. Nishio and K. Hori
;       95.11.10 Ver.3.0  M. Nishio refernce level at 9.4GHz= amb -> zero
;  <<Caution: ambient level at 9.4GHz is incorrect. Use zero as ref. level>>
;       95.12.12 Ver.3.1  M. Nishio and K. Shibasaki (1GHz ATT 7dB -> 4.3)
;       98.09.03          sekix  & shinox   add 80GHz
;       98.11.20  K. Hori
;       1999-1-12 TY unify program for old/new NoRP data
;       2000-4-11 TY make faster
;       2001-5-08 TY bug-fix
;
;-

natt=where((npa-shift(npa,1) ne 0),mattx)
if (mattx ge 1) then begin
  natti=lonarr(2,mattx)

  dt00=timej(1).time-timej(0).time
  dt01=fix(dt00*0.9)
  dt02=fix(dt00*1.1) 
  tmp00=(timej.time-shift(timej.time,1))(1:*) 
  whr1=where(tmp00 gt dt02 or tmp00 lt dt01, count)
 if (count eq 0) then begin ; faster uniform temporal spacing

  dtatt0=dtatt/dt00
  natti(0,*)=natt-dtatt0(0)
; natti(1,*)=natt-dtatt0(1) <-- bug (2001/5/8 fixed)
  natti(1,*)=natt+dtatt0(1)

 endif else begin
  for matt=0,mattx-1 do begin
    tatti_st=timej(natt(matt)).time-dtatt(0)
    natti(0,matt)=norp_t2i(timej.time,tatti_st)
    tatti_ed=timej(natt(matt)).time+dtatt(1)
    natti(1,matt)=norp_t2i(timej.time,tatti_ed)
  endfor
 endelse

endif else natti=-1

return,natti
end
