FUNCTION NORM_COORD, range

; This function takes a range vector [min, max] as contained
; in the [XYZ]RANGE property of an object and converts it to
; a scaling vector (suitable for the [XYZ]COORD_CONV property)
; that scales the object to fit in the range [0,1].

scale = [-range[0]/(range[1]-range[0]), 1/(range[1]-range[0])]

RETURN, scale

END


pro obj_plot_shartman,Directory=Directory


;set directory path delimiter
    if (!version.os_family eq 'unix') then begin
       delim='/'
    endif else begin
       delim='\'
    endelse

If (not keyword_set(Directory)) then Directory='/a/pippin01/Volumes/u08/lsst/CPanalysis/2005-05-10/ShackHartman/'


myplotmodel=obj_new('IDLgrModel')
;myxaxis=obj_new('IDLgrAxis',0)		;0 is x
;myyaxis=obj_new('IDLgrAxis',1)

;Get the range with the getproperty method from the myplot object
;myplot->Getproperty, XRANGE=xr, YRANGE=yr
;myxaxis->Setproperty, RANGE=xr
;myyaxis->Setproperty, RANGE=yr
;myplot->SetProperty, XCOORD_CONV=500*norm_coord(xr), YCOORD_CONV=500*norm_coord(yr)

myxaxis = OBJ_NEW('IDLgrAxis', 0, RANGE=[100, 800])
;myxaxis -> SetProperty, XCOORD_CONV=500*norm_coord(xr)
myyaxis = OBJ_NEW('IDLgrAxis', 1, RANGE=[100, 800])
;myyaxis -> SetProperty, YCOORD_CONV=500*norm_coord(yr)

;xtl = 0.02 * (xr[1] - xr[0])
;ytl = 0.02 * (yr[1] - yr[0])
;myxaxis -> SetProperty, TICKLEN=xt1
;myyaxis -> SetProperty, TICKLEN=yt1


xaxis_text=obj_new('IDLgrText','X Axis')
yaxis_text=obj_new('IDLgrText','Y Axis')
myfont=obj_new('IDLgrFont','times',size=8)

xaxis_text->Setproperty,font=myfont
yaxis_text->Setproperty,font=myfont
myxaxis->SetProperty,TITLE=xaxis_text
myyaxis->SetProperty,TITLE=yaxis_text

myyaxis->GetProperty, TICKTEXT=xtick_text
myxaxis->GetProperty, TICKTEXT=ytick_text

xtick_text->SetProperty, font=myfont
ytick_text->SetProperty, font=myfont

myplotmodel->add,myxaxis
myplotmodel->add,myyaxis
;myplotmodel->scale,2,2,1

;Now deal with colorbar and its properties
mytitle=obj_new('IDLgrText','My Colorbar') ;create an object of IDLgrText class
bardims=[10,200]
redvalues=BINDGEN(256)
greenvalues=redvalues
bluevalues=reverse(redvalues)
mycolorbar=obj_new('IDLgrColorbar',redvalues,greenvalues,bluevalues,$
        TITLE=mytitle, DIMENSIONS=barDims,/Show_Axis,/Show_outline)
mycolorbarmodel=obj_new('IDLgrModel')

mycolorbarmodel->Add,mycolorbar

;Now set up the Window to show the viewing surface and the group
mygroup=obj_new('IDLgrViewgroup')
myview=obj_new('IDLgrView')
myview->add,myplotmodel
myview->add,mycolorbarmodel
mygroup->add,[myview,xaxis_text,yaxis_text,myfont,mytitle]
mywindow=obj_new('IDLgrWindow',RETAIN=2,GRAPHICS_TREE=mygroup,UNITS=2)
mywindow->Getproperty,Screen_Dimensions=these_dim
print,these_dim
;Now that we have the dimensions of the window, we can figure out 
;where to put the colorbar

;myview->add,mycolorbarmodel
;myview->add,myplotmodel
;myview->add,mycolorbarmodel
;barplustextdims=mycolorbar->ComputeDimensions(mywindow)
;mycolorbarmodel->Translate, -bardims[0]+(barplustextdims[0]/.5), $
;  -bardims[1]+(barplustextdims[1]/2.),0
mycolorbarmodel->Translate,-100,150,1 ;the first is x, second is y
;mycolorbarmodel->scale,2,20,1
; Use the SET_VIEW procedure to add an appropriate viewplane rectangle
; to the view object.
SET_VIEW,myview,mywindow

loadct,31
mysymbols=obj_new('IDLgrSymbol',data=3)

for file_number=1, 100 do begin

if file_number lt 10 then file_name=Directory+'hr5132a_'+string(file_number,format='(I1)')+'_raw.fits.coo.1'
if file_number ge 10 and file_number lt 100 then file_name=Directory+'hr5132a_'+string(file_number,format='(I2)')+'_raw.fits.coo.1'
if file_number ge 100 and file_number lt 1000 then file_name=Directory+'hr5132a_'+string(file_number,format='(I3)')+'_raw.fits.coo.1'

print,file_name


readcol,file_name,x_coord,y_coord,format='f,f',SKIPLINE=42

this_plot='myplot'+file_name
this_plot=obj_new('IdlgrPlot',datax=x_coord,datay=y_coord,color=file_number,linestyle=6,symbol=mysymbols)
myplotmodel->add,this_plot
this_plot->SetProperty, XCOORD_CONV=[0,1], YCOORD_CONV=[0,1]


mywindow->Draw,myview,/draw_instance

endfor

myclipboard=obj_new('IDLgrClipboard',DIMENSIONS=windowsize,GRAPHICS_TREE=mygroup)


myclipboard->Draw,FILENAME='./new_sample1.ps',/postscript

end
