pro tilenames,source,ntile,tilecr,tilecd,tnames,obj=obj
; This routine produces names for the tiles described in its argument list.
; source=0 -> target stars, source=1 or 2 -> standard stars, hence only one
; file.
; ntile=number of tiles for which names are needed
; tilecr,tilecd = integer degrees of ra, dec for each tile
; tnames = strarr(ntile) = root names of files corresp to each tile
; If keyword obj is set, then 'o' is prepended to each tile name,
; to give "observation" tile names.

if(source eq 1 or source eq 2) then begin
  tnames=strarr(ntile)
  for i=0L,ntile-1 do begin
    tnames(i)='tstds'
    if(keyword_set(obj)) then tnames(i)='tostds'
  endfor
endif

f1='(i3)'
if(source eq 0) then begin
  tnames=strarr(ntile)
  if(keyword_set(obj)) then pre='to' else pre='t'
  for i=0L,ntile-1 do begin
    s1=byte(string(tilecr(i),format=f1))
    s=where(s1 eq 32,ns)
    if(ns gt 0) then s1(s)=48
    s1=string(s1)
    if(tilecd(i) lt 0) then u=abs(tilecd(i)+1) else u=tilecd(i)
    s2=byte(string(u,format=f1))
    s=where(s2 eq 32,ns)
    if(ns gt 0) then s2(s)=48
    s2=string(s2)
    if(tilecd(i) lt 0.) then mc='-' else mc='+'
    tnames(i)=pre+s1+mc+s2
  endfor
endif

end