|
From: Dieter J. <die...@t-...> - 2008-03-28 19:23:54
|
Dear listmembers,
is there any means to delete a variable you are using in a script?
Say, you have the variable
L=<somevalue>
at the beginning of a gnuplot - scriptfile. You reach the end of this file and
you would like to say
unset L (but this definitively does not work)
is there any means to achieve this? The reason why I am asking is the feature
of emacs-gnuplot mode and octave to keep an open gnuplot session. If you have
some condition like
if (exists (L)) <do something>
in your script, this only works the very fist time you source the script,
because from then on the variable is defined.
Maybe someone has a workaround, I did not find one, maybe there's a way to
delete the variable and I didn't find either.
Thanks for looking into this,
take care
Dieter Jurzitza
--
-----------------------------------------------------------
|
\
/\_/\ |
| ~x~ |/-----\ /
\ /- \_/
^^__ _ / _ ____ /
<°°__ \- \_/ | |/ | |
|| || _| _| _| _|
if you really want to see the pictures above - use some font
with constant spacing like courier! :-)
-----------------------------------------------------------
|
|
From: Dieter J. <die...@t-...> - 2008-04-04 19:33:46
|
Dear listmembers,
dear Thomas,
this is just to let you know that I worked hard through this week using the
new "delete <VARIABLENAME>" function intensively. It works like a charm, I
never noticed any issue.
I would be glad if this patch could find it's way into "official" gnuplot CVS.
One additional thing I found and would be glad to see:
if you use a configuration file, say
.myconfig
and you want to load it at the beginning of your script to initialize some
variables, the file _must_ be present in order to make gnuplot work on.
IMHO it would be great to have an option to load the file if present and
ignore it if not present, maybe a new command like "loadcfg", maybe the old
command issuing a message but not stopping gnuplot as is now. Such a kind of
functionality is only available for .gnuplot in your home-directory so far,
IMHO ".gnuplot" should be kept for "general" options rather than "specific"
script options.
I solve this currently via a preceeding command:
system ("test ! -f <filename> && touch <filename>")
load "<filename>
but this is only working in a linux/unix environment and thus not portable.
Any comments?
Thank you very much,
take care
Dieter Jurzitza
--
-----------------------------------------------------------
|
\
/\_/\ |
| ~x~ |/-----\ /
\ /- \_/
^^__ _ / _ ____ /
<°°__ \- \_/ | |/ | |
|| || _| _| _| _|
if you really want to see the pictures above - use some font
with constant spacing like courier! :-)
-----------------------------------------------------------
|
|
From: Thomas S. <t.s...@fz...> - 2008-04-05 08:13:20
|
Dear Dieter, On Fri, Apr 04, 2008 at 08:49:57PM +0200, Dieter Jurzitza wrote: > Dear listmembers, > dear Thomas, > this is just to let you know that I worked hard through this week using > the > new "delete <VARIABLENAME>" function intensively. It works like a charm, I > never noticed any issue. > I would be glad if this patch could find it's way into "official" gnuplot > CVS. it is already in the CVS, the syntax is a little bit different, it's "undefine <VARIABLENAME>" thomas -- View this message in context: http://www.nabble.com/Question-on-variables-tp16503962p16510682.html Sent from the Gnuplot - User mailing list archive at Nabble.com. |
|
From: Thomas S. <t.s...@fz...> - 2008-03-29 10:38:32
|
> Dear listmembers,
> is there any means to delete a variable you are using in a script?
> Say, you have the variable
> L=<somevalue>
>
> at the beginning of a gnuplot - scriptfile. You reach the end of this file
> and
> you would like to say
>
> unset L (but this definitively does not work)
because 'set L=1' is no valid syntax, 'unset L' doesn't work either,
instead, it should be 'undefine L' or 'delete L' (which are not
existing up to now).
> is there any means to achieve this? The reason why I am asking is the
> feature
> of emacs-gnuplot mode and octave to keep an open gnuplot session. If you
> have
> some condition like
>
> if (exists (L)) <do something>
>
> in your script, this only works the very fist time you source the script,
> because from then on the variable is defined.
>
> Maybe someone has a workaround, I did not find one, maybe there's a way to
> delete the variable and I didn't find either.
there is code ('cleanup_udvlist()') in 'parse.c' which would delete a
user defined variable once the 'udv_undef' element of the variables
structure is set to TRUE.
in principle it should be possible to delete a variable, but only with some
modification of the source code.
--
View this message in context: http://www.nabble.com/Question-on-variables-tp16360322p16368564.html
Sent from the Gnuplot - User mailing list archive at Nabble.com.
|
|
From: Dieter J. <die...@t-...> - 2008-03-29 11:10:05
|
Thank you Thomas,
this was a valuable statement. So, for now, I will ask for either
non-existence or an out-of bounds default at the beginning of my script. If
either one is true, I will assume start condition.
At the end of the script I will reassign the out of bound default value and
things ought to work for now.
Not smooth, but ought to work. I would appreciate the implementation of a
change as you pointed out. And, yes, "undefine" or "undef" sounds an
appropriate syntax for this.
Thanks again for clarifying.
Take care
Dieter
--
-----------------------------------------------------------
|
\
/\_/\ |
| ~x~ |/-----\ /
\ /- \_/
^^__ _ / _ ____ /
<°°__ \- \_/ | |/ | |
|| || _| _| _| _|
if you really want to see the pictures above - use some font
with constant spacing like courier! :-)
-----------------------------------------------------------Am Samstag, 29.
März 2008 11:38:38 schrieb Thomas Sefzick:
> > Dear listmembers,
> > is there any means to delete a variable you are using in a script?
> > Say, you have the variable
*****
|
|
From: Thomas S. <t.s...@fz...> - 2008-03-29 11:59:14
|
> in principle it should be possible to delete a variable, but only with some
> modification of the source code.
could somebody have a look into the attached patch?
seems to work, but i'm not sure if i did everything right.
--------------------------------- snip -------------------------------------
--- src/tables.c.orig 2008-03-29 10:28:07.000000000 +0100
+++ src/tables.c 2008-03-29 11:57:55.000000000 +0100
@@ -57,6 +57,7 @@
{ "cd", changedir_command },
{ "cl$ear", clear_command },
{ "ex$it", exit_command },
+ { "d$elete", delvar_command },
{ "f$it", fit_command },
{ "h$elp", help_command },
{ "?", help_command },
--- src/command.h.orig 2008-03-03 20:25:02.000000000 +0100
+++ src/command.h 2008-03-29 12:05:19.000000000 +0100
@@ -174,6 +174,7 @@
void test_command __PROTO((void));
void update_command __PROTO((void));
void do_shell __PROTO((void));
+void delvar_command __PROTO((void));
/* Prototypes for functions exported by command.c */
void extend_input_line __PROTO((void));
--- src/command.c.orig 2008-03-29 10:28:01.000000000 +0100
+++ src/command.c 2008-03-29 12:39:12.000000000 +0100
@@ -532,6 +532,33 @@
}
+void
+delvar_command()
+{
+ char *key = NULL;
+ struct udvt_entry **udv_ptr = &first_udv;
+ c_token++;
+ if (!END_OF_COMMAND) {
+ key = gp_input_line + token[c_token].start_index;
+ if (!key)
+ int_error(c_token, "expecting variable name");
+ if (!strncmp(key, "GPVAL_", 6) || !strncmp(key, "MOUSE_", 6))
+ int_error(c_token, "Cannot delete internal variables GPVAL_ and
MOUSE_");
+ while (*udv_ptr) {
+ if (!strcmp(key, (*udv_ptr)->udv_name)) {
+ (*udv_ptr)->udv_undef = TRUE;
+ cleanup_udvlist();
+ c_token++;
+ return;
+ }
+ udv_ptr = &((*udv_ptr)->next_udv);
+ }
+ int_error(c_token, "variable name not found");
+ }
+ int_error(c_token, "expecting variable name");
+}
+
+
static void
command()
{
--------------------------------- snip -------------------------------------
http://www.nabble.com/file/p16369153/delete_vars.patch delete_vars.patch
--
View this message in context: http://www.nabble.com/Question-on-variables-tp16360322p16369153.html
Sent from the Gnuplot - User mailing list archive at Nabble.com.
|
|
From: Dieter J. <die...@t-...> - 2008-03-29 19:37:56
|
Hi Thomas,
_wow_ this was fast - and seems to work like charm. Will test in more depth
early next week, will give you a feedback ASAP.
This is exactly what I have been looking for, thank you very much!
Take care
Dieter
--
-----------------------------------------------------------
|
\
/\_/\ |
| ~x~ |/-----\ /
\ /- \_/
^^__ _ / _ ____ /
<°°__ \- \_/ | |/ | |
|| || _| _| _| _|
if you really want to see the pictures above - use some font
with constant spacing like courier! :-)
-----------------------------------------------------------Am Samstag, 29.
März 2008 12:59:20 schrieb Thomas Sefzick:
> > in principle it should be possible to delete a variable, but only with
> > some modification of the source code.
>
> could somebody have a look into the attached patch?
*****
|