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. |