Viewing contents of file '../idllib/sdss/allpro/display_fchart.pro'


PRO display_fchart, fchart, object, objx, objy, clr, $
      box=box, gif=gif, ps=ps, fnameps=fnameps, $
      fnamegif=fnamegif, silent=silent, nodisplay=nodisplay, $
      hideradec=hideradec, circ_rad=circ_rad, nocirc=nocirc, _extra=extra

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;+
;
; NAME: 
;    DISPLAY_FCHART
;       
; PURPOSE: 
;    display a photo finding chart and circle the object that was used 
;    to make the chart.  Label axis with arcminutes from the center.
;	
;
; CALLING SEQUENCE:  display_fchart, fchart, object, objx, objy, clr, 
;     box=box, gif=gif, ps=ps, fnameps=fnameps, 
;     fnamegif=fnamegif, silent=silent, nodisplay=nodisplay, 
;     hideradec=hideradec,circ_rad=circ_rad, nocirc=nocirc, _extra=extra
;      
;                 
;
; INPUTS: fchart:  The finding chart
;         object:  The photo object used to make the finding chart.
;         objx:    x-position of object in the finding chart.
;         objy:    y-position
;         clr:     color index the finding chart was made from 
;                                          used in the title.
;
; INPUT KEYWORD PARAMETERS:
;         box:  Draw a box instead of a circle.
;         gif:  If set a gif's are output to cwd.
;         ps:   If set a postscript files are created for the requested items.
;         fnameps: name of ps file.  Default is fchart.ps
;         fnamegif: name if gif file.  Default is fchart.gif
;         silent:  If set, program will be silent except for error messages.
;         nodisplay: If set, there will be No x-window display of the chart.  
;               -May still make ps files.-
;         hideradec: Don't show the ra and dec on the plots.
;         circ_rad: radius of circle.
;         nocirc:  if set, no circle is drawn.
;         _extra: any extra plotting command keywords.
;       
; OUTPUTS: 
;
; OPTIONAL OUTPUTS: May output .ps or .gif files if requested.
;
; CALLED ROUTINES:
;
;                  RADECSTR
;                     RADEC
;                  SIGMA_CLIP
;                  BEGPLOT
;                  ENDPLOT
;                  RDIS_SETUP
;                  RDIS:
;                      TVIM2_SCL:
;                               TVIM2
;                  TVCIRCLE
;                  TVBOX
;
;
; REVISION HISTORY: 
;      Author: Erin Scott Sheldon  Umich 5/25/99
;	
;       
;                                      
;-                                       
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


  IF N_params() LT 5 THEN BEGIN 
     print,'-Syntax: display_fchart, fchart, object, objx, objy, clr, box=box, gif=gif, ps=ps, fnameps=fnameps, fnamegif=fnamegif, silent=silent, nodisplay=nodisplay, hideradec=hideradec, circ_rad=circ_rad, nocirc=nocirc, _extra=extra'
     print,''
     print,'Use doc_library,"display_fchart"  for more help.'  
     return
  ENDIF 


  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ; Some initializations
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  IF NOT keyword_set(gif)       THEN gif = 0
  IF NOT keyword_set(ps)        THEN ps=0
  IF NOT keyword_set(fnameps)   THEN fnameps = 'fchart.ps'
  IF NOT keyword_set(fnamegif)  THEN fnamegif = 'fchart.gif'
  IF NOT keyword_set(silent)    THEN silent = 0
  IF NOT keyword_set(nodisplay) THEN nodisplay=0

  IF NOT keyword_set(nocirc) THEN BEGIN
      nocirc = 0
      max = float(!d.n_colors)
      circ_color = 1.*max
  ENDIF

  ;; This is needed to fit all the info on.

  colors=['u','g','r','i','z'] 
 
  tags = tag_names(object)
  run = run2string(object.run)
  
  field = field2string(object.field)
  camcol = strtrim(string(object.camcol),2)
  id = strtrim(string(object.id), 2)

  wrer = where(tags EQ 'RERUN', nwrer)
  IF nwrer NE 0 THEN BEGIN
      rerun='-'+strtrim(string(object[0].(wrer[0])), 2)
  ENDIF ELSE BEGIN
      rerun = ''
  ENDELSE 
  ;; Set up titles
  title=run+'-'+camcol+rerun+'-'+field+'-'+id
  title = title + '   Filter: '+colors[clr]
  IF (NOT keyword_set(hideradec) ) THEN BEGIN 
      radecstr, object.ra, object.dec, rastr, decstr
      title = title + '  ' +rastr+' : ' + decstr
  ENDIF

  ytitle='Offset (arcminutes)'

  c = object.fibercounts
  xtitle=''
  FOR kk=0, 4 DO BEGIN
      IF (xtitle NE '') THEN xtitle = xtitle+'  '
      mag = strmid( strtrim(string(c[kk]),2), 0, 5)
      xtitle = xtitle + colors[kk]+'='+mag
  ENDFOR

  addtitle = ''
  FOR kk=0,3 DO BEGIN
      diff = strmid(strtrim(string(c[kk] - c[kk+1]),2), 0, 5)
      addtitle = addtitle + '  '+colors[kk]+'-'+colors[kk+1]+'='+diff
  ENDFOR
  xtitle = xtitle + addtitle  

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ; Now, draw the circle around our object and then display and save.
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
  ;;;; set appropriate scaling of the circle ;;;;

  ss = size(fchart)
  sx = ss[1]*.4/60.0
  sy = ss[2]*.4/60.0
  IF (NOT keyword_set(circ_rad)) THEN circ_rad = min([ss[1],ss[2]])/20.0

  ;;;; make x and y tick labels
  xlabels = [strmid(strtrim(string(-2*sx/4.0), 2), 0, 4)  , $
             strmid(strtrim(string(-sx/4.0), 2), 0, 4)  , $
             '0.0', $
             strmid(strtrim(string(sx/4.0),2), 0, 4), $
             strmid(strtrim(string(2*sx/4.0),2), 0, 4)]
  ylabels = [strmid(strtrim(string(-2*sy/4.0), 2), 0, 4), $
             strmid(strtrim(string(-sy/4.0), 2), 0, 4), $
             '0.0', $
             strmid(strtrim(string(sy/4.0),2), 0, 4), $
             strmid(strtrim(string(2*sy/4.0),2), 0, 4)]

  pold=!p.multi
  !p.multi=[0,0,1]

  ;; Fchart statistics
  sigma_clip,fchart,mean,sigma,nsig=3.5,niter=2,/silent
  rdis_setup, fchart, pls

  ;; Check variance of image.
  IF (sigma LT 5.0) THEN BEGIN 
      pls.low = mean
      pls.high = mean + 25.
  ENDIF ELSE BEGIN
      pls.low = mean
      pls.high = mean + 10.*sigma
  ENDELSE 

  ;; Postscript output
  IF (ps) THEN BEGIN 
      pcharold = !p.charsize
      !p.charsize=.7
      begplot, name=fnameps
      rdis, fchart, pls, /silent, /noframe, title=title, _extra=extra
      IF (NOT nocirc) THEN BEGIN 
          IF (NOT keyword_set(box) ) THEN $
            tvcircle, circ_rad, objx, objy, circ_color, /data $
          ELSE tvbox, 2*circ_rad, objx, objy, circ_color, /data
      ENDIF
      axis,xaxis=0,xticks=4,xtickn=xlabels, xtitle=xtitle
      axis,xaxis=1,xticks=4,xtickn=[' ',' ',' ',' ',' ']
      axis,yaxis=0,yticks=4,ytickn=ylabels, ytitle=ytitle
      axis,yaxis=1,yticks=4,ytickn=[' ',' ',' ',' ',' ']
      endplot,/noprint
      !p.charsize=pcharold
  ENDIF 

  ;; X window and gif output
  IF (NOT nodisplay) THEN BEGIN 

      rdis, fchart, pls, /silent,/noframe, title=title, _extra=extra
        
      IF (NOT nocirc) THEN BEGIN
          IF (NOT keyword_set(box) ) THEN $
            tvcircle, circ_rad, objx, objy, circ_color, /data $
          ELSE tvbox, 2*circ_rad, objx, objy, circ_color, /data
      ENDIF
      axis,xaxis=0,xticks=4,xtickn=xlabels, xtitle=xtitle
      axis,xaxis=1,xticks=4,xtickn=[' ',' ',' ',' ',' ']
      axis,yaxis=0,yticks=4,ytickn=xlabels, ytitle=ytitle
      axis,yaxis=1,yticks=4,ytickn=[' ',' ',' ',' ',' ']
      IF (gif) THEN BEGIN
          wshow, 0, iconic=0
          write_gif, fnamegif, tvrd()
      ENDIF
  ENDIF 
  !p.multi=pold


return
end