From: Robbie M. <ro...@ac...> - 2011-03-09 17:32:58
|
Hello Thomas Many many thanks for this. I will try to test your patch this weekend and report back. with best wishes, Robbie > ------------------------------------------------------------ > To: gnu...@li... > Subject: Re: [Gnuplot-info] name of current script > Message-ID: <311...@ta...> > From: Thomas Sefzick <t.s...@fz...> > Date: Wed, 9 Mar 2011 09:03:45 -0800 (PST) > ------------------------------------------------------------ > > the best place to set such a variable would be the > 'load_file()' routine in 'misc.c'. > > two lines need to be added there: > > --- misc.c.orig 2011-03-08 15:15:32.240304167 +0100 > +++ misc.c 2011-03-09 18:00:13.300516216 +0100 > @@ -215,6 +215,8 @@ > lf_push(fp, name, NULL); /* save state for errors and recursion */ > do_load_arg_substitution = can_do_args; > > + fill_gpval_string("GPVAL_LOAD_FILE", name); > + > if (fp == (FILE *) NULL) { > os_error(c_token, "Cannot open %s file '%s'", > can_do_args ? "call" : "load", name); > @@ -286,6 +288,8 @@ > } > } > > + fill_gpval_string("GPVAL_LOAD_FILE", ""); > + > /* pop state */ > (void) lf_pop(); /* also closes file fp */ > } > > Robbie Morrison wrote: >> >> >> Hello all >> >> It would be rather useful if the current filename was >> available from within a gnuplot script. [snip - feature request] --- Robbie Morrison PhD student -- policy-oriented energy system simulation Technical University of Berlin (TU-Berlin), Germany University email (redirected) : mor...@ie... Webmail (preferred) : ro...@ac... [from Webmail client] |
From: Robbie M. <ro...@ac...> - 2011-03-22 10:37:43
|
Hello all First up, thanks Vinod for your suggestion of a bash wrapper script. Please note the following corrections: exho is echo, the OUT assignment (righthand-side) should be in backticks (`) not single-quotes ('), --persist should be -persist. I reworked the original script and tested it on Linux plus Gnuplot 4.2 patchlevel 6: --- src begin / bash -------- #! /bin/bash # usage message (optional) case "$1" in --help|--hel|--he|--h|-help|-hel|-he|-h|"-?") SCRIPT=$(basename "$0") echo " usage: $SCRIPT <gnuplot-cmds> create LOADFILE string and load gnuplot-cmds file" echo " $SCRIPT --help show this message and exit" exit 0 ;; "") SCRIPT=$(basename "$0") echo "$SCRIPT: gnuplot file name required (try --help for usage)" exit 2 esac # active code ARG1=$(basename "$1") # adapt these next two lines to your needs ARG1="$PWD/$ARG1" echo "LOADFILE = \"$ARG1\"; load '$1'" | gnuplot -persist ----src end ----------------- And tested it with the following gnuplot code: --- src begin / gnuplot ----- set title "source : " . LOADFILE # 'LOADFILE' is set by invoking script plot sin(x) --- src end ----------------- best wishes Robbie --- > ------------------------------------------------------------ > To: gnu...@li... > Subject: Re: [Gnuplot-info] name of current script > Message-ID: <311...@ta...> > From: vinodkgul <vin...@ya...> > Date: Sun, 20 Mar 2011 08:00:39 -0700 (PDT) > ------------------------------------------------------------ > > Hi, > > You can use the shell scrip As follows: > 1st file--> gnuplot_file_print.sh > exho $1 > OUT='echo $1 | cut -d "." -f1' > echo "set label 101 ' Path: `pwd` Filename : $OUT' ; load '$1' " | gnuplot --persist > > say test.gnu is the file containing the plot commands then from prompt use > following : > > sh gnuplot_file_print.sh test.gnu > > Vinod > > Robbie Morrison wrote: >> >> >> Hello all >> >> It would be rather useful if the current filename was >> available from within a gnuplot script. >> >> [snip - original posting] --- Robbie Morrison PhD student -- policy-oriented energy system simulation Technical University of Berlin (TU-Berlin), Germany University email (redirected) : mor...@ie... Webmail (preferred) : ro...@ac... [from Webmail client] |
From: Robbie M. <ro...@ac...> - 2011-06-25 21:40:13
|
Hello all, hi Thomas I can confirm the patch from Thomas Sefzick (see below) works for real files but not for 'stdin'. The patch allows the name of the current script to be recovered from within that script. I suggest the patch gets developed a little and transferred to the gnuplot mainline. Can someone therefore cross-post this message to the dev list please? TIA. The patch was tested on Ubuntu 10.04 (64-bit) / Linux 2.6.32-32-generic / gcc 4.4.3 / Intel Core i5-520M. Here are the build calls: $ ./configure --without-lua # 11 seconds $ make # 35 seconds The test script: $ cat gpval-load-file.gp show version print GPVAL_LOAD_FILE Some trials: $ src/gnuplot gpval-load-file.gp G N U P L O T Version 4.4 patchlevel 3 (with modifications by robbie) last modified June 2011 System: Linux 2.6.32-32-generic Copyright (C) 1986-1993, 1998, 2004, 2007-2010 Thomas Williams, Colin Kelley and many others gnuplot home: http://www.gnuplot.info faq, bugs, etc: type "help seeking-assistance" immediate help: type "help" plot window: hit 'h' gpval-load-file.gp However this patch fails if reading from 'stdin:' $ src/gnuplot < gpval-load-file.gp G N U P L O T Version 4.4 patchlevel 3 (with modifications by robbie) last modified June 2011 System: Linux 2.6.32-32-generic Copyright (C) 1986-1993, 1998, 2004, 2007-2010 Thomas Williams, Colin Kelley and many others gnuplot home: http://www.gnuplot.info faq, bugs, etc: type "help seeking-assistance" immediate help: type "help" plot window: hit 'h' line 0: undefined variable: GPVAL_LOAD_FILE After examining 'misc.c', I should imagine the fix to this problem would be straightforward. many thanks to Thomas, best wishes to all Robbie ------------------------------------------------------------ To: gnu...@li... Subject: Re: [Gnuplot-info] name of current script Message-ID: <311...@ta...> From: Thomas Sefzick <t.s...@fz...> Date: Wed, 9 Mar 2011 09:03:45 -0800 (PST) ------------------------------------------------------------ > the best place to set such a variable would be the > 'load_file()' routine in 'misc.c'. > > two lines need to be added there: > > --- misc.c.orig 2011-03-08 15:15:32.240304167 +0100 > +++ misc.c 2011-03-09 18:00:13.300516216 +0100 > @@ -215,6 +215,8 @@ > lf_push(fp, name, NULL); /* save state for errors and recursion */ > do_load_arg_substitution = can_do_args; > > + fill_gpval_string("GPVAL_LOAD_FILE", name); > + > if (fp == (FILE *) NULL) { > os_error(c_token, "Cannot open %s file '%s'", > can_do_args ? "call" : "load", name); > @@ -286,6 +288,8 @@ > } > } > > + fill_gpval_string("GPVAL_LOAD_FILE", ""); > + > /* pop state */ > (void) lf_pop(); /* also closes file fp */ > } > > Robbie Morrison wrote: >> >> >> Hello all >> >> It would be rather useful if the current filename was >> available from within a gnuplot script. >> >> This suggestion was raised in 2008 and 2009 >> respectively: >> >> >> http://groups.google.com/group/comp.graphics.apps.gnuplot/browse_thread/thread/2b34fa67a0365173/8f8c63c891f59aeb?lnk=gst&q=%22current+filename%22#8f8c63c891f59aeb >> >> http://groups.google.com/group/comp.graphics.apps.gnuplot/browse_thread/thread/781545ccfbaada56/ebffa12161a37fe3?lnk=gst&q=%22get+filename%22#ebffa12161a37fe3 >> >> And, AFAIK, has not been resolved. >> >> One approach might be: >> >> assume the file 'myfile.gp' contains the lines: >> >> myfile = GPVAL_LOAD_FILE >> print "myfile = ", myfile >> >> then entering the command: >> >> load "myfile.gp" >> >> would display either of the following -- the first >> being a simple echo and the second being the canonical >> file path: >> >> myfile = myfile.gp >> myfile = /path/to/myfile.gp >> >> On termination, GPVAL_LOAD_FILE would be unset. >> >> Another approach (probably too late) would have been >> to have the 'call' command assign the filename to $0 >> in line with most other shell positional variable >> conventions. >> >> If there is a work-around, that would be good to know. >> >> best wishes >> Robbie --- Robbie Morrison PhD student -- policy-oriented energy system simulation Technical University of Berlin (TU-Berlin), Germany University email (redirected) : mor...@ie... Webmail (preferred) : ro...@ac... [from Webmail client] |
From: Thomas S. <t.s...@fz...> - 2011-06-28 08:42:18
|
if there is no load file, then GPVAL_LOAD_FILE is undefined, i.e. not existing, and this can be tested using the 'exists()' function: if (exists("GPVAL_LOAD_FILE")) print GPVAL_LOAD_FILE Robbie Morrison wrote: > > > Hello all, hi Thomas > > I can confirm the patch from Thomas Sefzick (see below) > works for real files but not for 'stdin'. The patch > allows the name of the current script to be recovered > from within that script. I suggest the patch gets > developed a little and transferred to the gnuplot mainline. > Can someone therefore cross-post this message to the > dev list please? TIA. > > The patch was tested on Ubuntu 10.04 (64-bit) / Linux > 2.6.32-32-generic / gcc 4.4.3 / Intel Core i5-520M. > Here are the build calls: > > $ ./configure --without-lua # 11 seconds > $ make # 35 seconds > > The test script: > > $ cat gpval-load-file.gp > show version > print GPVAL_LOAD_FILE > > Some trials: > > $ src/gnuplot gpval-load-file.gp > > G N U P L O T > Version 4.4 patchlevel 3 (with modifications by robbie) > last modified June 2011 > System: Linux 2.6.32-32-generic > > Copyright (C) 1986-1993, 1998, 2004, 2007-2010 > Thomas Williams, Colin Kelley and many others > > gnuplot home: http://www.gnuplot.info > faq, bugs, etc: type "help seeking-assistance" > immediate help: type "help" > plot window: hit 'h' > > gpval-load-file.gp > > However this patch fails if reading from 'stdin:' > > $ src/gnuplot < gpval-load-file.gp > > G N U P L O T > Version 4.4 patchlevel 3 (with modifications by robbie) > last modified June 2011 > System: Linux 2.6.32-32-generic > > Copyright (C) 1986-1993, 1998, 2004, 2007-2010 > Thomas Williams, Colin Kelley and many others > > gnuplot home: http://www.gnuplot.info > faq, bugs, etc: type "help seeking-assistance" > immediate help: type "help" > plot window: hit 'h' > > line 0: undefined variable: GPVAL_LOAD_FILE > > After examining 'misc.c', I should imagine the fix to > this problem would be straightforward. > > many thanks to Thomas, best wishes to all > Robbie > > ------------------------------------------------------------ > To: gnu...@li... > Subject: Re: [Gnuplot-info] name of current script > Message-ID: <311...@ta...> > From: Thomas Sefzick <t.s...@fz...> > Date: Wed, 9 Mar 2011 09:03:45 -0800 (PST) > ------------------------------------------------------------ > >> the best place to set such a variable would be the >> 'load_file()' routine in 'misc.c'. >> >> two lines need to be added there: >> >> --- misc.c.orig 2011-03-08 15:15:32.240304167 +0100 >> +++ misc.c 2011-03-09 18:00:13.300516216 +0100 >> @@ -215,6 +215,8 @@ >> lf_push(fp, name, NULL); /* save state for errors and recursion */ >> do_load_arg_substitution = can_do_args; >> >> + fill_gpval_string("GPVAL_LOAD_FILE", name); >> + >> if (fp == (FILE *) NULL) { >> os_error(c_token, "Cannot open %s file '%s'", >> can_do_args ? "call" : "load", name); >> @@ -286,6 +288,8 @@ >> } >> } >> >> + fill_gpval_string("GPVAL_LOAD_FILE", ""); >> + >> /* pop state */ >> (void) lf_pop(); /* also closes file fp */ >> } >> >> Robbie Morrison wrote: >>> >>> >>> Hello all >>> >>> It would be rather useful if the current filename was >>> available from within a gnuplot script. >>> >>> This suggestion was raised in 2008 and 2009 >>> respectively: >>> >>> >>> http://groups.google.com/group/comp.graphics.apps.gnuplot/browse_thread/thread/2b34fa67a0365173/8f8c63c891f59aeb?lnk=gst&q=%22current+filename%22#8f8c63c891f59aeb >>> >>> http://groups.google.com/group/comp.graphics.apps.gnuplot/browse_thread/thread/781545ccfbaada56/ebffa12161a37fe3?lnk=gst&q=%22get+filename%22#ebffa12161a37fe3 >>> >>> And, AFAIK, has not been resolved. >>> >>> One approach might be: >>> >>> assume the file 'myfile.gp' contains the lines: >>> >>> myfile = GPVAL_LOAD_FILE >>> print "myfile = ", myfile >>> >>> then entering the command: >>> >>> load "myfile.gp" >>> >>> would display either of the following -- the first >>> being a simple echo and the second being the canonical >>> file path: >>> >>> myfile = myfile.gp >>> myfile = /path/to/myfile.gp >>> >>> On termination, GPVAL_LOAD_FILE would be unset. >>> >>> Another approach (probably too late) would have been >>> to have the 'call' command assign the filename to $0 >>> in line with most other shell positional variable >>> conventions. >>> >>> If there is a work-around, that would be good to know. >>> >>> best wishes >>> Robbie > --- > Robbie Morrison > PhD student -- policy-oriented energy system simulation > Technical University of Berlin (TU-Berlin), Germany > University email (redirected) : mor...@ie... > Webmail (preferred) : ro...@ac... > [from Webmail client] > > > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure contains a > definitive record of customers, application performance, security > threats, fraudulent activity and more. Splunk takes this data and makes > sense of it. Business sense. IT sense. Common sense.. > http://p.sf.net/sfu/splunk-d2d-c1 > _______________________________________________ > gnuplot-info mailing list > gnu...@li... > https://lists.sourceforge.net/lists/listinfo/gnuplot-info > > -- View this message in context: http://old.nabble.com/Re%3A-name-of-current-script-tp31928369p31944425.html Sent from the Gnuplot - User mailing list archive at Nabble.com. |
From: Robbie M. <ro...@ac...> - 2011-07-01 10:18:14
|
Hello Thomas, hello all I guess I was being a bit cryptic about my suggestion regarding input that was either redirected from 'stdin' or piped from another command. In this case, GPVAL_LOAD_FILE should be assigned "-". Which suggests that perhaps GPVAL_FILE would be a better name for this variable, because 'stdin' is a type of file in the sense it gets file descriptor 0. Can I recommend this concept gets developed and added to the mainline codebase. Hint! thanks Robbie ------------------------------------------------------------ To: gnu...@li... Subject: Re: [Gnuplot-info] name of current script Message-ID: <319...@ta...> From: Thomas Sefzick <t.s...@fz...> Date: Tue, 28 Jun 2011 01:42:11 -0700 (PDT) ------------------------------------------------------------ if there is no load file, then GPVAL_LOAD_FILE is undefined, i.e. not existing, and this can be tested using the 'exists()' function: if (exists("GPVAL_LOAD_FILE")) print GPVAL_LOAD_FILE Robbie Morrison wrote: > > Hello all, hi Thomas > > I can confirm the patch from Thomas Sefzick (see > below) works for real files but not for 'stdin'. The > patch allows the name of the current script to be > recovered from within that script. I suggest the > patch gets developed a little and transferred to the > gnuplot mainline. Can someone therefore cross-post > this message to the dev list please? TIA. [snip] --- Robbie Morrison PhD student -- policy-oriented energy system simulation Technical University of Berlin (TU-Berlin), Germany University email (redirected) : mor...@ie... Webmail (preferred) : ro...@ac... [from Webmail client] |
From: Robbie M. <ro...@ac...> - 2011-07-01 10:56:32
|
Hello Thomas, all To follow up on my early posting, here is a list of "GPVAL_[A-Za-z0-9_]*" strings in 4.4.3 codebase. Some may be commented out or in conditional code -- I did not check: GPVAL_ GPVAL_COMPILE_OPTIONS GPVAL_DATA GPVAL_DATA_ GPVAL_ERRMSG GPVAL_ERRNO GPVAL_LAST_PLOT GPVAL_LOAD_FILE GPVAL_MULTIPLOT GPVAL_NAME_WINDOWID GPVAL_NaN GPVAL_OUTPUT GPVAL_PATCHLEVEL GPVAL_PI GPVAL_PLOT GPVAL_PWD GPVAL_SPLOT GPVAL_TERM GPVAL_TERMINALS GPVAL_TERMOPTIONS GPVAL_TERM_ GPVAL_TERM_WINDOWID GPVAL_TERM_XMAX GPVAL_TERM_XMIN GPVAL_TERM_YMAX GPVAL_TERM_YMIN GPVAL_VERSION GPVAL_VIEW_ GPVAL_VIEW_MAP GPVAL_VIEW_ROT_X GPVAL_VIEW_ROT_Z GPVAL_VIEW_SCALE GPVAL_VIEW_ZSCALE GPVAL_X2_MAX GPVAL_X2_MIN GPVAL_X_MAX GPVAL_X_MIN GPVAL_Y2_MAX GPVAL_Y2_MIN GPVAL_Y_MAX GPVAL_Y_MIN GPVAL_pi And here is a list of what is available after simply opening gnuplot: $ gnuplot gnuplot> show variables all <edited and sorted> GPVAL_COMPILE_OPTIONS = <long list deleted> GPVAL_ERRMSG = "" GPVAL_ERRNO = 0 GPVAL_MULTIPLOT = 0 GPVAL_NaN = NaN GPVAL_OUTPUT = "" GPVAL_PATCHLEVEL = "3" GPVAL_PLOT = 0 GPVAL_PWD = "/home/robbie/synk/temp" GPVAL_SPLOT = 0 GPVAL_TERM = "wxt" GPVAL_TERMINALS = <long list deleted> GPVAL_TERMOPTIONS = "0" GPVAL_VERSION = 4.4 It would seem the suggestion of GPVAL_FILE would sit quite well with GPVAL_PWD. best wishes Robbie --- Robbie Morrison PhD student -- policy-oriented energy system simulation Technical University of Berlin (TU-Berlin), Germany University email (redirected) : mor...@ie... Webmail (preferred) : ro...@ac... [from Webmail client] |