NewImage from DataBrowser selection with scale bar

With this function you can create a NewImage of the wave, which is selected in the DataBrowser. Instead of the normale Igor scale, a Scale bar is inserted, which has a predefined length. You have to define the height or the width of the Newimage. The aspect ratio of this NewImage is determined by the dimdelta and not only by the number of points of each dimension.

v_length_input -> Defines the length of width or height

v_mode -> 0 for the width, 1 for the height

v_bar_length -> How long the scale should be? It will use the dimdelta of the dimensions.

v_pixel_min -> Minimum thickness of the bar. Only used if the Newimage is very flat.

s_color -> String that containts the color scale name, like "Rainbow"

v_reverse -> 0 for normal color scale, 1 for reverse

Example: f_newimage_scalebar(100,0,5,5,"Rainbow",1)

function f_newimage_scalebar(variable v_length_input, variable v_mode, variable v_bar_length, variable v_pixel_min, string s_color, variable v_reverse)
    if (v_mode!=0&&v_mode!=1)
        print "Error: Input of v_mode wrong. Choose 0 for fixed width and 1 for fixed height."
        return 0   
    endif
    string s_importwave  = getbrowserSelection(0)
    if (waveexists($s_importwave)==0)
        print "Error: No wave selected."
        return 0
    endif
    wave w_importwave=$s_importwave
    variable v_rows=dimsize(w_importwave,0)
    variable v_columns=dimsize(w_importwave,1)
    if (v_columns<=1)
        print "Error: No multidim. wave selected."
        return 0   
    endif
    variable v_row_offset=dimoffset(w_importwave,0)
    variable v_row_delta=dimdelta(w_importwave,0)
    variable v_row_length=(v_rows-1)*v_row_delta
    variable v_col_offset=dimoffset(w_importwave,1)
    variable v_col_delta=dimdelta(w_importwave,1)
    variable v_col_length=(v_columns-1)*v_col_delta
    variable v_width,v_height
    switch (v_mode)
        case 0:
            v_width=v_length_input
            v_height=(v_col_length/v_row_length)*v_width
        break
        case 1:
            v_height=v_length_input
            v_width=(v_row_length/v_col_length)*v_height
        break  
    endswitch
    string S_name //name of window of NewImage
    NewImage/K=1/F w_importwave
    string s_nameofwave=nameofwave(w_importwave)       
    ModifyImage $s_nameofwave, ctab= {*,*,$s_color,v_reverse}
    ModifyGraph nticks=0
    ModifyGraph margin(left)=10,margin(bottom)=10,margin(right)=10,margin(top)=10
    ModifyGraph width=v_width
    ModifyGraph height=v_height
    variable v_bar_length_rel=(v_bar_length/v_row_length)
    variable y_end= 0.95
    variable y_start= 0.93
    variable y_end_abs=(1-y_end)*v_height
    variable x_start=0.05
    if (x_start>(y_end_abs/v_width))
        x_start=(y_end_abs/v_width)
    endif
    variable v_x_pixel_min_rel=v_pixel_min/v_width
    variable v_y_pixel_min_rel=v_pixel_min/v_height
    variable x_end=x_start+v_bar_length_rel
    variable v_y_delta_abs=abs(y_end-y_start)*v_height
    if (y_end>(1-v_y_pixel_min_rel))
        y_end=1-v_y_pixel_min_rel
        y_start=y_end-0.02
    endif
    if (x_start<v_x_pixel_min_rel)
        x_start=v_x_pixel_min_rel
        x_end=x_start+v_bar_length_rel
    endif  
    if (v_y_delta_abs<7) //if not, height to low
        y_start=y_end-(7/v_height)
    endif
    ModifyGraph noLabel=2
    SetDrawEnv xcoord= axrel,ycoord= axrel
    DrawRect x_start,y_start,x_end,y_end
end

 

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More