Changeset 6f212c in git


Ignore:
Timestamp:
Apr 14, 2011, 12:23:58 PM (13 years ago)
Author:
Frank Seelisch <seelisch@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
2a8e216b3f6b1bd5e09a39259b6dbbfbf9805663
Parents:
0c0be739d66ec1afc78865376e3b4bb4bc2e96ef
Message:
commands plot and surfer finally work under Windows (fixes track ticket #208)

git-svn-id: file:///usr/local/Singular/svn/trunk@14162 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/surf.lib

    • Property mode changed from 100644 to 100755
    r0c0be73 r6f212c  
    11///////////////////////////////////////////////////////////////////////////////
    2 version="$Id$";
     2version="$Id: surf.lib 13499 2010-10-15 09:55:26Z hannes $";
    33category="Visualization";
    44info="
    55LIBRARY: surf.lib    Procedures for Graphics with Surf
    6 AUTHOR: Hans Schoenemann
     6AUTHOR: Hans Schoenemann, Frank Seelisch
    77
    88NOTE:
     
    6565ASSUME: I defines a plane curve or a surface given by one equation
    6666RETURN: nothing
    67 NOTE: requires the external program 'surf' to be installed,
    68       to close the graphical interface just press 'Q'
     67NOTE: requires the external program `surf` to be installed,
     68      to close the graphical interface just press `Q`
    6969EXAMPLE: example plot; shows an example
    7070"
     
    139139  }
    140140
    141   string surf_call;
    142 
     141  string surf_call; i = 0;
    143142  if (isWindows())
    144143  {
    145     surf_call = "((xwin -multiwindow -clipboard -silent-dup-error";
    146     surf_call = surf_call + " >/dev/null 2>&1 &) && sleep 5 && (surf";
    147     if (defined(extra_surf_opts))
    148     {
    149       surf_call = surf_call + " " + extra_surf_opts;
    150     }
    151     surf_call = surf_call + l + ">/dev/null 2>&1))";
    152     surf_call = surf_call + "&& /bin/rm " + l;
    153     "Press q to exit from 'surf'.";
    154     "(You may leave the XServer running for further invocations"
    155     + " of 'plot'.)";
    156     i = system("sh", surf_call);
     144    string surferPath = getShellOutput("which surfer");
     145    if (find(surferPath, "no surfer in") != 0)
     146    { /* did not find surfer: either not installed or
     147         not yet included in $PATH variable */
     148      err_mes = "calling `surfer` failed" + newline
     149      + " (Either the program Surfer is not installed," + newline
     150      + "  or it has not yet been included in $PATH.)";
     151      ERROR(err_mes);
     152    }
     153    else
     154    {
     155      surf_call = "((xwin -multiwindow -clipboard -silent-dup-error";
     156      surf_call = surf_call + " >/dev/null 2>&1 &) && sleep 5 && (surf";
     157      if (defined(extra_surf_opts))
     158      {
     159        surf_call = surf_call + " " + extra_surf_opts;
     160      }
     161      surf_call = surf_call + l + ">/dev/null 2>&1))";
     162      surf_call = surf_call + "&& /bin/rm " + l;
     163      "Press q to exit from `surf`.";
     164        " (You may leave the XServer running for further" + newline
     165      + "  invocations of `plot`.)";
     166      i = system("sh", surf_call);
     167      if (i != 0)
     168      {
     169        err_mes = "calling `surf` failed" + newline
     170                + " (The shell returned the error code "
     171                + string(i) + "." + newline
     172                + "  Perhaps the XServer was not properly set up, so" + newline
     173                + "  try your plot command again. If `plot` fails" + newline
     174                + "  again, then make sure that the program Surfer" + newline
     175                + "  is installed and included in your $PATH variable.)";
     176        ERROR(err_mes);
     177      }
     178    }
    157179  }
    158180  else
     
    165187    surf_call = surf_call + l + " >/dev/null 2>&1";
    166188
    167     if ("ppcMac-darwin" == system("uname"))
     189    if (system("uname") == "ppcMac-darwin")
    168190    {
    169191       surf_call = surf_call + " || " + "singularsurf "
     
    171193    }
    172194
    173     "Press q to exit from 'surf'";
     195    "Press q to exit from `surf`.";
    174196    i = system("sh", surf_call);
    175     system("sh", "/bin/rm " + l);
    176   }
    177 
    178   if (i != 0)
    179   {
    180     err_mes = "calling `surf` failed" + newline
     197    if (i != 0)
     198    {
     199      err_mes = "calling `surf` failed" + newline
    181200              + " (The shell returned the error code "
    182201              + string(i) + "." + newline
    183               + "Probably, the executable `surf` was not found.)";
    184     ERROR(err_mes);
    185   }
     202              + "  Make sure that the program Surfer is installed.)";
     203      ERROR(err_mes);
     204    }
     205  }
     206  system("sh", "/bin/rm " + l);
    186207}
    187208example
     
    215236
    216237}
     238
    217239proc surfer(ideal I)
    218240"USAGE:   surfer(f);  f poly
    219241ASSUME: f defines a surface given by one equation
    220242RETURN: nothing
    221 NOTE: requires the external program 'surfer' to be installed,
     243NOTE: requires the external program `surfer` to be installed,
    222244      to close the graphical interface just close the window of surfer
    223245EXAMPLE: example surfer; shows an example
    224246"
    225247{
    226   string l = "./surfer" + string(system("pid"));
     248  string lForWindows = "surfer" + string(system("pid"));
     249  string l = "./" + lForWindows;
    227250  string err_mes; // string containing error messages
    228251  def base=basering;
     
    263286    ERROR(err_mes);
    264287  }
    265   string surf_call;
    266 
    267   surf_call = "surfer";
    268   surf_call = surf_call + " " + l + " >/dev/null 2>&1";
    269   "Close window to exit from 'surfer'";
    270   i = system("sh", surf_call);
     288
     289  string surf_call; i = 0;
     290  if (isWindows())
     291  {
     292    string surferPath = getShellOutput("which surfer");
     293    if (find(surferPath, "no surfer in") != 0)
     294    { /* did not find surfer: either not installed or
     295         not yet included in $PATH variable */
     296      err_mes = "calling `surfer` failed" + newline
     297      + " (Either the program Surfer is not installed," + newline
     298      + "  or it has not yet been included in $PATH.)";
     299      ERROR(err_mes);
     300    }
     301    else
     302    {
     303      string singularPath = getShellOutput("pwd");
     304      surferPath = windowsCorrection(surferPath);
     305      surferPath = surferPath[1..size(surferPath)-size("/surfer")];
     306      singularPath = windowsCorrection(singularPath);
     307      singularPath = "c:"
     308         + singularPath[size("/cygdrive/c/")..size(singularPath)];
     309      surf_call = "cygstart -w -d " + surferPath + " ";
     310      surf_call = surf_call + surferPath + "/surfer ";
     311      surf_call = surf_call + singularPath + "/" + lForWindows;
     312      "Close window to exit from `surfer`.";
     313      i = system("sh", surf_call);
     314    }
     315  }
     316  else
     317  {
     318    surf_call = "surfer " + l + " >/dev/null 2>&1";
     319    "Close window to exit from `surfer`.";
     320    i = system("sh", surf_call);
     321  }
    271322  system("sh", "/bin/rm " + l);
    272323
     
    275326    err_mes = "calling `surfer` failed" + newline
    276327              + " (The shell returned the error code "
    277               + string(i) + "." + newline
    278               + "Probably, the executable `surfer` was not found.)";
     328              + string(i) + ".";
    279329    ERROR(err_mes);
    280330  }
     
    295345  // Whitney umbrella
    296346  surfer(z^2-x^2*y);
    297 
    298 }
    299 proc isWindows()
     347}
     348
     349static proc isWindows()
    300350"returns 1 if this SINGULAR instance runs under (some) Windows OS;
    3013510 otherwise"
     
    317367  return (0);
    318368}
     369
     370static proc getShellOutput(string shellCommand)
     371"returns the console output when executing the given shellCommand"
     372{
     373   int s;
     374   string tempFilename = "tmp" + string(system("pid"));
     375   s = system("sh", shellCommand + " > " + tempFilename + " 2>&1");
     376   string r1 = read(tempFilename);
     377   s = size(r1) - 1;
     378   string r2 = r1[1..s];
     379   s = system("sh", "/bin/rm " + tempFilename);
     380   return (r2);
     381}
     382
     383static proc windowsCorrection(string windowsPath)
     384"puts a backslash in front of each space and each special character
     385and returns the resulting string"
     386{
     387  string s = ""; int i;
     388  for (i = 1; i <= size(windowsPath); i++)
     389  {
     390    if (find(" ()", windowsPath[i]) != 0)
     391    {
     392      s = s + "\\";
     393    }
     394    s = s + windowsPath[i];
     395  }
     396  return (s);
     397}
    319398///////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.