PRO tvnplot, image, MIN = min, MAX = max, GAMMA = gamma, MSK = msk, ERASE = erase, $ ibase = ibase, jbase = jbase, INTERP = interp, $ SCALE_X = scale_x, SCALE_Y = scale_y, PS = ps, _EXTRA = extra IF keyword_set(min) EQ 0 THEN min = min(image) IF keyword_set(max) EQ 0 THEN max = max(image) IF keyword_set(scale_x) EQ 0 THEN scale_x = 1. IF keyword_set(scale_y) EQ 0 THEN scale_y = 1. IF keyword_set(ibase) EQ 0 THEN ibase = 0. IF keyword_set(jbase) EQ 0 THEN jbase = 0. sample = 0 IF keyword_set(interp) EQ 0 THEN sample = 1 x_env_save = !x y_env_save = !y p_env_save = !p !p.background = 255 !p.color = 0 !p.charsize=1 image = reform(image) IF (size(image))[0] NE 2 THEN BEGIN print, ' tvnplot needs a 2D array' stop ENDIF ni = (size(image))[1] nj = (size(image))[2] IF keyword_set(gamma) EQ 0 THEN BEGIN gamma = 600/max([ni, nj]) ENDIF IF n_elements(ps) EQ 1 THEN BEGIN gamma = 5 ENDIF image2 = ((min > image < max) -min)*(!d.n_colors-2)/(max-min)+1 IF n_elements(msk) NE 0 THEN BEGIN image2(where(msk EQ 0)) = 0 ENDIF image2 = rebin(image2, gamma*ni, gamma*nj, sample = sample) IF n_elements(ps) EQ 0 THEN BEGIN xsize = ni*gamma+200 ysize = nj*gamma+200 IF (!d.x_size LT xsize) OR (!d.y_size LT ysize) THEN $ window, xsize = ni*gamma+200, ysize = nj*gamma+200 xcmperpix = 1. ycmperpix = 1. ENDIF ELSE BEGIN set_plot, 'ps' device, xsize = 19, ysize = 20, xoffset = 1, yoffset = 1, bits = 8, /color device, xsize = 25, ysize = 19, xoffset = 1, yoffset = 28, bits = 8, /color, /land xcmperpix = !d.X_PX_CM/50. ycmperpix = !d.y_PX_CM/50. print, xcmperpix, ycmperpix ENDELSE xsize = gamma*ni*xcmperpix ysize = gamma*nj*ycmperpix x0 = (!d.x_size-xsize)/2. ; coordonnees de l''image y0 = (!d.y_size-ysize)/2. ; x1 = x0/!d.x_size y1 = y0/!d.y_size !x.range = ibase+[0, ni*scale_x] !y.range = jbase+[0, nj*scale_y] !x.style = 1 !y.style = 1 !p.position = [x1, y1, 1-x1, 1-y1] ; position du cadre subtitle = 'MIN='+string(min)+' / MAX='+string(max) IF keyword_set(erase) NE 0 THEN erase, 255 tv, image2, x0, y0, xsize = xsize, ysize = ysize, _extra = extra plot, !x.crange, !y.crange, subtitle = subtitle, /nodata, /noerase, $ xticklen = 1, yticklen = 1, color = 0, _extra = extra ; cadre x0 = !x.window(0) y0 = !y.window(0) dx = !x.window(1)-!x.window(0) dy = !y.window(1)-!y.window(0) deltax = (!x.window[1]-!x.window[0]) deltay = (!y.window[1]-!y.window[0]) x00 = !x.window[1] y00 = !y.window[0] colorbar,/vert,color=0,bottom = 1, $ min=min,max=max,$ divisions=10, /right, $ position =[x00+deltax*0.01,y00+deltay*0.1,x00+deltax*0.04,y00+deltay*0.9] IF n_elements(ps) EQ 0 THEN BEGIN print, 'button 1 = value / button 2 = zoom / button 3 = exit' REPEAT BEGIN cursor,x,y,/normal, /down button = !mouse.button i=0 > floor(ni*(x-x0)/dx) < (ni-1) j=0 > floor(nj*(y-y0)/dy) < (nj-1) CASE button OF 1: BEGIN print, 'i=', i+ibase, ' / j=', j+jbase, ' / z(i,j)=', image(i, j) wait, .2 END 2: BEGIN i0 = i j0 = j cursor,x,y,/normal, /down i1=0 > floor(ni*(x-x0)/dx) < (ni-1) j1=0 > floor(nj*(y-y0)/dy) < (nj-1) IF i1 LE i0 THEN i1 = (i0+10) < (ni-1) IF j1 LE j0 THEN j1 = (j0+10) < (nj-1) tvnplot, image(i0:i1, j0:j1), _extra = extra, /erase, $ ibase = i0+ibase, jbase = j0+jbase, MIN = min, Max = max END 4: return ELSE: ENDCASE ENDREP UNTIL (button EQ 4) ENDIF x_env_save = !x y_env_save = !y p_env_save = !p IF n_elements(ps) EQ 0 THEN BEGIN ENDIF ELSE BEGIN device, /close ; tvlct, r, g, b set_plot, 'x' ENDELSE !x = x_env_save !y = y_env_save !p = p_env_save END ;+ ; NAME: ; COLORBARTV ; ; PURPOSE: ; The purpose of this routine is to add a color bar to the current ; graphics window. ; ; CATEGORY: ; Graphics, Widgets. ; ; CALLING SEQUENCE: ; COLORBAR ; ; INPUTS: ; None. ; ; KEYWORD PARAMETERS: ; ; BOTTOM: The lowest color index of the colors to be loaded in ; the bar. ; ; CHARSIZE: The character size of the color bar annotations. Default is 1.0. ; ; COLOR: The color index of the bar outline and characters. Default ; is ncolors - 1 + bottom. ; ; DISCRET: Vecteur contenant les incices des couleurs a tracer en barre ; de couleur. On obtient ainsi une barre de couleur discrete ne comportant que ; les couleurs specifiees ds l'ordre ou elles apparaissent ds le vecteur. ; ; DIVISIONS: The number of divisions to divide the bar into. There will ; be (divisions + 1) annotations. The default is 2. ; ; FORMAT: The format of the bar annotations. Default is '(F6.2)'. ; ; MAX: The maximum data value for the bar annotation. Default is ; NCOLORS-1. ; ; MIN: The minimum data value for the bar annotation. Default is 0. ; ; NCOLORS: This is the number of colors in the color bar. ; ; POSITION: A four-element array of normalized coordinates in the same ; form as the POSITION keyword on a plot. Default is ; [0.88, 0.15, 0.95, 0.95] for a vertical bar and ; [0.15, 0.88, 0.95, 0.95] for a horizontal bar. ; ; PSCOLOR: This keyword is only applied if the output is being sent to ; a PostScript file. It indicates that the PostScript device ; is configured for color output. If this keyword is set, then ; the annotation is drawn in the color specified by the COLOR ; keyword. If the keyword is not set, the annotation is drawn ; in the color specified by the !P.COLOR system variable ; (usually this will be the color black). In general, this ; gives better looking output on non-color or gray-scale ; printers. If you are not specifically setting the annotation ; color (with the COLOR keyword), it will probably ; be better NOT to set this keyword either, even if you ; are outputting to a color PostScript printer. ; ; RIGHT: This puts the labels on the right-hand side of a vertical ; color bar. It applies only to vertical color bars. ; ; TITLE: This is title for the color bar. The default is to have ; no title. ; ; TOP: This puts the labels on top of the bar rather than under it. ; The keyword only applies if a horizontal color bar is rendered. ; ; VERTICAL: Setting this keyword give a vertical color bar. The default ; is a horizontal color bar. ; ; COMMON BLOCKS: ; None. ; ; SIDE EFFECTS: ; Color bar is drawn in the current graphics window. ; ; RESTRICTIONS: ; The number of colors available on the display device (not the ; PostScript device) is used unless the NCOLORS keyword is used. ; ; EXAMPLE: ; To display a horizontal color bar above a contour plot, type: ; ; LOADCT, 5, NCOLORS=100 ; CONTOUR, DIST(31,41), POSITION=[0.15, 0.15, 0.95, 0.75], $ ; C_COLORS=INDGEN(25)*4, NLEVELS=25 ; COLORBAR, NCOLORS=100 ; ; MODIFICATION HISTORY: ; Written by: David Fanning, 10 JUNE 96. ; 10/27/96: Added the ability to send output to PostScript. DWF ; 11/4/96: Substantially rewritten to go to screen or PostScript ; file without having to know much about the PostScript device ; or even what the current graphics device is. DWF ; 1/27/97: Added the RIGHT and TOP keywords. Also modified the ; way the TITLE keyword works. DWF ; 7/15/97: Fixed a problem some machines have with plots that have ; no valid data range in them. DWF ; 3/3/98: ajout du keyword discret par ; sebastien (smasson@lodyc.jussieu.fr) ;- PRO COLORBARTV, BOTTOM=bottom, CHARSIZE=charsize, COLOR=color, $ DIVISIONS=divisions, DISCRET=discret, $ FORMAT=format, POSITION=position, MAX=max, MIN=min, NCOLORS=ncolors, $ PSCOLOR=pscolor, TITLE=title, VERTICAL=vertical, TOP=top, RIGHT=right ; Is the PostScript device selected? postScriptDevice = (!D.NAME EQ 'PS') ; Check and define keywords. IF N_ELEMENTS(ncolors) EQ 0 THEN BEGIN ; Most display devices to not use the 256 colors available to ; the PostScript device. This presents a problem when writing ; general-purpose programs that can be output to the display or ; to the PostScript device. This problem is especially bothersome ; if you don't specify the number of colors you are using in the ; program. One way to work around this problem is to make the ; default number of colors the same for the display device and for ; the PostScript device. Then, the colors you see in PostScript are ; identical to the colors you see on your display. Here is one way to ; do it. IF postScriptDevice THEN BEGIN oldDevice = !D.NAME ; What kind of computer are we using? SET_PLOT to appropriate ; display device. thisOS = !VERSION.OS_FAMILY thisOS = STRMID(thisOS, 0, 3) thisOS = STRUPCASE(thisOS) CASE thisOS of 'MAC': SET_PLOT, thisOS 'WIN': SET_PLOT, thisOS ELSE: SET_PLOT, 'X' ENDCASE ; Open a window (to make sure !D.N_COLORS is accurate). WINDOW, /FREE, /PIXMAP, XSIZE=10, YSIZE=10 WDELETE, !D.WINDOW ; Here is how many colors we should use. ncolors = !D.N_COLORS SET_PLOT, oldDevice ENDIF ELSE ncolors = !D.N_COLORS ENDIF IF N_ELEMENTS(bottom) EQ 0 THEN bottom = 0B IF N_ELEMENTS(charsize) EQ 0 THEN charsize = 1.0 IF N_ELEMENTS(format) EQ 0 THEN format = '(F8.2)' IF N_ELEMENTS(color) EQ 0 THEN color = ncolors - 1 + bottom IF N_ELEMENTS(min) EQ 0 THEN min = 0.0 IF N_ELEMENTS(max) EQ 0 THEN max = FLOAT(ncolors) - 1 IF N_ELEMENTS(divisions) EQ 0 THEN divisions = 2 IF N_ELEMENTS(title) EQ 0 THEN title = '' pscolor = KEYWORD_SET(pscolor) IF KEYWORD_SET(vertical) THEN BEGIN IF KEYWORD_SET(discret) THEN begin facteur=256/n_elements(discret) discret=reform(replicate(1,facteur) # discret,facteur*n_elements(discret)) bar = REPLICATE(1B,10) # discret endif else bar = REPLICATE(1B,10) # BINDGEN(256) IF N_ELEMENTS(position) EQ 0 THEN position = [0.88, 0.15, 0.95, 0.95] ENDIF ELSE BEGIN IF KEYWORD_SET(discret) THEN begin facteur=256/n_elements(discret) discret=reform(replicate(1,facteur) # discret,facteur*n_elements(discret)) bar = discret # REPLICATE(1B,10) endif else bar = BINDGEN(256) # REPLICATE(1B, 10) IF N_ELEMENTS(position) EQ 0 THEN position = [0.15, 0.88, 0.95, 0.95] ENDELSE ; Scale the color bar. IF NOT KEYWORD_SET(discret) THEN $ bar = BYTSCL(bar, TOP=ncolors-1) + bottom ; Get starting locations in DEVICE coordinates. xstart = position(0) * !D.X_VSIZE ystart = position(1) * !D.Y_VSIZE ; Get the size of the bar in DEVICE coordinates. xsize = (position(2) - position(0)) * !D.X_VSIZE ysize = (position(3) - position(1)) * !D.Y_VSIZE ; For PostScript output only, draw the annotation in !P.COLOR ; unless "pscolor" is set. This makes better output on grayscale ; printers. IF postScriptDevice AND (pscolor NE 1) THEN BEGIN oldcolor = color color = !P.COLOR ENDIF ; Display the color bar in the window. Sizing is ; different for PostScript and regular display. IF postScriptDevice THEN BEGIN TV, bar, xstart, ystart, XSIZE=xsize, YSIZE=ysize ENDIF ELSE BEGIN bar = CONGRID(bar, CEIL(xsize), CEIL(ysize), /INTERP) TV, bar, xstart, ystart ENDELSE ; Annotate the color bar. IF KEYWORD_SET(vertical) THEN BEGIN IF KEYWORD_SET(right) THEN BEGIN PLOT, [min,max], [min,max], /NODATA, XTICKS=1, $ YTICKS=divisions, XSTYLE=1, YSTYLE=9, $ POSITION=position, COLOR=color, CHARSIZE=charsize, /NOERASE, $ YTICKFORMAT='(A1)', XTICKFORMAT='(A1)', YTICKLEN=0.1 , $ YRANGE=[min, max], YTITLE=title AXIS, YAXIS=1, YRANGE=[min, max], YTICKFORMAT=format, YTICKS=divisions, $ YTICKLEN=0.1, YSTYLE=1, COLOR=color, CHARSIZE=charsize ENDIF ELSE BEGIN PLOT, [min,max], [min,max], /NODATA, XTICKS=1, $ YTICKS=divisions, XSTYLE=1, YSTYLE=9, $ POSITION=position, COLOR=color, CHARSIZE=charsize, /NOERASE, $ YTICKFORMAT=format, XTICKFORMAT='(A1)', YTICKLEN=0.1 , $ YRANGE=[min, max] AXIS, YAXIS=1, YRANGE=[min, max], YTICKFORMAT='(A1)', YTICKS=divisions, $ YTICKLEN=0.1, YTITLE=title, YSTYLE=1, COLOR=color, CHARSIZE=charsize ENDELSE ENDIF ELSE BEGIN IF KEYWORD_SET(top) THEN BEGIN PLOT, [min,max], [min,max], /NODATA, XTICKS=divisions, $ YTICKS=1, XSTYLE=9, YSTYLE=1, $ POSITION=position, COLOR=color, CHARSIZE=charsize, /NOERASE, $ YTICKFORMAT='(A1)', XTICKFORMAT='(A1)', XTICKLEN=0.1, $ XRANGE=[min, max], XTITLE=title AXIS, XTICKS=divisions, XSTYLE=1, COLOR=color, CHARSIZE=charsize, $ XTICKFORMAT=format, XTICKLEN=0.1, XRANGE=[min, max], XAXIS=1 ENDIF ELSE BEGIN PLOT, [min,max], [min,max], /NODATA, XTICKS=divisions, $ YTICKS=1, XSTYLE=1, YSTYLE=1, $ POSITION=position, COLOR=color, CHARSIZE=charsize, /NOERASE, $ YTICKFORMAT='(A1)', XTICKFORMAT=format, XTICKLEN=0.1, $ XRANGE=[min, max], TITLE=title ENDELSE ENDELSE ; Restore color variable if changed for PostScript. IF postScriptDevice AND (pscolor NE 1) THEN color = oldcolor END