/*
**    PROC    addline
**    Author: Paul L. Fackler
**            Department of Agricultural and Resource Economics
**            North Carolina State University - Box 8109
**            Raleigh, NC, USA 27695
**            919-515-4535
**            paul_fackler@ncsu.edu
**    Provided without guarantees for free public, non-commercial use.
**    Date: 13 June 1997
**
**    Purpose: indicate dates by vertical lines in a time
**             series plot.
**
**    Format: addline(x,y,ltype,lsize);
**
**    INPUT:   x      = nxk matrix
**             y      = nxk matrix
**             ltype  = line type
**             lsize  = line size
**
*/

@
Adds lines defined by x and y (each nx1 or nxk).
Type (1x1 or kx1) defines the line type:
1)dashes 2)dots 3)short dashes 4)close dots 5)dots and dashes 6)solid
Size (1x1 or kx1) defines the thickness of the lines (0 for default)

This proc appends information to the global parameter _PLINE so
_pline should be cleared before constructing a new plot.
Example:
To add a dotted vertical line at x=5 on a plot in which y is displayed
from -10 to 10 use:
  addline((5|5),(-10|10),5,0)
@

clear _pline;
proc (0)=addline(x,y,ltype,lsize);
  local temp,n,k,newline,i;
  k=maxc(cols(y)|cols(x));
  if k>1;
    if cols(y)==1;y=y+zeros(1,k);endif;
    if cols(x)==1;x=x+zeros(1,k);endif;
  endif;
  if (cols(y)/=k) or (cols(x)/=k);
   "Error: X and Y have different number of columns";
   stop;
  endif;
  if rows(y)/=rows(x);
   "Error: X and Y have different number of rows";
   stop;
  endif;
  n=rows(y);
  if n==1;
   "Error: X and Y have only one row";
   stop;
  endif;
  if rows(ltype)==1;ltype=ltype+zeros(k,1);endif;
  if rows(lsize)==1;lsize=lsize+zeros(k,1);endif;
  newline=0;
  if cols(_pline)==1;_pline=zeros(1,9);newline=1;endif;

  i=0; do until i>=k;i=i+1;
    temp=zeros(n-1,9)+(1~ltype[i]~0~0~0~0~0~15~lsize[i]);
    temp[1,7]=1;
    temp[.,3 5]=trimr(x[.,i],0,1)~trimr(x[.,i],1,0);
    temp[.,4 6]=trimr(y[.,i],0,1)~trimr(y[.,i],1,0);
    _pline=_pline|temp;
  endo;
  if newline; _pline=trimr(_pline,1,0);endif;
endp;
