/********* PLOT TEXT LABELS ***************
Author: Gerrit Draisma
        http://www.few.eur.nl/few/people/draisma/
        Econometrisch Instituut - Tinbergen Instituut
        +31-10-4088834 fax: +31-10-4089162
        Erasmus Universiteit Rotterdam
Date: Dec 1999
This code is provided gratis without warrantee.
**********************************************/

@begin example of use:@
new;
library pgraph;
clear all;
n = 37 ;
_plctrl = -1 ;
_pstype = 1 ;

X = rndn(n,2) ;
s = ftocv(seqa(1,1,n),0,0)$+"x";
gdtext(x[.,1],x[.,2],s) ;
begwind;
xy(x[.,1],x[.,2]);
endwind;
@end example of use:@

/*
**  gdtext
**
**  purpose: add "text" to a plot
**
**  format: gdtext(x,y,s) ;
**
**  input: x, y: n x 1  : location of text
**         s   : n x 1  : text (Character vector)
**
**  output: none
**
**  globals: _pmsgctl  : Gauss global message location and format.
**           _pmsgstr  : string with message text.
**           _gdtxtype : 1 x 4 , color-height-thickness-angle
**
**  remarks:
**           gdtext is useful to add text to a plot.
**           gdline(0,0,0) resets the _pmsgstr/ctl variables:
**              "deletes" all texts
**
**  date:  21-12-98
**  author: G. Draisma, Econometric Institute
*/


declare _gdtxtype ?= {15 0.20 0 0 } ;
proc (0) = gdtext(x,y,s) ;
local i, n, tp  ;
tp = _gdtxtype[2 4]~1~_gdtxtype[1 3] ;
x = vecr(x) ;
y = vecr(y) ;
n = maxc(rows(x)|rows(y)) ;
x = reshape(x,n,1) ;
y = reshape(y,n,1) ;
s = reshape(0 + s,n,1) ;
if s == 0;
   _pmsgctl = 0 ;
   _pmsgstr = "" ;
retp ;
endif ;
if cols(_pmsgctl) < 2 ;
  _pmsgctl = x~y~reshape(tp,n,5) ;
  _pmsgstr = "" ;
  i = 0 ;
  do while i < n ;
     i = i + 1;
     _pmsgstr = _pmsgstr $+ s[i] $+ "\000" ;
  endo ;
else ;
  _pmsgctl = _pmsgctl|(x~y~reshape(tp,n,5)) ;
  i = 0 ;
  do while i < n ;
     i = i + 1;
     _pmsgstr = _pmsgstr $+ s[i] $+ "\000" ;
  endo ;
endif ;
retp ;
endp ;
