;                      GS_WHEN.pro
;+
;  Routine for noting the time from a greyscale image.
;
;  Click mouse button to get time of corresponding spectrum
;  End by clicking at same place twice in succession.
;
;
;  Use:
;          IDL>  .run gs              display data
;          IDL>  .run gs_when         time output each button click
;                                     enter same place twice running to end
;
;  To switch off display of time on screen, set GS_WHEN_DISP = 0
;  or to switch ON set it to 1.
;
;   
;    v1.0         Feb 92 CDP
;    v1.1         make time calculation non-VMS specific
;    v1.2         use yds3 instead of yds1                   Mar 92   
;    v2.0         rewrite using fmt_tim                      Mar 92
;                 introduce switch off off on-display time o/p
;-
if n_elements(gs_cur_flag) eq 0 then gs_cur_flag = 1
if n_elements(gs_when_disp) eq 0 then gs_when_disp = 1
   
ydslast = 0
Print,' '
Print,' A time is given for every button click,'
Print,' click twice in same place to end:'
Print, ' '
wset,0
;
;  set up blanking array
;
gs_xx = bytarr(80,12)
gs_xx(*,*) = 0
;
;  loop until same place entered twice
;
for i=0,100 do begin

   cursor,xdum,ydum,3,/dev
   yds3 = ydum
   if yds3 eq ydslast then goto, fin
   ydslast = yds3
;
;  correct for display offset
;
   yds3 = yds3 - gs_off(1) - 1
;
   ndim = size(gsa)
   if yds3 lt 0 then yds3 = 0
   if yds3 gt ndim(2) then yds3 = ndim(2)
;
;  report back
;
   print,fmt_tim(index(yds3))
   if gs_when_disp eq 1 then begin
      tvscl,gs_xx,xdum,ydum-2
      xyouts,xdum,ydum,'____'+strmid(fmt_tim(index(yds3)),10,9),/dev
   endif
endfor
fin:

end
