cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
cc                     Version 1.1                        cc
cc                     plg.f                              cc
cc    Jun 16 1993 add group variable specification        cc
cc usage is the same as for pl with the following changes cc
cc (1) the user can specify or ignore group changes as    cc
cc a criterion for breaking a line                        cc
cc (2) error handling is improved                         cc 
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc

      program plotter
      parameter (nn=3)
      parameter (huge_line=255)

      character*40 names(nn)
      real vals(nn),oldval
      character*80 tmp
      character*255 nam
      integer handle

      integer num,flag

      logical logvar(nn)
      data logvar/nn*.false./
      integer mktyp
      data mktyp/0/
      real mkhgt
      data mkhgt/2.0/  
      data vals/-999.,-999.,-999./
      num=1
      call getarg(1,nam)
      i=2
      numg = 0
      ig= 0
      oldval=-999.
      do while(i.le.iargc())
         call getarg(i,tmp)
         if(tmp.eq.'-l')then
            logvar(num)=.true.
            i=i+1
         else if(tmp.eq.'-brk')then
            i=i+1
            call getarg(i,tmp)
            ig=3
            names(ig)=tmp
            call fixstr(names(ig))
            numg=1
            i=i+1
         else if(tmp.eq. '-nobrk') then
            i=i+1
            ig=3
         else if(tmp.eq.'-sym')then
            i=i+1
            call getarg(i,tmp)
            read(tmp,*,err=999)mktyp
            mktyp=mktyp+1
            i=i+1
         else if(tmp.eq.'+sym')then
            i=i+1
            call getarg(i,tmp)
            read(tmp,*,err=999)mktyp
            mktyp=mktyp+1
            mktyp=-mktyp
            i=i+1
         else if(tmp.eq.'-siz')then
            i=i+1
            call getarg(i,tmp)
            read(tmp,*,err=998)mkhgt
            i=i+1
         else
            names(num)=tmp
            call fixstr(names(num))
            num=num+1
            i=i+1
         endif
      enddo
 10   continue
      num=num-1
      if(num.ne.2) stop 'Plot requires both x and y variable names '
      call fixstr(nam)

      handle=1
      ilevel=jdbopen(handle,nam,names,40,num+numg)
      if(ilevel.lt.0)then
         if (ilevel.eq.-999)then
            write(*,*)'Object not found or no permission'
         else
            write(*,*)'Variable not found - ',names(-ilevel)
         endif
         call exit(1)
      endif
      if(ig.eq.0)ilevel=min(jdblevel(handle,0),jdblevel(handle,1))

      call scale

 100  continue
      flag=jdbread(handle,vals)
c      write(*,*)'>>',flag,ilevel
      if (flag.lt.0)then
         call jdbclose(handle)
         call penup
         call endplt
         call exit(0)
      endif
      if(ig.eq.0)then
         if (flag.lt.ilevel) call penup
c         if (flag.lt.ilevel) write(*,*)'penup'
      else if (vals(ig).ne.oldval) then
          call penup
c         write(*,*)'penup'
         oldval=vals(ig)
      endif
      do 12 i=1,num
         if (logvar(i)) then
            if (vals(i).gt.0.0) then 
               vals(i)=log10(vals(i))
            else 
               vals(i)=-9999.99
            endif
         endif
 12   continue
      if (mktyp.le.0) call plot(vals(1),vals(2))
      if (mktyp.ne.0) call marker(abs(mktyp),vals(1),vals(2),mkhgt)
c      write(*,*)vals(1),vals(2)
      goto 100
c/* note- this only prints the first element of an array variable */
998   stop 'size of marker not an integer'
999   stop 'number of marker not an integer'
      end

	subroutine marker(mktyp,x,y,amksiz)
        include '../lib/penplot.com'
	character*7 st
	write(st,1)mktyp-1
1	format('\\200',i1,'\\')
c	call fixstr(st)
cd	write(*,*)amksiz,x,y,st
        if (x.lt.min(x0,x1) .or. x.gt.max(x0,x1) .or.
     $      y.lt.min(y0,y1) .or. y.gt.max(y0,y1))return
	xs=x
	ys=y
	call text(st,xs,ys,0.0,0.0,0,amksiz,1)
	call plot(x,y)
	return
	end


