;+
; NAME:
;      NEW_NORMAL_POINT 
; PURPOSE:
;      Generate a new OG#032 (dec) 
; CATEGORY:
;      Yohkoh
; CALLING SEQUENCE:
;      new_normal_point (no arguments)
;      new_normal_point, ogname=['w.751','n1.76'] to force a starting point.
;        This form must be used if the tohbans have not properly archived
;        the current OG#032, in which case the automatic software will
;        start from the wrong coordinates. The "ogname" variable is the
;        two-element name of the currently running OG.
;      new_normal_point, target = [500,  590] (21-Mar-00; the 
;        11-Feb trial position  was [500,592])
; INPUTS:
;      Current absolute coordinates, obtained from OG name
; OPTIONAL (KEYWORD) INPUT PARAMETERS:
;      target, the desired CCD coordinates of sun center (default [520,590])
;      lookback, the number of SFDs in the comparison (default 20)
;      nofile, disables filing the fax message
;      direct, two-element array giving the SXT_CEN input directly, ie
;        bypassing the automatic use of the most recent SFDs
; OUTPUTS:
; COMMON BLOCKS:
; SIDE EFFECTS:
; RESTRICTIONS:
;      hardwired to [520,590] target (see "target" keyword)
; WARNING:
; MODIFICATION HISTORY:
;      19-Nov-1999, written by Hugh Hudson 
;      29-Nov-1999, more documentation (HSH)
;      11-Feb-2000, added assignable target coordinates and fixed
;         yet another Y2K bug (HSH, DMCK)
;       3-Mar-2000, hard-wired new coordinates (HSH)
;      21-Mar-2000, tweaked to [520, 590] because of Feb. 00 problems (HSH)
;      10-Apr-2000, added a keyword for the look-back image number in
;         the SFD reference
;       7-Jun-2000, nofile and direct keywords added 
;-
pro new_normal_point, ogname=ogname, target=target, qdebug=qdebug, test=test, $
  lookback=lookback, nofile=nofile, direct=direct 
;if n_elements(target) eq 0 then target = [520,592]  ; NP prior to 11-Feb-00
;if n_elements(target) eq 0 then target = [500,592]  ; NNP as of 11-Feb-00
if n_elements(target) eq 0 then target = [500,590]   ; NNP as of 21-Mar-00
;
if n_elements(lookback) eq 0 then lookback = 20
;infil = file_list('$DIR_SITE_NEWDATA','sfd*',/cd)
infil = find_file('$DIR_SITE_NEWDATA/sfd*',/nodot)
n_files = n_elements(infil)
file_times = fltarr(n_files)
for i = 0, n_files-1 do begin
  rd_xda,infil(i),0,index
  file_times(i) = anytim(index) 
endfor
ss = sort(file_times)
infil = infil(ss)
rd_roadmap,infil,rm
n_dat = n_elements(rm)
rd_xda,infil,n_dat-21+indgen(lookback),index
if n_elements(direct) eq 0 then begin
  print,' '
  print,'The range of SFDs used to assess the current pointing is:'
  fmt_timer,index
  print,' '
endif
xy = sxt_cen(index)
if n_elements(direct) ne 0 then $
  xy = [[direct(0),direct(1)],[direct(0),direct(1)]]
xsigma = stdev(xy(0,*),xbar)
ysigma = stdev(xy(1,*),ybar)
perror1 = [xbar-target(0), ybar-target(1)]*2.46
perror = [-perror1(1), -perror1(0)]
offset = [-7.14189,1.86672]
if n_elements(test) ne 0 then perror = test 
if n_elements(ogname) eq 0 then ogname = get_ogname()
ogname2euler, ogname, euler
point_hex2,[-0.0458143-euler(0)+(offset(0) + perror(0))/3600,$
  -0.0482259-euler(1)+ (offset(1)+perror(1))/3600],/name,/text
;
print,'The OG name we worked from was: ',ogname
print,'Please be sure that this is the current name of OG#032 (dec).'
print,'The displacements calculated are ', -perror1/2.46,' pixels (EW, NS)',$
  format='(a,f8.2,", ",f8.2,a)'
print,'(positive means S/C to N and W).'
if n_elements(nofile) eq 0 then write_point_archive
if n_elements(direct) eq 0 then begin
  print,' '
  print,'The range of SFDs used to assess the current pointing is:'
  fmt_timer,index
  print,' '
endif
if n_elements(nofile) eq 0 then $
  print,'Now mail the pointing request file to alias "point"'
print,' '
if n_elements(qdebug) then stop
;
end
