Changeset 6f212c in git
- Timestamp:
- Apr 14, 2011, 12:23:58 PM (13 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 2a8e216b3f6b1bd5e09a39259b6dbbfbf9805663
- Parents:
- 0c0be739d66ec1afc78865376e3b4bb4bc2e96ef
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/surf.lib
-
Property
mode
changed from
100644
to100755
r0c0be73 r6f212c 1 1 /////////////////////////////////////////////////////////////////////////////// 2 version="$Id $";2 version="$Id: surf.lib 13499 2010-10-15 09:55:26Z hannes $"; 3 3 category="Visualization"; 4 4 info=" 5 5 LIBRARY: surf.lib Procedures for Graphics with Surf 6 AUTHOR: Hans Schoenemann 6 AUTHOR: Hans Schoenemann, Frank Seelisch 7 7 8 8 NOTE: … … 65 65 ASSUME: I defines a plane curve or a surface given by one equation 66 66 RETURN: nothing 67 NOTE: requires the external program 'surf'to be installed,68 to close the graphical interface just press 'Q'67 NOTE: requires the external program `surf` to be installed, 68 to close the graphical interface just press `Q` 69 69 EXAMPLE: example plot; shows an example 70 70 " … … 139 139 } 140 140 141 string surf_call; 142 141 string surf_call; i = 0; 143 142 if (isWindows()) 144 143 { 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 } 157 179 } 158 180 else … … 165 187 surf_call = surf_call + l + " >/dev/null 2>&1"; 166 188 167 if ( "ppcMac-darwin" == system("uname"))189 if (system("uname") == "ppcMac-darwin") 168 190 { 169 191 surf_call = surf_call + " || " + "singularsurf " … … 171 193 } 172 194 173 "Press q to exit from 'surf'";195 "Press q to exit from `surf`."; 174 196 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 181 200 + " (The shell returned the error code " 182 201 + 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); 186 207 } 187 208 example … … 215 236 216 237 } 238 217 239 proc surfer(ideal I) 218 240 "USAGE: surfer(f); f poly 219 241 ASSUME: f defines a surface given by one equation 220 242 RETURN: nothing 221 NOTE: requires the external program 'surfer'to be installed,243 NOTE: requires the external program `surfer` to be installed, 222 244 to close the graphical interface just close the window of surfer 223 245 EXAMPLE: example surfer; shows an example 224 246 " 225 247 { 226 string l = "./surfer" + string(system("pid")); 248 string lForWindows = "surfer" + string(system("pid")); 249 string l = "./" + lForWindows; 227 250 string err_mes; // string containing error messages 228 251 def base=basering; … … 263 286 ERROR(err_mes); 264 287 } 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 } 271 322 system("sh", "/bin/rm " + l); 272 323 … … 275 326 err_mes = "calling `surfer` failed" + newline 276 327 + " (The shell returned the error code " 277 + string(i) + "." + newline 278 + "Probably, the executable `surfer` was not found.)"; 328 + string(i) + "."; 279 329 ERROR(err_mes); 280 330 } … … 295 345 // Whitney umbrella 296 346 surfer(z^2-x^2*y); 297 298 } 299 proc isWindows()347 } 348 349 static proc isWindows() 300 350 "returns 1 if this SINGULAR instance runs under (some) Windows OS; 301 351 0 otherwise" … … 317 367 return (0); 318 368 } 369 370 static 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 383 static proc windowsCorrection(string windowsPath) 384 "puts a backslash in front of each space and each special character 385 and 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 } 319 398 /////////////////////////////////////////////////////////////////////////////// -
Property
mode
changed from
Note: See TracChangeset
for help on using the changeset viewer.