define FOGR,0  rem  section dealing with graph as a whole
define FSGR,1
define FAGR,2
define TCGR,3
define LCGR,4
define LWGR,5
define PDGR,6
define PSGR,7
define BGGR,8
define PWGR,9
define PHGR,10
define BWGR,11
define DCOLGR,12
define GRGR,17
define ROWS,18
define COLUMNS,19
define TDGR,20
define GRAPHTYPE,21
define XLABEL,22
define YLABELS,23
define THICKNESSGR,29
define FRGR,30
define OLGR,31
define OTGR,32
define ORGR,33
define OBGR,34
define ILGR,35
define ITGR,36
define IRGR,37
define IBGR,38
define MTGR,39
define MSGR,40
define PIGR,41
define MAGR,42
define PSIZE,43
define FOA,0   rem  Section dealing with axis
define FSA,1
define FAA,2
define TCA,3
define LCA,4
define LWA,5
define STA,6
define LGA,7
define INA,8
define UPA,9
define LOA,10
define NSA,11
define AA,12
define BA,13
define WIDTHA,14
define HEIGHTA,15
define HOTXA,16
define HOTYA,17
define FORMATA,18
define LENGTHA,19
define PAXIS,20
define FOD,0    rem Section dealing with data set
define FSD,1
define FAD,2
define TCD,3
define LWD,4
define LCD,5
define PDD,6
define PSD,7
define FCD,8
define MTD,9
define MSD,10
define MCD,11
define FRD,12
define TDD,13
define PDATA, 14
define FOM,0    rem Section dealing with marker keys - text properties
define FSM,1
define FAM,2
define TCM,3
define LWM,4    rem line properties
define LCM,5
define PDM,6
define PSM,7
define MTM,8    rem marker properties- repeated 5 times
define MSM,9
define MCM,10
define XSM,28
define YSM,29
define XEM,30
define YEM,31
define NSM,32
define MDATA,33
define FOC,0    rem Section dealing with colour keys - text properties
define FSC,1
define FAC,2
define TCC,3
define LWC,4    rem line properties
define LCC,5
define PDC,6
define PSC,7
define FCC,8    rem colour (repeated 16 times)
define XSC,20
define YSC,21
define XEC,22
define YEC,23
define CDATA,24
define LINES_ONLY,0   rem types of 2D graph
define POINTS_ONLY,1
define LINES_AND_POINTS,2
define VERTICAL_HISTOGRAM,3
define HORIZONTAL_HISTOGRAM,4
define STACKED_VERTICAL_HISTOGRAM,5
define STACKED_HORIZONTAL_HISTOGRAM,6
define PICTOGRAM,7
define PIE_CHART,8
define TWO_LINES,9
define BOX_AND_TAILS,10
define DISTRIBUTION,11
define GENERAL,12
define LINE_HISTO,13
define DRAG_ALLOWED, 0x1
define SELECT_ALLOWED, 0x2
define TEXT_EFFECTS, 0x4
define FILL_EFFECTS, 0x8
define LINE_EFFECTS, 0x10
define GRAPH_COLOUR_ALLOWED, 0x20
define THREE_DEE_ALLOWED, 0x40
define GRID_ALLOWED, 0x80
define EXPLODE_ALLOWED, 0x100
define COLOURS_ALLOWED, 0x200
define BAR_WIDTH_ALLOWED, 0x400
define POINT_DETAILS_ALLOWED, 0x800
define TICKS_ALLOWED, 0x1000
define DIMENSIONS_ALLOWED, 0x2000
define TOP_ALLOWED, 0x4000
define DELETE_ALLOWED, 0x8000
define ALL_SELECTED, 0x10000
define NONE_SELECTED, 0x20000
define REDRAW_NEEDED, 0x40000
define NOGRAPH,0

rem : Plotter for general graph.   We use a plotter function which 
rem : examines the data and returns a marker for the graph type.
rem : This must be one of
rem : 
rem :                     VERTICAL_HISTOGRAM
rem :                     HORIZONTAL_HISTOGRAM
rem :                     LINES_ONLY
rem :                     POINTS_ONLY
rem :                     LINE HISTO
rem :            or       -1 (No graph)
rem :            

macro CRM_which_type(data(),s,p(),v,date)
local rows,columns,r,j,k,res
    rows = first(data)-1
    columns = second(data)-1
rem   search top row for labels
    r = 0 
    for j = 0 to columns-1
       if type (data(0,j)) = 3 then r=1
    next j

rem now search rest of graph for numbers
    for k = r to rows-1
        for j = 1 to columns-1
           if type(data(k,j)) > 2 then  =-1
        next j
    next k
rem see what left hand side is
    for k = r to rows-1
       if type(data(k,0)) > 2 then goto cc
    next k
rem now see if numbers increase monotonically
    for k = r to rows -3
        if  data(k+1,0) <= data(k,0) then = POINTS_ONLY
     next k
    =LINES_ONLY
cc:
     if(date and rows <= 16) then = LINE_HISTO
     if (rows < 8) then = VERTICAL_HISTOGRAM
     if (rows < 15) then = HORIZONTAL_HISTOGRAM
     =-1
endmacro
     
     
                           
macro general(a(),s)
graphmacro "General",0x19FF,""
   local v,q,n,res,h,w,j
   local p(PSIZE)
   v = psregister(s)
   q = psstep(v)
   if iserror(q) then = q
   if q<> CRM_code("A") then = "Missing parameter substring"
   res = CRM_get_gr_params(p,v)
   p(GRAPHTYPE) = GENERAL
   h = first(a)
   w = second(a)
   n = CRM_datasets(v,w,h)
  if n <= 1 then = "Graph can't be plotted"
   if pscontains(v,"u") then 
      res = CRM_point_plot_row_data(a,s,v,p,w,n,2)
  else
      res = CRM_point_plot_col_data(a,s,v,p,h,n,2)
   endif
  q= CRM_close_string(v)
  if res = LINES_ONLY then = line_plot(a,s)
   if res = POINTS_ONLY then = scatter_diagram(a,s)
   if res = VERTICAL_HISTOGRAM then 
        = all_histograms(a,s,VERTICAL_HISTOGRAM)
   endif
   if res = HORIZONTAL_HISTOGRAM then 
        = all_histograms(a,s,HORIZONTAL_HISTOGRAM)
   endif
   if res = LINE_HISTO then
          = all_histograms(a,s,LINE_HISTO)
   endif
  = "Can't plot this graph"
   
endmacro
