## 4. Vector Fields

To illustrate how to display vector data, we begin with a two dimensional vector field that is the gradient of the function , which was used to illustrate contour, raster and surface plots in the previous section. Code 3 illustrates how to write a simple MTV data file containing the vector field (vx,vy,vz) = (2x,-2y,0) on a 25x25 grid over the square 0 < x,y < 5. Note that even though a two dimensional vector field is to be displayed, it is necessary to write the vector data set in the form x y z vx vy vz, where x,y,z specify the tail of a given vector and vx,vy,vz designate the components of the vector.

### Code 3:

program vector parameter(mmax=25,nmax=25) parameter(xmin=0.0,ymin=0.0,xmax=5.0,ymax=5.0) parameter(dx=(xmax-xmin)/mmax,dy=(ymax-ymin)/nmax) open(4,file='vect.dat',status='unknown') c Specify that data are to be vectors write(4,*)'\$DATA=VECTOR' c Set the maximum and minimum x, y and z-values write(4,*)'%xmin=',xmin write(4,*)'%ymin=',ymin write(4,*)'%xmax=',xmax write(4,*)'%ymax=',ymax write(4,*)'%zmin=-0.5' write(4,*)'%zmax=0.5' c Set a scale factor to control the length of the vectors write(4,*)'%vscale=0.02' z = 0.0 vz = 0.0 y = ymin - dy do 1 n = 1,nmax x = xmin y = y + dy do 2 m = 1,mmax vx = 2.0*x vy = -2.0*y c Write the coordinates of the tail and the components of vector write(4,100)x,y,z,vx,vy,vz x = x + dx 2 continue 1 continue 100 format(3f10.2,' ',3f10.2) close(4) end