From: LukasP <LP...@po...> - 2010-07-15 13:47:00
|
Hello, is there a built-in string replacing function? a = replace("ABC\\XYZ", "\\", "/") # a -> "ABC/XYZ" It would be very useful especially when migrating between Linux and Win apps as Linux uses "/" as directory separator but Windows use "\". Sometimes I pass an argument to a gnuplot script which represents a file name and it must contain "\\" due to Win command line, but later I'd need to perform the above replacement. Is there a possibility? Thanks. -- View this message in context: http://old.nabble.com/Function-%22replace%22-for-strings--tp29173139p29173139.html Sent from the Gnuplot - Dev mailing list archive at Nabble.com. |
From: Tait <gnu...@t4...> - 2010-07-17 01:58:09
|
> Sometimes I pass an argument to a gnuplot script which represents a file > name and it must contain "\\" due to Win command line, but later I'd need to > perform the above replacement. Just use / as a directory separator in all cases. Windows allows this. |
From: LukasP <LP...@po...> - 2010-07-17 17:07:35
|
It doesn't work in all cases. Let's have "~" directory in the current directory. The command xcopy ~\*.* ~~\*.* is OK in Windows, but xcopy ~/*.* ~~/*.* is not (error: "Invalid number of parameters"). It seems Wins treat such parameters like switches, which are usually prefixed by "/". Anyway, don't you think the "replace" function would be useful? LuP Tait wrote: > > Just use / as a directory separator in all cases. Windows allows this. > -- View this message in context: http://old.nabble.com/Function-%22replace%22-for-strings--tp29173139p29192627.html Sent from the Gnuplot - Dev mailing list archive at Nabble.com. |
From: Marek P. <ma...@du...> - 2010-07-18 11:23:28
|
Nazdar, > Anyway, don't you think the "replace" function would be useful? personally, I think it would not. The valuable property of Gnuplot is, that it is not a huge wannabe almighty package like SciLab or Emacs, but a very clever bounded set of features around plotting. I think your feature-request is similar to this older one: http://marc.info/?l=gnuplot-info&m=109472624100968&w=2 ..and the right answer is, IMHO, the very same. At se dari, Marek |
From: Tatsuro M. <tma...@ya...> - 2010-07-19 23:26:43
|
Hello The windows console prompt and almost console commands do not accept '/' as a path separator. See d:\usr\Tatsu>cd d:/usr The system cannot find the path specified. d:\usr\Tatsu>cd d:\usr D:\usr> Therefore replacement of '/' by '\' as path separator sometimes are really required on windows. BTW, the gnuplot prompt accepts '/' as path sepearator. See; gnuplot> cd 'd:/usr' gnuplot> pwd d:\usr In the almost programing languages working on windows accept '/' as a path separator. Regards Tatsuro --- Tait wrote: > > Sometimes I pass an argument to a gnuplot script which represents a file > > name and it must contain "\\" due to Win command line, but later I'd need to > > perform the above replacement. > > Just use / as a directory separator in all cases. Windows allows this. > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > gnuplot-beta mailing list > gnu...@li... > https://lists.sourceforge.net/lists/listinfo/gnuplot-beta > -------------------------------------- Get the new Internet Explorer 8 optimized for Yahoo! JAPAN http://pr.mail.yahoo.co.jp/ie8/ |
From: Tatsuro M. <tma...@ya...> - 2010-07-20 03:07:15
|
This post is just an error correction. Term in 'path separator' in the following is to be 'directory separator'. Regards Tatsuro --- Tatsuro MATSUOKA wrote: > Hello > > The windows console prompt and almost console commands do not accept '/' as a path separator. > > See > d:\usr\Tatsu>cd d:/usr > The system cannot find the path specified. > > d:\usr\Tatsu>cd d:\usr > > D:\usr> > > Therefore replacement of '/' by '\' as path separator sometimes are really required on windows. > > BTW, the gnuplot prompt accepts '/' as path sepearator. > See; > gnuplot> cd 'd:/usr' > gnuplot> pwd > d:\usr > > In the almost programing languages working on windows accept '/' as a path separator. > > Regards > > Tatsuro > > --- Tait wrote: > > > > Sometimes I pass an argument to a gnuplot script which represents a file > > > name and it must contain "\\" due to Win command line, but later I'd need to > > > perform the above replacement. > > > > Just use / as a directory separator in all cases. Windows allows this. > > > > > > > > ------------------------------------------------------------------------------ > > This SF.net email is sponsored by Sprint > > What will you do first with EVO, the first 4G phone? > > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > > _______________________________________________ > > gnuplot-beta mailing list > > gnu...@li... > > https://lists.sourceforge.net/lists/listinfo/gnuplot-beta > > > > > -------------------------------------- > Get the new Internet Explorer 8 optimized for Yahoo! JAPAN > http://pr.mail.yahoo.co.jp/ie8/ > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > gnuplot-beta mailing list > gnu...@li... > https://lists.sourceforge.net/lists/listinfo/gnuplot-beta > -------------------------------------- Get the new Internet Explorer 8 optimized for Yahoo! JAPAN http://pr.mail.yahoo.co.jp/ie8/ |
From: Petr M. <mi...@ph...> - 2010-07-19 13:40:18
|
> is there a built-in string replacing function? > a = replace("ABC\\XYZ", "\\", "/") # a -> "ABC/XYZ" you can use the following: # replace "o" by "XYZ": a="hello world" b="echo ".a." | sed s=o=XYZ=g" c=system(b) print c => it prints: hellXYZ wXYZrld > It would be very useful especially when migrating between Linux and Win apps > as Linux uses "/" as directory separator but Windows use "\". This is not needed if gnuplot is compiled by a gcc-based suite on Windows; thus use always "/". --- Petr Mikulik |
From: Tatsuro M. <tma...@ya...> - 2010-07-20 03:39:20
|
Hello --- Petr Mikulik wrote: > This is not needed if gnuplot is compiled by a gcc-based suite on Windows; > thus use always "/". Even in the MSVC, '/' can be used as a directory separator. I have confirmed the above on the MSVC++ express 2008. So the gnuplot binaries built by MSVC '/' can be used. gnuplot> cd 'd:/usr' gnuplot> pwd d:\usr gnuplot> I have confirmed using the binaries provided by Kakuto, which are prepared by the MSVC toolkits. http://www.ring.gr.jp/pub/text/TeX/ptex-win32/w32/gnuplot-45pl0w32.zip In addition, the MinGW version of gcc can understand '\' as a directory separator. Therefore gnuplot binaries built by gcc (e.g. official distribution), we can aloso use '\' gnuplot> cd 'd:\usr' gnuplot> pwd d:\usr Regards Tatsuro -------------------------------------- Get the new Internet Explorer 8 optimized for Yahoo! JAPAN http://pr.mail.yahoo.co.jp/ie8/ |
From: LukasP <LP...@po...> - 2010-07-19 06:41:29
|
Hello, agree with that gnuplot is highly capable plot processor and it is its primary purpose. But gnuplot provides some programming functionality and some string functions for it - strlen, strstrt, substr etc. - so I think one function for doing string replacements would be useful. And I mean simple string-for-string replacement, not wild char matching or regexs (e.g. strrepl("abcd", "bc", "+BC+") -> "a+BC+d"). As for your link for the similar question - I know there are possibilities how to solve problem - I can still pass more arguments to gnuplot where one contains string with "\"s and the other with "/"s; and these args are prepared by another program. But I'd rather pass only one argument which would be processed later in gnuplot; it seems to me simpler and a bit more elegant. Zdar LuP Marek Peca wrote: > > Nazdar, > >> Anyway, don't you think the "replace" function would be useful? > > personally, I think it would not. The valuable property of Gnuplot is, > that it is not a huge wannabe almighty package like SciLab or Emacs, but a > very clever bounded set of features around plotting. > > I think your feature-request is similar to this older one: > http://marc.info/?l=gnuplot-info&m=109472624100968&w=2 > > ..and the right answer is, IMHO, the very same. > > > At se dari, > Marek > -- View this message in context: http://old.nabble.com/Function-%22replace%22-for-strings--tp29173139p29201826.html Sent from the Gnuplot - Dev mailing list archive at Nabble.com. |
From: Tait <gnu...@t4...> - 2010-07-20 01:59:06
|
> ... > But gnuplot provides some programming functionality and some string > functions for it - strlen, strstrt, substr etc. - so I think one function > for doing string replacements would be useful. ... Gnuplot is a plotting program, not a scripting (or data manipulation) language. Where then, to draw the line between the two? This is just my opinion, but the further we go toward scripting, the more difficult we make it for ourselves. Nobody developing gnuplot is a language designer I suspect, and scripting is done far better by any number of other utilities, from fortran to Perl to the GNU scientific computing libraries. I find the scripting-like syntax and utilities available now in gnuplot (e.g. for and string variables) to be brittle and unintuitive. It's limited to specific pre-conceived use cases and users will always find new, unexpected usages. Gnuplot adapts to these poorly. If we want script-like utility, we'd be better to make gnuplot interface easily to existing tools, instead of re-inventing the wheel ourselves. It's common that people ask whether gnuplot can internally sort their data; extract parameters from the data, to be used in other aspects of the plot; do complicated logic evaluation; or to repeat the same thing slightly differently for data sets involving thousands of plots. Once past a low level of complexity, I always advise these people to stop treating gnuplot like a language and start treating it like a purpose-specific tool. Use a more flexible, general-purpose tool like Ruby to handle sorting, data analysis, and logic. Have Ruby generate a script file gnuplot can understand, and use the Ruby layer to handle all the arbitrary complexity. This works better, because Ruby has access to more inputs (filesystem, network, ...) and can support unlimited abstraction, arbitrary expressions, logic, and linking into other utilities in a way gnuplot never will. I've picked Ruby rather arbitrarily here; plenty of other languages can do the same. data (mess) -> scripting language -> plot file -> gnuplot -> output rather than data (mess) -> plot file (try to handle mess) -> gnuplot -> output String replacement is a low hurdle at which to require introducing the scripting language layer, but there are many more potential uses of search-and-replace than just substitution within a string variable like var2=replace(var1, "foo", "bar"). Take string substitution within commands for example, set title font replace(<stuff>), or set key autotitle columnheader replace(<stuff>). The scope of the change quickly becomes significant, with potential to misparse a legit command increasing. Limiting string substitution to the first example invites questions from confused users about why it works in one context and not another, a type of question I see too often already. Pushing gnuplot a little closer to being a poor scripting language is not the right answer here, I think. |
From: <pl...@pi...> - 2010-07-20 08:05:50
|
On 07/19/10 08:41, LukasP wrote: > > Hello, > > agree with that gnuplot is highly capable plot processor and it is its > primary purpose. > > But gnuplot provides some programming functionality and some string > functions for it - strlen, strstrt, substr etc. - so I think one function > for doing string replacements would be useful. And I mean simple > string-for-string replacement, not wild char matching or regexs (e.g. > strrepl("abcd", "bc", "+BC+") -> "a+BC+d"). > > As for your link for the similar question - I know there are possibilities > how to solve problem - I can still pass more arguments to gnuplot where one > contains string with "\"s and the other with "/"s; and these args are > prepared by another program. But I'd rather pass only one argument which > would be processed later in gnuplot; it seems to me simpler and a bit more > elegant. > > Zdar > > LuP > > > Marek Peca wrote: >> >> Nazdar, >> >>> Anyway, don't you think the "replace" function would be useful? >> >> personally, I think it would not. The valuable property of Gnuplot is, >> that it is not a huge wannabe almighty package like SciLab or Emacs, but a >> very clever bounded set of features around plotting. >> >> I think your feature-request is similar to this older one: >> http://marc.info/?l=gnuplot-info&m=109472624100968&w=2 >> >> ..and the right answer is, IMHO, the very same. >> >> >> At se dari, >> Marek >> > Firstly , please don't top post when replying , it makes discussions hard to follow. Isn't the simplest solution here to use gnuplot's system() command to call some external utility like sed or awk to do the substitution? If this is just for labels why request a mod for what can done with existing code in a trivial amount of time. regards |
From: LukasP <LP...@po...> - 2010-07-19 14:32:06
|
... There's no doubt there are possibilities how to convert \ to /. The solution suggested bellow is usable on Linux, but not in Windows - when I need to convert hundreds of datafiles under Windows to png and when I use command "dir /s /b *.dat", I get a list where "\" is used as directory separator in file path. Personally - on Windows - I use an ("ultra-easy") bksl2sl.exe utility, which reads stdin, each occurance of "\" replaces by "/" and writes bytes to stdout. It works, although its "non-standard". Petr Mikulik wrote: > >> is there a built-in string replacing function? >> a = replace("ABC\\XYZ", "\\", "/") # a -> "ABC/XYZ" > > you can use the following: > > # replace "o" by "XYZ": > a="hello world" > b="echo ".a." | sed s=o=XYZ=g" > c=system(b) > print c > > => it prints: > hellXYZ wXYZrld > ... OK, I treat it as a possibility which works on Linux; it doesn't work on Windows. IMHO, I don't think it's the way of best performance - to create new process, wait for the pipe until it is broken and the take the result. When converting a large number of files, a built-in replacing function should be much quicker, don't you think? Petr Mikulik wrote: > >> It would be very useful especially when migrating between Linux and Win >> apps >> as Linux uses "/" as directory separator but Windows use "\". > > This is not needed if gnuplot is compiled by a gcc-based suite on Windows; > thus use always "/". > > --- > Petr Mikulik > ... Personally, no problem with using "/" for directory separator (and "-" for command option). But it's otherwise on Windows - its commands use "\" for path description and "/" as command separator; I cann't do nothing with that. LuP -- View this message in context: http://old.nabble.com/Function-%22replace%22-for-strings--tp29173139p29205345.html Sent from the Gnuplot - Dev mailing list archive at Nabble.com. |
From: Petr M. <mi...@ph...> - 2010-07-20 15:42:05
|
> Personally - on Windows - I use an ("ultra-easy") bksl2sl.exe utility, which > reads stdin, each occurance of "\" replaces by "/" and writes bytes to > stdout. It works, although its "non-standard". Then it's exactly what the standard tr or sed can do. > > c=system(b) > ... OK, I treat it as a possibility which works on Linux; it doesn't work on > Windows. It does; however, you have to run pipe-enabled gnuplot, i.e. gnuplot.exe or wgnuplot_pipes.exe (see README.Windows). > IMHO, I don't think it's the way of best performance - to create new > process, wait for the pipe until it is broken and the take the result. When > converting a large number of files, a built-in replacing function should be > much quicker, don't you think? You can read all of them at once; and then use words() and word() functions to step through the file list, e.g. if (!exist('a')) a=system('dir *.dat | bksl2sl'); n=words(a); k=1 plot word(a,k) pause 2 k=k+1 if (k<=n) reread --- PM |