home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug175.arc / JRTMAN3.LBR / JRTMAN.AZE / JRTMAN.APE
Text File  |  1979-12-31  |  13KB  |  380 lines

  1. .OP
  2.       JRT Pascal  User's Guide                         NOT FOR SALE   -177-
  3.  
  4.  
  5.  
  6.       E.   JGRAF
  7.  
  8.  
  9.            JGRAF  is  an  external  procedure  which formats x-y graphs and
  10.       scatter graphs.  The graph size in rows and columns and the lower and
  11.       upper x and y bounds are set by the user.  A title to the  graph  may
  12.       be  provided.   Once the graph has been prepared, it can be displayed
  13.       on the console, printed or stored in a disk file.
  14.  
  15.            Any number of  data  points  can  be  plotted.   Any  number  of
  16.       separate   plots   can  be  prepared  simultaneously  (within  memory
  17.       limitations).
  18.  
  19.            To  use  JGRAF,  your  program  (or  occasionally  an   external
  20.       procedure) must declare the char9000 and jgraf_interface types.  Your
  21.       program   must   then   declare   one  (or  more)  variable  of  type
  22.       jgraf_interface.  For convenience, the  interface  variable  will  be
  23.       called  jgi  in this document.  Your program could call the interface
  24.       variable(s) anything appropriate.  Your  program  must  also  declare
  25.       JGRAF as an external procedure.
  26.  
  27.            The  declarations  for  sample  main  program  to  take plotting
  28.       commands from a disk file and create a plot is shown here.  (The body
  29.       of the sample program is listed later.)  Everything  listed  here  is
  30.       required of any program using JGRAF except for the declarations noted
  31.       as specific to jg.
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.       Copy compliments of Merle Schnick                 APPENDIX E:   JGRAF
  56. .PAè
  57.       JRT Pascal  User's Guide                         NOT FOR SALE   -178-
  58.  
  59.  
  60.  
  61.       program jg;
  62.       %ltrace %ptrace  (* optional - suggested *)
  63.  
  64.       type
  65.       char9000 = array [1..9000] of char;
  66.       jgraf_interface = record
  67.               command : char;         (* R *)
  68.               plot_char : char;       (* R *)
  69.               x_grid : boolean;       (* R *)
  70.               y_grid : boolean;       (* R *)
  71.               rows : integer;         (* R *)
  72.               columns : integer;      (* R *)
  73.               x_lower : real;         (* R *)
  74.               x_upper : real;         (* R *)
  75.               y_lower : real;         (* R *)
  76.               y_upper : real;         (* R *)
  77.               filename : array [1..14] of char;
  78.               graf_title : string;    (* R *)
  79.  
  80.       (* fields below used internally by jgraf *)
  81.               b : ^char9000;
  82.               bufr_size : integer;
  83.               line_size : integer;
  84.               row_count : integer;
  85.               x_spacing : real;
  86.               y_spacing : real;
  87.               end;
  88.  
  89.       var
  90.       jgi : jgraf_interface;
  91.  
  92.       (* following are used by program jg *)
  93.       file_name : array[1..20] of char;
  94.       title : array[1..24] of char;
  95.       inf : file of char;
  96.       x, y : real;
  97.       command : char;
  98.       (* end of variables used by sample program *)
  99.  
  100.       procedure jgraf ( var jg : jgraf_interface;
  101.                         x, y : real ); extern;
  102.  
  103.       (* end of declarations *)
  104.  
  105.  
  106.            To  produce  graphs,  your program must first set all members of
  107.       jgi marked (*  R  *)  in  the  jgraf_interface  type  declaration  to
  108.       appropriate values.
  109.       Copy compliments of Merle Schnick                 APPENDIX E:   JGRAF
  110. .PAè
  111.       JRT Pascal  User's Guide                         NOT FOR SALE   -179-
  112.  
  113.  
  114.  
  115.            Jgi.x_grid  would  be  set to false if grid lines running across
  116.       the graph should be omitted.  Jg.y_grid is likewise set to  false  if
  117.       grid  lines  running  up  and  down  are to be omitted.  Jgi.rows and
  118.       jgi.columns contain the number of  lines  and  number  of  characters
  119.       across the body of the plot itself (minus one).
  120.  
  121.            The  number  of rows and columns should normally be divisible by
  122.       10.  Plot size can be calculated  as  (number  of  columns  +  16)  *
  123.       (number  of lines + 5), which should not exceed 9000 characters.  The
  124.       length of jgi.title should be less than the number of columns in  the
  125.       plot.
  126.  
  127.            Once  all  the  requaired  members  of  jgi are initialized, set
  128.       jgi.command to 'I' and call JGRAF, as
  129.  
  130.               JGI.COMMAND := 'I';
  131.               JGRAF ( JGI, 0.0, 0.0 );
  132.  
  133.       (Note  that  the  examples  listed  here  in  upper  case   are   for
  134.       illustration only and are NOT part of the program jg.)
  135.  
  136.            Then,  to place data points on the graph, set jgi.command to 'D'
  137.       and call JGRAF for each of the appropriate points.  Do this as  often
  138.       as  needed.   To get two distinct curves, you could set jgi.plot_char
  139.       to '*' for one set of points, then set it to '#' before calling JGRAF
  140.       with another set of points.
  141.  
  142.               JGI.COMMAND := 'D';
  143.               JGI.PLOT_CHAR := '*';
  144.               JGRAF ( JGI, 15.4, 199.2 );
  145.               JGRAF ( JGI, 15.9, 205.7 );
  146.               JGI.PLOT_CHAR := '#';
  147.               JGRAF ( JGI, 9.0, 105.0 );
  148.  
  149.            To print the graph on the console, set jgi.command  to  'C'  and
  150.       call JGRAF with x and y arguments zero, as
  151.  
  152.               JGI.COMMAND := 'C';
  153.               JGRAF ( JGI, 0.0, 0.0 );
  154.  
  155.            If  you  want  output  to  the  line  printer  as well as to the
  156.       console, set jgi.command to 'P' instead of 'C' before calling JGRAF.
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.       Copy compliments of Merle Schnick                 APPENDIX E:   JGRAF
  164. .PAè
  165.       JRT Pascal  User's Guide                         NOT FOR SALE   -180-
  166.  
  167.  
  168.  
  169.            To write the graph to a file, set jgi.filename  to  the  desired
  170.       name, jgi.command to 'S', and call JGRAF.
  171.  
  172.               JGI.FILENAME := 'B:PLOT.5';
  173.               JGI.COMMAND := 'S';
  174.               JGRAF ( JGI, 0.0, 0.0 );
  175.  
  176.            More data points can be added to a graph after printing, so that
  177.       development  or  trends  can  be  plotted in succession.  Further, by
  178.       setting jgi.plot_char to a space (' '), data  points  can  be  erased
  179.       (although grid lines will not be restored).
  180.  
  181.            If  you  want  to  print  more  than  one  graph  using the same
  182.       interface record (jgi) or want JGRAF to free the memory allocated  to
  183.       produce a graph, you can set jgi.command to 'X' before calling JGRAF.
  184.       This will free the buffers allocated by JGRAF (in the 'I' command).
  185.  
  186.            Note  that  every  call  to  JGRAF  that  is  not providing data
  187.       (jgi.command = 'D') should have the x and y arguments equal to 0.0.
  188.  
  189.            The body  of  the  sample  program  jg  is  included  here,  and
  190.       illustrates  one  use  of JGRAF.  Jg takes a disk file of commands as
  191.       input and produces one or more plots as directed.   Commands  on  the
  192.       disk  file are similiar to the options to JGRAF, with the addition of
  193.       two commands.  T followed by  'title'  may  preceed  the  I  command.
  194.       Period  (.)  followed  by a space and a new plot character will reset
  195.       the current plot character.
  196.  
  197.               begin  (* jg *)
  198.               write('General graphing input file: ');
  199.               readln(file_name);
  200.               reset(inf,file_name, text, 512);
  201.               jgi.title := ' ';
  202.               while (not eof(inf)) do
  203.                       begin
  204.                       read(inf; command);
  205.                       command := upcase(command);
  206.                       writeln('db ',command);
  207.                       jgi.command := command;
  208.                       case command of
  209.                       'T':    begin
  210.                               readln (inf; title);
  211.                               jgi.title := title;
  212.                               end;
  213.  
  214.  
  215.  
  216.  
  217.       Copy compliments of Merle Schnick                 APPENDIX E:   JGRAF
  218. .PAè
  219.       JRT Pascal  User's Guide                         NOT FOR SALE   -181-
  220.  
  221.  
  222.  
  223.                       'I':    begin
  224.                               readln (inf; jgi.rows, jgi.columns,
  225.                                       jgi.x_lower, jgi.x_upper,
  226.                                       jgi.y_lower, jgi.y_upper);
  227.                               jgi.plot_char := '*';
  228.                               jgi.x_grid := true;
  229.                               jgi.y_grid := true;
  230.                                       (* note that all required members *)
  231.                                       (* of jgi have been set *)
  232.                               jgraf(jgi, 0.0, 0.0);
  233.                               writeln(' done I');
  234.                               end;
  235.                       'D':    begin
  236.                               read(inf; x, y);
  237.                               jgraf(jgi, x, y);
  238.                               end;
  239.                       '.':    readln(inf; jgi.plot_char);
  240.                       'C':    jgraf(jgi, 0.0, 0.0);
  241.                       'P':    jgraf(jgi, 0.0, 0.0);
  242.                       'S':    begin
  243.                               readln(inf; file_name);
  244.                               jgi.filename := file_name;
  245.                               jgraf(jgi, 0.0, 0.0);
  246.                               end;
  247.                       'X':    jgraf(jgi, 0.0, 0.0);
  248.                       else:   writeln('Unrecognized command: ',command);
  249.                               end;
  250.                       end;
  251.               close(inf);
  252.               end.
  253.  
  254.       Given the input file SAMPLE.DAT as follows:
  255.  
  256.               T 'Sample'
  257.               I 20 40 0 40 0 60
  258.               D 5 6   D 6 10
  259.               D 7 12  D 8 15
  260.               D 9 16  D 10 16
  261.               . #
  262.               D 5 2   D 32 6
  263.               D 32 27
  264.               C
  265.               S sample.out
  266.               X
  267.  
  268.  
  269.  
  270.  
  271.       Copy compliments of Merle Schnick                 APPENDIX E:   JGRAF
  272. .PAè
  273.       JRT Pascal  User's Guide                         NOT FOR SALE   -182-
  274.  
  275.  
  276.  
  277.       Jg will produce the  (uninspired)  output file SAMPLE.OUT as follows,
  278.       given the input listed above.
  279.  
  280.  
  281.       JGRAF ver 3.0    **** Sample                ****
  282.  
  283.                60 -I---------I---------I---------I---------I
  284.                    I         I         I         I         I
  285.                    I         I         I         I         I
  286.                    I         I         I         I         I
  287.                    I         I         I         I         I
  288.                    I         I         I         I         I
  289.                    I         I         I         I         I
  290.                    I         I         I         I         I
  291.                    I         I         I         I         I
  292.                    I         I         I         I         I
  293.                30 -I---------I---------I---------I---------I
  294.                    I         I         I         I #       I 
  295.                    I         I         I         I         I
  296.                    I         I         I         I         I
  297.                    I         I         I         I         I
  298.                    I       ***         I         I         I
  299.                    I      *  I         I         I         I
  300.                    I     *   I         I         I         I
  301.                    I    *    I         I         I #       I
  302.                    I    #    I         I         I         I
  303.                 0 -I---------I---------I---------I---------I
  304.  
  305.                    0         10        20        30        40
  306.  
  307.  
  308.       A summary of the commands to JGRAF is included now for reference:
  309.  
  310.              code     meaning
  311.              ----     -----------
  312.               C       display graph on console
  313.               D       plot a data point
  314.               I       initialize graph buffer and axes
  315.               P       print graph
  316.               S       save graph on a disk file
  317.               X       delete graph buffer
  318.  
  319.  
  320.            The source code for JGRAF is provided and may be modified.   For
  321.       example,  the number of lines between the x_grid lines can be changed
  322.       to 6 (or to 8) so that the grid lines  form  a  one  inch  square  on
  323.       printers with 10 characters per inch and 6 (or 8) lines per inch.
  324.  
  325.       Copy compliments of Merle Schnick                 APPENDIX E:   JGRAF
  326. .PAè
  327.       JRT Pascal  User's Guide                         NOT FOR SALE   -183-
  328.  
  329.  
  330.  
  331.            JGRAF  is  not  limited  to  scatter  plots.   With  appropriate
  332.       selection of data points, histograms can be produced.  Contour  plots
  333.       (and even isometric drawings) are also possible.
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.       Copy compliments of Merle Schnick                 APPENDIX E:   JGRAF
  380. .PAè