func solarbxy(tai, sunx, suny)
 ;7/1/2007 - this may not be used anymore since we now have planned
 ;pointing in the quicklook reformatted files
 ;we assume the pointing array is in a global $solarbpnts
 sunx = 0	suny = 0
 if defined($solarbpnts) eq 0 then {
    ;try to read in
    $solarbpntfname = getenv('ANA_SOLARB_PFILE')
    if num_elem($solarbpntfname) le 1 then {
       ;avoid popping this error more than once
       if defined(errorflag) eq 0 then 
          errormess,'the environmental ANA_SOLARB_PFILE\nis not defined'
       errorflag = 1
       ;but still print it
       ty,'the environmental ANA_SOLARB_PFILE is not defined'
       return
    }
    fzread, $solarbpnts, $solarbpntfname
    $solarbpntssize = filesize($solarbpntfname)
    if isarray($solarbpnts) eq 0 then { ty,'no pointing data available'  return, 0 }
 }
 if dimen($solarbpnts,0) ne 7 then { ty,'$solarbpnts array not valid'  return, 0 }
 if defined($solarbpnttimes) eq 0 then $solarbpnttimes = $solarbpnts(0,*)
 ;if we have a previous result, check if the range is still valid
 if defined($solarbpntsindex) then {
   if tai ge $solarbpnttimes($solarbpntsindex) and tai le $solarbpnttimes($solarbpntsindex+1) then
     iq = $solarbpntsindex else iq = 0 } else  iq = 0
 ;if iq is 0, we have to find tai in $solarbpnttimes
 while (1) {
   if iq le 0 then iq = bsearch($solarbpnttimes, tai)
   if iq ge 0 and iq lt num_elem($solarbpnttimes) then break	;done
     ;check if we may have newer (larger) file
   if filesize($solarbpntfname) gt $solarbpntssize then {
     fzread, $solarbpnts, $solarbpntfname
     $solarbpnttimes = $solarbpnts(0,*)
     $solarbpntssize = filesize($solarbpntfname)
     if isarray($solarbpnts) eq 0 then { ty,'problem with new pointing file?'  return, 0 }
   } else { ty,'pointing time out of range'  return, 0 }
 }
 $solarbpntsindex = iq
 ;iq is the nearest previous time, we rotate on the sun for any elapsed time
 ;and apply the offset
 tref = $solarbpnts(1,iq)
 if tref ne 0 then {
   dt = tai - tref
   ;rotate the longitude according to time and rate
   longt = $solarbpnts(2,iq) + dt * $solarbpnts(4,iq)
   b = sun_b_tai(tai) * #d2r
   r = sun_r_tai(tai)
   lat = $solarbpnts(3,iq) * #d2r
   longt = longt * #d2r
   sunx=r*cos(lat)*sin(longt)
   suny=0.5*r*(sin(lat-b)*(1.+cos(longt))+sin(lat+b)*(1.-cos(longt)))
 }
 ;and add the offsets
 sunx = sunx -  $solarbpnts(6,iq)*3600.
 suny = suny -  $solarbpnts(5,iq)*3600.
 return, 1
 endfunc
 ;=================================================================
