rgpcsl.red 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. module rgpcsl.red; % REDUCE-gnuplot configuration for CSL
  2. %
  3. % The file complements the (notionally) generic file "gnuplot.red" to
  4. % provide system-specific interfaces between REDUCE and the gnuplot
  5. % package itself.
  6. % A C Norman. 1996
  7. global '(plottemp!* plotdir!* dirchar!* opsys!* tempdir!*);
  8. symbolic procedure channelflush x;
  9. << x := wrs x; flush(); wrs x >>;
  10. symbolic procedure gtmpnam base;
  11. if null tempdir!* then base
  12. else compress ('!" . append(explodec tempdir!*,
  13. car explodec dirchar!* . cdr explode base));
  14. % In general I want the initialisation actions indicated here to be
  15. % obeyed at load-time. I achieve this by packaging them all inside
  16. % a function, which I then call. I could be even more CSL-specific by
  17. % using eval-when style options imported from the Common Lisp world...
  18. symbolic procedure init_gnuplot();
  19. <<
  20. !*plotpause := -1; % wait for newline from user
  21. % plotcleanup!* is a list of commands to be obeyed after a gnuplot run.
  22. % it is mainly needed to get rid of the data file (used even when pipes
  23. % are available).
  24. plotcleanup!* := {};
  25. tempdir!* := getenv 'tmp;
  26. if null tempdir!* then tempdir!* := getenv 'temp;
  27. dirchar!* := "/";
  28. plotcommand!* := "gnuplot";
  29. opsys!* := assoc('opsys, lispsystem!*);
  30. if null opsys!* then opsys!* := 'unknown
  31. else opsys!* := cdr opsys!*;
  32. % If a shell variable "gnuplot" is set it is expected to be the
  33. % directory within which gnuplot binaries can be found.
  34. plotdir!* := getenv "gnuplot";
  35. % Otherwise, and this is what I hope and expect to happen more often, I
  36. % will expect to find gnuplot in the same directory that REDUCE was
  37. % loaded from. This will all work wonderfully under Windows, but under Unix
  38. % there is a much greater chance that I will need to set an environment
  39. % variable "gnuplot".
  40. if null plotdir!* and not (opsys!* = 'unix) then
  41. plotdir!* := get!-lisp!-directory();
  42. if opsys!* = 'win32 then <<
  43. % For Microsoft Windows use I try to use "wgnuplot" rather than "gnuplot",
  44. % and the options provided are copied from the PSL case above.
  45. plotcommand!* := "wgnuplot";
  46. plotheader!* := "";
  47. dirchar!* := "\";
  48. plotdta!* := for each n in
  49. {"gnutmp.tm1", "gnutmp.tm2", "gnutmp.tm3", "gnutmp.tm4",
  50. "gnutmp.tm5", "gnutmp.tm6", "gnutmp.tm7", "gnutmp.tm8"}
  51. collect gtmpnam n;
  52. plotcleanup!* := if null tempdir!* then {"erase gnutmp.tm*"}
  53. else {bldmsg("erase %w\gnutmp.tm*", tempdir!*)} >>
  54. else if opsys!* = 'msdos then <<
  55. % Under MSDOS the PSL version sets a VGA screen explicitly - that seems to
  56. % upset the version of gnuplot that I have to test. Also I find "tmpnam"
  57. % somewhat unhelpful, I can do a bit better (I hope) here.
  58. plotheader!* := ""; % ?? "set term vga";
  59. dirchar!* := "\";
  60. plotdta!* := for each n in
  61. {"gnutmp.tm1", "gnutmp.tm2", "gnutmp.tm3", "gnutmp.tm4",
  62. "gnutmp.tm5", "gnutmp.tm6", "gnutmp.tm7", "gnutmp.tm8"}
  63. collect gtmpnam n;
  64. plotcmds!*:= gtmpnam "gnutmp.tm0";
  65. plotcleanup!* := if null tempdir!* then {"erase gnutmp.tm*"}
  66. else {bldmsg("erase %w\gnutmp.tm*", tempdir!*)} >>
  67. else if opsys!* = 'riscos then <<
  68. % Under RiscOS I need to be running under the window system for GNUPLOT
  69. % to be available. I will not test for that here but will expect the
  70. % "PLOT" command to fail if run from the command line.
  71. plotheader!* := "";
  72. dirchar!* := ".";
  73. plotdta!* := for i:=1:10 collect tmpnam();
  74. plotcmds!*:= tmpnam();
  75. plotcleanup!* :=
  76. bldmsg("remove %w", plotcmds!*) .
  77. for each f in plotdta!* collect bldmsg("remove %w", f)
  78. >>
  79. else if opsys!* = 'unix then <<
  80. % For Unix I assume X11.
  81. plotheader!* := "set term x11";
  82. plotdta!* := for i:=1:10 collect tmpnam();
  83. plotcmds!*:= tmpnam();
  84. plotcleanup!* :=
  85. bldmsg("rm %w", plotcmds!*) .
  86. for each f in plotdta!* collect bldmsg("rm %w", f) >>
  87. else <<
  88. % Other systems set up for a dumb terminal. This is probably unsatisfactory,
  89. % but you can easily change the source here to adjust for what you want.
  90. % If you just comment out the "rederr" line you will have gnuplot working
  91. % in dumb-terminal mode.
  92. rederr bldmsg("gnuplot for %w not available yet", opsys!*);
  93. plotdta!* := for i:=1:10 collect tmpnam();
  94. plotcmds!*:= tmpnam();
  95. plotheader!* := "set term dumb" >>;
  96. % If there are no pipes available gnuplot will need a command-line
  97. % argument indicating where its input file is.
  98. if 'pipes member lispsystem!* then !*plotusepipe:=t
  99. else plotcommand!* := bldmsg("%w %w", plotcommand!*, plotcmds!*);
  100. % If I have a directory to look for gnuplot in I either just give a
  101. % full path or (under Unix) I temporarily switch current directories
  102. % to there.
  103. if plotdir!* then
  104. plotcommand!* := bldmsg("%w%w%w",
  105. plotdir!*, dirchar!*, plotcommand!*);
  106. % Under Windows 95 I want the plotting sub-task to finish before I
  107. % resume running REDUCE (and delete the temporary files). This may be an
  108. % area where Windows 95 and NT are not compatible. If so tough luck for now.
  109. % Actually if I am going to call wgnuplot rather than gnuplot this is
  110. % not a useful thing to do after all...
  111. % if 'win95 member lispsystem!* then
  112. % plotcommand!* := bldmsg("start /w %w", plotcommand!*);
  113. nil >>;
  114. init_gnuplot();
  115. endmodule;
  116. end;