# original is in a gnuplot's demo of vector.dem;
#   $Id: vector.dem,v 1.9 2005/03/25 05:01:06 sfeam Exp $
#
# modified for demonstrating pm3d's functionarity 
#   by N. Matuda 2005/12/12
#   by N. Matuda 2013/03/29 against Ver.4.6.2
#
      coef=.6
      x0=1.5
      q1=1
      q2=-1.5
#
      r(x,y)=sqrt(x*x+y*y)
      v1(x,y)=  q1/(r((x-x0),y))
      v2(x,y)=  q2/(r((x+x0),y))
#
      vtot(x,y)=v1(x,y)+v2(x,y)
#
      e1x(x,y)= q1*(x-x0)/r(x-x0,y)**3
      e1y(x,y)= q1*(y)/r(x-x0,y)**3
      e2x(x,y)= q2*(x+x0)/r(x+x0,y)**3
      e2y(x,y)= q2*(y)/r(x+x0,y)**3
      etotx(x,y)=e1x(x,y)+e2x(x,y)
      etoty(x,y)=e1y(x,y)+e2y(x,y)
      enorm(x,y)=sqrt(etotx(x,y)*etotx(x,y)+etoty(x,y)*etoty(x,y))
      dx1(x,y)=coef*etotx(x,y)/enorm(x,y)
      dy1(x,y)=coef*etoty(x,y)/enorm(x,y)
      dx2(x,y)=coef*etotx(x,y)
      dy2(x,y)=coef*etoty(x,y)
#
set xrange [-5:5]; set yrange [-5:5]
set cbrange[-5:5]
set samples 60
set isosamples 50,70
set palette defined (0 0 0 1, 0.48 0 0 0.5, 0.5 0 0 0, 0.52 0.5 0 0, 1 1 0 0)
unset colorbox
unset key
unset tics
unset border
###
set table "potential.dat"
splot vtot(x,y)
###
set contour 
set cntrparam cubicspline
set cntrparam levels discrete -3,-2,-1,-0.5,-0.2,-0.1,0,0.1,0.2,0.5,1,2,3
unset surface
set table "contour.dat"
splot vtot(x,y) w lines
###
unset table
unset contour
set pm3d map interpolate 2,2
set surface
set term pngc size 686,686 crop 
set out 'asym-dipole.png'
splot vtot(x,y) w pm3d,\
      "contour.dat" w lines lw 0.5 lc rgb "light-green",\
      "potential.dat" using 1:2:(0):(coef*dx1($1,$2)):(coef*dy1($1,$2)):(0)\
      every 3:3:0 w vec lw 0.5 lc rgb "gold"
###
!display asym-dipole.png