function diamond(args)

loc='r'
marg=0.1
fsize=0.1
scol=1
oline='off'
fs=1
dsize='auto'



check=1
a=1
v=1
while(check=1)
  line=subwrd(args,a)
  if(line='');break;endif

  if(line='-help' | line='-h')
    help()
    return
  endif

  if(line='-size' | line='-s');dsize=subwrd(args,a+1);endif
  if(line='-marg');marg=subwrd(args,a+1);endif
  if(line='-line'| line='-l');oline=subwrd(args,a+1);endif
  if(line='-fs'| line='-int');fs=subwrd(args,a+1);endif
  if(line='-font'| line='-fontsize');fsize=subwrd(args,a+1);endif
  if(line='-scol');scol=subwrd(args,a+1);endif
  if(line='-loc');loc=subwrd(args,a+1);endif
  
  if(line='-r');loc='r';endif
  if(line='-l');loc='l';endif
  if(line='-t');loc='t';endif
  if(line='-b');loc='b';endif

  if(line='-help')
    help()
    return
  endif

  a=a+1
endwhile


'q gxinfo'
xlims=sublin(result,3)
xl=subwrd(xlims,4);xr=subwrd(xlims,6)
ylims=sublin(result,4)
yb=subwrd(ylims,4);yt=subwrd(ylims,6)

'q shades'
shades=result
numshades=sublin(shades,1)
c=subwrd(numshades,5)
say c

line=1
wr=1
while(line<=c)

if(loc='r')
  if(dsize='auto');size=(yt-yb)/c;else;size=dsize;endif
  x1=xr+marg
  x2=x1+size
  y1=yb+size*(line-1)
  y2=yb+size*line
  j='l'
  sx=x2+marg/2
  sy=y2
endif


if(loc='l')
  if(dsize='auto');size=(yt-yb)/c;else;size=dsize;endif
  x1=xl-marg-size
  x2=xl-marg
  y1=yb+size*(line-1)
  y2=yb+size*line
  j='r'
  sx=x2-marg/2-size
  sy=y2
endif


if(loc='t')
  if(dsize='auto');size=(xr-xl)/c;else;size=dsize;endif
  x1=xl+size*(line-1)
  x2=xl+size*line
  y1=yt+marg
  y2=y1+size
  j='c'
  sx=x2
  sy=y2+marg/2
endif

if(loc='b')
  if(dsize='auto');size=(xr-xl)/c;else;size=dsize;endif
  x1=xl+size*(line-1)
  x2=xl+size*line
  y1=yb-marg-size
  y2=y1+size
  j='c'
  sx=x2
  sy=y1-marg/2
endif

cline=sublin(shades,line+1)
  color=subwrd(cline,1)
  if(subwrd(cline,3)='>');value='>'value;else;value=subwrd(cline,3);endif

  if(valnum(value) != 0)
    if(math_strlen(value) > 6)
      if(valnum(value)=0)
        value=math_format(%6.2,value)
      endif
    endif
  endif


  'set line 'color
  draw_diamond(x1,x2,y1,y2,size,1)

  if(oline ='on')
    'set line 1'
    draw_diamond(x1,x2,y1,y2,size,0)
  endif

  if(wr=fs)
    'set string 'scol' 'j' 0.1'
    'set strsiz 'fsize
    'draw string 'sx' 'sy' 'value
    wr=1
  else
    wr=wr+1
  endif

  
  line=line+1
endwhile

******

function help()
  say '---------------------------------------------------'
  say '|                                                 |'
  say '|                 diamondbar.gs v1.0                    |'
  say '|                 January 2014                       |'
  say '---------------------------------------------------'
  say 'Usage:'
  say 'Draws a color bar using diamonds'
  say ''
  say 'No Required arguments'
  say ''
  say 'Example: "diamondbar"'
  say '  -draws a colorbar using diamonds on an axis using the shading information on the plot'
  say '---------------------------------------------------'
  say ''  
  say 'Optional: -help           - Pulls up this Help Page'
  say '          -loc            - Chooses location for the colorbar (r=right-vertical, '
  say '                            l=left-vertical, b=bottom-horizontal,t=top-horizontal)'
  say '                            can also be called by (-l,-r,-b,-t)'
  say '          -size/s         - sets size of each diamond, defaults to "auto"'
  say '          -marg           - sets margin to axis'
  say '          -fs/int         - sets the interval for each number plotted along the colorbar'
  say '          -font/fontsize  - sets the font size of the numbers'
  say '          -scol           - sets the color of the numbers'
  say '          -line           - draws outline around each diamond if included'    
  say ''
  say '---------------------------------------------------'
  say ''
  say 'Example: diamondbar -r -scol 2 -marg 0.2'
  say '   Draws a colorbar made of diamonds in the right axis with numbers labled in red, and a margin 0.2'
  say ''
  say ''
  say 'GENERAL NOTES:'
  say ''
  say 'Version 1.0: Orginially Developed by GrADS-Aholic: January 2014'
  say ''
  say 'Please report any bugs to http://gradsaddict.blogspot.com/'
  return


function draw_diamond(x1,x2,y1,y2,size,f)

    p1=size/2+x1' 'y1
    p2=x2' 'size/2+y1
    p3=size/2+x1' 'y2
    p4=x1' 'size/2+y1
   
    if(f=1)
      'draw polyf 'subwrd(p1,1)' 'subwrd(p1,2)' 'subwrd(p2,1)' 'subwrd(p2,2)' 'subwrd(p3,1)' 'subwrd(p3,2)' 'subwrd(p4,1)' 'subwrd(p4,2)
    else
      'draw line 'subwrd(p1,1)' 'subwrd(p1,2)' 'subwrd(p2,1)' 'subwrd(p2,2)
      'draw line 'subwrd(p2,1)' 'subwrd(p2,2)' 'subwrd(p3,1)' 'subwrd(p3,2) 
      'draw line 'subwrd(p3,1)' 'subwrd(p3,2)' 'subwrd(p4,1)' 'subwrd(p4,2)
      'draw line 'subwrd(p4,1)' 'subwrd(p4,2)' 'subwrd(p1,1)' 'subwrd(p1,2) 
    endif


****







