|
From: theozh <th...@gm...> - 2017-05-24 19:36:33
|
With the following commands (under Windows) I would like to plot several
datafiles located in several subdirectories, which obey a certain name
scheme.
FileList = system("dir /B /S Data*.dat")
plot for [FileName in FileList] FileName u 1:2 w l title FileName
However, with this, FileName always contains the full path,
e.g. C:\SubDir1\SubSubDir2\Test3\Blabla4\Data007.dat
which is not very helpful in the legend.
Any ideas how I can separate the path from the filename in gnuplot,
or even just extract what "*" was, e.g. the number "007"?
substr() will not work because subpaths can have different length.
Is there anything like regular expressions in gnuplot?
Thank you for any hints.
|
|
From: BBands <bb...@gm...> - 2017-05-24 19:46:34
|
There are some example of gnuplot's strong variable capabilities here that should solve your needs. http://gnuplot.sourceforge.net/demo/stringvar.html John On Wed, May 24, 2017 at 12:36 PM, theozh <th...@gm...> wrote: > With the following commands (under Windows) I would like to plot several > datafiles located in several subdirectories, which obey a certain name > scheme. > > FileList = system("dir /B /S Data*.dat") > plot for [FileName in FileList] FileName u 1:2 w l title FileName > > However, with this, FileName always contains the full path, > e.g. C:\SubDir1\SubSubDir2\Test3\Blabla4\Data007.dat > which is not very helpful in the legend. > > Any ideas how I can separate the path from the filename in gnuplot, > or even just extract what "*" was, e.g. the number "007"? > substr() will not work because subpaths can have different length. > Is there anything like regular expressions in gnuplot? > Thank you for any hints. > > > ------------------------------------------------------------ > ------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > gnuplot-info mailing list > gnu...@li... > Membership management via: https://lists.sourceforge.net/ > lists/listinfo/gnuplot-info > |
|
From: Ethan M. <eam...@gm...> - 2017-05-24 19:49:41
|
Assuming that the subdirectories are not themselves named Datasomething,
I'd use something like
chop(fullname) = fullname[ strstrt(fullname,"Data") : * ]
plot for [FileName in FileList] FileName u 1:2 w l title chop(FileName)
On Wed, May 24, 2017 at 12:36 PM, theozh <th...@gm...> wrote:
> With the following commands (under Windows) I would like to plot several
> datafiles located in several subdirectories, which obey a certain name
> scheme.
>
> FileList = system("dir /B /S Data*.dat")
> plot for [FileName in FileList] FileName u 1:2 w l title FileName
>
> However, with this, FileName always contains the full path,
> e.g. C:\SubDir1\SubSubDir2\Test3\Blabla4\Data007.dat
> which is not very helpful in the legend.
>
> Any ideas how I can separate the path from the filename in gnuplot,
> or even just extract what "*" was, e.g. the number "007"?
> substr() will not work because subpaths can have different length.
> Is there anything like regular expressions in gnuplot?
> Thank you for any hints.
>
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> gnuplot-info mailing list
> gnu...@li...
> Membership management via: https://lists.sourceforge.net/
> lists/listinfo/gnuplot-info
>
|
|
From: theozh <th...@gm...> - 2017-05-25 13:17:20
|
Thanks, John & Ethan for your immediate response. > There are some example of gnuplot's strong variable capabilities here that > should solve your needs. > http://gnuplot.sourceforge.net/demo/stringvar.html > @John, thanks for the link, but strong string variable capabilities? Are you serious? It would be nice to find the last key (e.g. '\') in a word. Or at least a function to reverse a string. Best would be of course regular expressions ;-). > Assuming that the subdirectories are not themselves named Datasomething, Well, I cannot be sure that this will always be the case. > I'd use something like > > chop(fullname) = fullname[ strstrt(fullname,"Data") : * ] > > plot for [FileName in FileList] FileName u 1:2 w l title chop(FileName) > @Ethan, yes, this works with the above mentioned limitations. Based on your suggestion, the following is a cumbersome workaround for a function to extract the file name (at least to 6 levels of subdirectories, but can be extended). TestFile = 'C:\sub1\sub2\sub3\sub4\Data007.dat' chop1(FullName) = FullName[strstrt(FullName,'\')+1:*] chop2(FullName) = chop1(FullName)[strstrt(chop1(FullName),'\')+1:*] chop3(FullName) = chop2(FullName)[strstrt(chop2(FullName),'\')+1:*] chop4(FullName) = chop3(FullName)[strstrt(chop3(FullName),'\')+1:*] chop5(FullName) = chop4(FullName)[strstrt(chop4(FullName),'\')+1:*] chop6(FullName) = chop5(FullName)[strstrt(chop5(FullName),'\')+1:*] chop(FullName) = chop6(FullName)[strstrt(chop6(FullName),'\')+1:*] FileName = chop(TestFile) print FileName If anybody knows a more elegant or smarter solution, please let me know. |
|
From: BBands <bb...@gm...> - 2017-05-25 15:16:46
|
Er, that was a typo. I meant to write 'string variables'.
John
On Thu, May 25, 2017 at 6:17 AM, theozh <th...@gm...> wrote:
> Thanks, John & Ethan for your immediate response.
>
> > There are some example of gnuplot's strong variable capabilities here
> that
> > should solve your needs.
> > http://gnuplot.sourceforge.net/demo/stringvar.html
> >
>
> @John, thanks for the link, but strong string variable capabilities? Are
> you serious?
> It would be nice to find the last key (e.g. '\') in a word. Or at least
> a function to reverse a string. Best would be of course regular
> expressions ;-).
>
|
|
From: thse <t.s...@fz...> - 2017-05-25 14:32:36
|
> If anybody knows a more elegant or smarter solution, please let me know. Call the function recursively: TestFile = 'C:\sub1\sub2\sub3\sub4\Data007.dat' chop(fn) = strstrt(fn,'\')?chop(fn[strstrt(fn,'\')+1:*]):fn print chop(TestFile) -- View this message in context: http://gnuplot.10905.n7.nabble.com/Extract-filename-tp20651p20657.html Sent from the Gnuplot - User mailing list archive at Nabble.com. |
|
From: theozh <th...@gm...> - 2017-05-25 18:29:02
|
Thanks a lot, Thomas, that's probably the shortest and most elegant way
to do it.
I was not aware that recursive functions are possible.
The following code will give only the content of the wildcard in the
title/legend/key.
### start code
BeforeWC = "Data"
AfterWC = ".dat"
FileList = system("dir /B /S ".BeforeWC."*".AfterWC)
chop(fn) = strstrt(fn,'\')?chop(fn[strstrt(fn,'\')+1:*]):fn
Wildcard(fn) = chop(fn)[strlen(BeforeWC)+1:strlen(chop(fn))-strlen(AfterWC)]
plot for [FileName in FileList] FileName u 1:2 w l title
Wildcard(FileName) noenhanced
### end code
If anybody has again a smarter solution please let me know.
Are there any chances (now or in the future) to somehow use "Regular
expressions" in gnuplot?
Thanks, Theo.
|
|
From: Ethan M. <eam...@gm...> - 2017-05-25 23:56:39
|
On Thu, May 25, 2017 at 11:28 AM, theozh <th...@gm...> wrote: > > Are there any chances (now or in the future) to somehow use "Regular > expressions" in gnuplot? > Thanks, Theo. > > Can you fill in that idea a bit? Do you envision this as a binary test 'does string A match regexp B? yes/no'? Something more complicated? |
|
From: theozh <th...@gm...> - 2017-05-26 05:16:55
|
> >> Can you fill in that idea a bit? Do you envision this as a binary test > 'does string A match regexp B? yes/no'? Something more complicated? > Honestly, it's not thought through thoroughly. Just when trying to extract the filename from the full filename I thought it would be nice if in above example an expression something like |.*\\Data(.*)\.dat| directly returned the "007". Well, now I have a rather compact solution. On the otherhand, when creating a list of data files to be plotted it would be nice if the search pattern in FileList = system(dir /B /S Data*.dat) could be a bit more sophisticated than a simple wildcard. I know that this is a Windows system command and gnuplot doesn't have any influence on it. Although, gnuplot could filter it further and/or "distribute" the files to sublists which are then plotted in a single plot or multiplot environment. I need to find a practical example to illustrate. But probably one can also find a solution with the already existing gnuplot commands. I guess a binary regexp test together with the ternary operator could be quite powerful. Well, as I said, it's not fully thought out... |