|
View:
New views
20 Messages
—
Rating Filter:
Alert me
|
| < Prev | 1 - 2 - 3 | Next > |
|
|
fopen doesn't return when opening a fifo!!The following code fragment fails for me on Octave 3.0.x and 3.1.x
tn = tmpnam (); ## 6*8*8 = 0600 mode [err, msg] = mkfifo(tn, 6*8*8) gpin = fopen (tn, "r"); fclose (gpin); unlink (tn); as the fopen on the fifo does not return. I originally thought this might be an issue with my libc on my 64-bit system, but the same occurs on an old 32-bit system. Do others see the same bug? Anyone know what is going on? D. -- David Bateman David.Bateman@... Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob) 91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax) The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Re: fopen doesn't return when opening a fifo!!On Mar 31, 2008, at 9:15 AM, David Bateman wrote: > The following code fragment fails for me on Octave 3.0.x and 3.1.x > > tn = tmpnam (); > ## 6*8*8 = 0600 mode > [err, msg] = mkfifo(tn, 6*8*8) > gpin = fopen (tn, "r"); > fclose (gpin); > unlink (tn); > > as the fopen on the fifo does not return. I originally thought this > might be an issue with my libc on my 64-bit system, but the same > occurs > on an old 32-bit system. Do others see the same bug? Anyone know > what is > going on? > > D. Yes I see the same, and my activity monitor indicates Octave is idle. Ben _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Re: fopen doesn't return when opening a fifo!!On Mar 31, 2008, at 9:49 AM, Ben Abbott wrote: > > On Mar 31, 2008, at 9:15 AM, David Bateman wrote: >> The following code fragment fails for me on Octave 3.0.x and 3.1.x >> >> tn = tmpnam (); >> ## 6*8*8 = 0600 mode >> [err, msg] = mkfifo(tn, 6*8*8) >> gpin = fopen (tn, "r"); >> fclose (gpin); >> unlink (tn); >> >> as the fopen on the fifo does not return. I originally thought this >> might be an issue with my libc on my 64-bit system, but the same >> occurs >> on an old 32-bit system. Do others see the same bug? Anyone know >> what is >> going on? >> >> D. > > Yes I see the same, and my activity monitor indicates Octave is idle. > > eval (sprintf ('ls -l %s', tn)) prw------- 1 bpabbott wheel 0 2008-03-31 09:44 /var/tmp/oct-Z5XKZQ hmmm ... that's not what I expected to see. > ls -l /var/tmp/oct-* prw------- 1 bpabbott wheel 0 2008-03-31 09:43 /var/tmp/oct-9DVwxT prw------- 1 bpabbott wheel 0 2008-03-31 09:44 /var/tmp/oct-Z5XKZQ -rw-r--r-- 1 root wheel 0 2007-11-24 22:25 /var/tmp/oct-p0PLLi -rw-r--r-- 1 root wheel 0 2007-12-02 22:47 /var/tmp/oct-pqjfGX [snip] *My* temporary oct-files prior to Dec 2 have different permissions (I have no idea when the binary that produced them was built). In any event, it looks like the permissions have changed. A quick search of src/ChangeLog, turns up this. 2172 2007-11-02 John W. Eaton <jwe@...> 2173 2174 * file-io.cc (fopen_mode_to_ios_mode): Use std::ios::app instead 2175 of std::ios::ate. I have no idea if this is even relevant, but since I'm stuck at home waiting on a tow truck :-( ... I thought I'd poke around. Ben _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Re: fopen doesn't return when opening a fifo!!On Mon, Mar 31, 2008 at 3:15 PM, David Bateman
<David.Bateman@...> wrote: > The following code fragment fails for me on Octave 3.0.x and 3.1.x > > tn = tmpnam (); > ## 6*8*8 = 0600 mode > [err, msg] = mkfifo(tn, 6*8*8) > gpin = fopen (tn, "r"); > fclose (gpin); > unlink (tn); > > as the fopen on the fifo does not return. I originally thought this > might be an issue with my libc on my 64-bit system, but the same occurs > on an old 32-bit system. Do others see the same bug? Anyone know what is > going on? That's what is supposed to happen, isn't it? The GNU C library manual, chapter 15.3 "FIFO Special Files" says: "Opening a FIFO for reading normally blocks until some other process opens the same FIFO for writing, and vice versa." I think that you have to open specially if you want to avoid this. In general, it is a useful behaviour IMHO, as opening a FIFO usually means listening for commands. cheers, -- RNDr. Jaroslav Hajek computing expert Aeronautical Research and Test Institute (VZLU) Prague, Czech Republic url: www.highegg.matfyz.cz _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Re: fopen doesn't return when opening a fifo!!Jaroslav Hajek wrote:
> On Mon, Mar 31, 2008 at 3:15 PM, David Bateman > <David.Bateman@...> wrote: > >> The following code fragment fails for me on Octave 3.0.x and 3.1.x >> >> tn = tmpnam (); >> ## 6*8*8 = 0600 mode >> [err, msg] = mkfifo(tn, 6*8*8) >> gpin = fopen (tn, "r"); >> fclose (gpin); >> unlink (tn); >> >> as the fopen on the fifo does not return. I originally thought this >> might be an issue with my libc on my 64-bit system, but the same occurs >> on an old 32-bit system. Do others see the same bug? Anyone know what is >> going on? >> > > > That's what is supposed to happen, isn't it? > > The GNU C library manual, chapter 15.3 "FIFO Special Files" says: > "Opening a FIFO for reading normally blocks until some other process opens > the same FIFO for writing, and vice versa." > > I think that you have to open specially if you want to avoid this. In > general, it is a useful behaviour IMHO, as opening a FIFO usually > means listening for commands. > > http://gnuplot.sourceforge.net/links.html to the new graphics handle interface, and I believe I have the code setup correctly. However, opening the fifo to read the feedback from gnuplot blocks. The code I currently have is attached if anyone wants to take a look at this.. D. -- David Bateman David.Bateman@... Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob) 91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax) The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary ## Copyright (C) 2004, 2006, 2008 Petr Mikulik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{x}, @var{y}, @var{buttons}] =} ginput (@var{n}) ## Return which mouse buttons were pressed and keys were hit on the current ## figure. If @var{n} is defined, then wait for @var{n} mouse clicks ## before returning. If @var{n} is not defined, then @code{ginput} will ## loop until the return key is pressed. ## @end deftypefn ## This is ginput.m implementation for gnuplot and X11. ## It requires gnuplot 4.1 and later. ## This file initially bore the copyright statement ## Petr Mikulik ## History: June 2006; August 2005; June 2004; April 2004 ## License: public domain function varargout = ginput (n) if (nargin > 1) print_usage (); elseif (nargin == 0) ## A startup-value n = 100; endif f = gcf(); drawnow (); backend = (get (f, "__backend__")); varargout = cell (1, nargout); if (nargin == 0) [varargout{:}] = feval (strcat ("__", backend, "_ginput__"), f); else [varargout{:}] = feval (strcat ("__", backend, "_ginput__"), f, n); endif endfunction function [x, y, button] = __gnuplot_ginput__ (f, n) stream = get (f, "__plot_stream__"); if (compare_versions (__gnuplot_version__ (), "4.0", "<=")) error ("ginput: version %s of gnuplot not supported", gnuplot_version ()); endif if (nargin == 0) x = zeros (n, 1); y = zeros (n, 1); button = zeros (n, 1); else x = zeros (n, 1); y = zeros (n, 1); button = zeros (n, 1); endif gpin_name = tmpnam (); ## 6*8*8 == 0600 [err, msg] = mkfifo(gpin_name, 6*8*8); if (err != 0) error ("ginput: Can not open fifo (%s)", msg); endif k = 0; while (true) k++; fprintf (stream, "set print \"%s\";\n", gpin_name); gpin = fopen (gpin_name, "r"); fprintf (stream, "pause mouse any\n\n"); ## Notes: MOUSE_* can be undefined if user closes gnuplot by "q" or Alt-F4. ## Further, this abrupt close also requires the leading "\n" on the ## next line. fprintf (stream, "\nif (exists(\"MOUSE_KEY\") && exists(\"MOUSE_X\")) print MOUSE_X, MOUSE_Y, MOUSE_KEY; else print \"0 0 -1\"\n"); ## close output file, otherwise all blocks (why?!) fprintf (stream, "set print\n"); ## Now read from fifo [x(k), y(k), button(k), count] = fscanf (gpin, "%f %f %d", "C"); fclose (gpin); if ([x(k), y(k), button(k)] == [0, 0, -1]) ## Mousing not active (no plot until now) break; endif if (nargin > 0) ## input argument n was given => stop when k==n if (k == n) break; endif else ## input argument n not given => stop when hitting a return key ## if (button(k)==0x0D || button(k)==0x0A) ## ## hit Return or Enter if (button(k) == 0x0D) ## hit Return x (k : end) = []; y (k : end) = []; button (k : end) = []; break; endif endif endwhile unlink(gpin_name); endfunction _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Re: fopen doesn't return when opening a fifo!!David Bateman wrote:
> Jaroslav Hajek wrote: > >> On Mon, Mar 31, 2008 at 3:15 PM, David Bateman >> <David.Bateman@...> wrote: >> >> >>> The following code fragment fails for me on Octave 3.0.x and 3.1.x >>> >>> tn = tmpnam (); >>> ## 6*8*8 = 0600 mode >>> [err, msg] = mkfifo(tn, 6*8*8) >>> gpin = fopen (tn, "r"); >>> fclose (gpin); >>> unlink (tn); >>> >>> as the fopen on the fifo does not return. I originally thought this >>> might be an issue with my libc on my 64-bit system, but the same occurs >>> on an old 32-bit system. Do others see the same bug? Anyone know what is >>> going on? >>> >>> >> That's what is supposed to happen, isn't it? >> >> The GNU C library manual, chapter 15.3 "FIFO Special Files" says: >> "Opening a FIFO for reading normally blocks until some other process opens >> the same FIFO for writing, and vice versa." >> >> I think that you have to open specially if you want to avoid this. In >> general, it is a useful behaviour IMHO, as opening a FIFO usually >> means listening for commands. >> >> >> > Ok, then I have some other strange effect. I've tried to convert Petr's > ginput function from > > http://gnuplot.sourceforge.net/links.html > > to the new graphics handle interface, and I believe I have the code > setup correctly. However, opening the fifo to read the feedback from > gnuplot blocks. The code I currently have is attached if anyone wants to > take a look at this.. > > D. > > > attached version of ginput.m works with Octave 3.1.x and versions of gnuplot newer than 4.1.x.. I'm not sure this works with other terminals than X11 though so I'm not sure its a generic solution for ginput for Octave with a gnuplot backend. Find a attached a working version of ginput.m for Octave 3.1.x. To get it to work for Octave 3.0, only the test for the __backend__ property needs to be removed and the __gnuplot_ginput__ subfunction called unconditionally. Regards David -- David Bateman David.Bateman@... Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob) 91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax) The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary ## Copyright (C) 2004, 2006, 2008 Petr Mikulik ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{x}, @var{y}, @var{buttons}] =} ginput (@var{n}) ## Return which mouse buttons were pressed and keys were hit on the current ## figure. If @var{n} is defined, then wait for @var{n} mouse clicks ## before returning. If @var{n} is not defined, then @code{ginput} will ## loop until the return key is pressed. ## @end deftypefn ## This is ginput.m implementation for gnuplot and X11. ## It requires gnuplot 4.1 and later. ## This file initially bore the copyright statement ## Petr Mikulik ## History: June 2006; August 2005; June 2004; April 2004 ## License: public domain function varargout = ginput (n) if (nargin > 1) print_usage (); elseif (nargin == 0) ## A startup-value n = 100; endif f = gcf(); drawnow (); backend = (get (f, "__backend__")); varargout = cell (1, nargout); if (nargin == 0) [varargout{:}] = feval (strcat ("__", backend, "_ginput__"), f); else [varargout{:}] = feval (strcat ("__", backend, "_ginput__"), f, n); endif endfunction function [x, y, button] = __gnuplot_ginput__ (f, n) stream = get (f, "__plot_stream__"); if (compare_versions (__gnuplot_version__ (), "4.0", "<=")) error ("ginput: version %s of gnuplot not supported", gnuplot_version ()); endif if (nargin == 0) x = zeros (n, 1); y = zeros (n, 1); button = zeros (n, 1); else x = zeros (n, 1); y = zeros (n, 1); button = zeros (n, 1); endif gpin_name = tmpnam (); ## 6*8*8 == 0600 [err, msg] = mkfifo(gpin_name, 6*8*8); if (err != 0) error ("ginput: Can not open fifo (%s)", msg); endif k = 0; while (true) k++; fprintf (stream, "set print \"%s\";\n", gpin_name); fflush (stream); gpin = fopen (gpin_name, "r"); fprintf (stream, "pause mouse any\n\n"); ## Notes: MOUSE_* can be undefined if user closes gnuplot by "q" or Alt-F4. ## Further, this abrupt close also requires the leading "\n" on the ## next line. fprintf (stream, "\nif (exists(\"MOUSE_KEY\") && exists(\"MOUSE_X\")) print MOUSE_X, MOUSE_Y, MOUSE_KEY; else print \"0 0 -1\"\n"); ## close output file, otherwise all blocks (why?!) fprintf (stream, "set print\n"); fflush (stream); ## Now read from fifo [x(k), y(k), button(k), count] = fscanf (gpin, "%f %f %d", "C"); fclose (gpin); if ([x(k), y(k), button(k)] == [0, 0, -1]) ## Mousing not active (no plot until now) break; endif if (nargin > 0) ## input argument n was given => stop when k==n if (k == n) break; endif else ## input argument n not given => stop when hitting a return key ## if (button(k)==0x0D || button(k)==0x0A) ## ## hit Return or Enter if (button(k) == 0x0D) ## hit Return x (k : end) = []; y (k : end) = []; button (k : end) = []; break; endif endif endwhile unlink(gpin_name); endfunction _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Re: fopen doesn't return when opening a fifo!!On 31-Mar-2008, David Bateman wrote:
| Oppps, ok I figured it out.. I need to flush the stream to gnuplot | otherwise gnuplot doesn't open the fifo and its blocked as you say.. The | attached version of ginput.m works with Octave 3.1.x and versions of | gnuplot newer than 4.1.x.. I'm not sure this works with other terminals | than X11 though so I'm not sure its a generic solution for ginput for | Octave with a gnuplot backend. | | Find a attached a working version of ginput.m for Octave 3.1.x. To get | it to work for Octave 3.0, only the test for the __backend__ property | needs to be removed and the __gnuplot_ginput__ subfunction called | unconditionally. Since it seems to work, I checked it in. I split the __gnuplot_ginput__ function into a separate file and added an unwind_protect block to ensure that the tmp file is cleaned up. I'm sure we'll find out soon enough whether it works with non-X11 terminals... Thanks, jwe _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Re: fopen doesn't return when opening a fifo!!John W. Eaton wrote:
> On 31-Mar-2008, David Bateman wrote: > > | Oppps, ok I figured it out.. I need to flush the stream to gnuplot > | otherwise gnuplot doesn't open the fifo and its blocked as you say.. The > | attached version of ginput.m works with Octave 3.1.x and versions of > | gnuplot newer than 4.1.x.. I'm not sure this works with other terminals > | than X11 though so I'm not sure its a generic solution for ginput for > | Octave with a gnuplot backend. > | > | Find a attached a working version of ginput.m for Octave 3.1.x. To get > | it to work for Octave 3.0, only the test for the __backend__ property > | needs to be removed and the __gnuplot_ginput__ subfunction called > | unconditionally. > > Since it seems to work, I checked it in. I split the > __gnuplot_ginput__ function into a separate file and added an > unwind_protect block to ensure that the tmp file is cleaned up. I'm > sure we'll find out soon enough whether it works with non-X11 > terminals... > It doesn't work for Windows due to the use of mkfifo. Though probably works on Macs. I have some mods, and the waitforbuttonpress and gtext function as well to come.. I'm trying to figure out a clean way to get this code to work on systems with mkfifo as well with char files, though I'm having problems with blocking reads from the chat file or to the gnuplot stream to allow the chat file to be synchronized between gnuplot and Octave. I'll try and send a patch soon. D. _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Re: fopen doesn't return when opening a fifo!!On 31-Mar-2008, David Bateman wrote:
| It doesn't work for Windows due to the use of mkfifo. Though probably | works on Macs. I have some mods, and the waitforbuttonpress and gtext | function as well to come.. I'm trying to figure out a clean way to get | this code to work on systems with mkfifo as well with char files, though | I'm having problems with blocking reads from the chat file or to the | gnuplot stream to allow the chat file to be synchronized between gnuplot | and Octave. I'll try and send a patch soon. If we can make these functions work then OK, but I wouldn't work too hard at it. I expect they will be obsolete once the OpenGL code is the default. jwe _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Re: fopen doesn't return when opening a fifo!!John W. Eaton wrote:
> On 31-Mar-2008, David Bateman wrote: > > | It doesn't work for Windows due to the use of mkfifo. Though probably > | works on Macs. I have some mods, and the waitforbuttonpress and gtext > | function as well to come.. I'm trying to figure out a clean way to get > | this code to work on systems with mkfifo as well with char files, though > | I'm having problems with blocking reads from the chat file or to the > | gnuplot stream to allow the chat file to be synchronized between gnuplot > | and Octave. I'll try and send a patch soon. > > If we can make these functions work then OK, but I wouldn't work too > hard at it. I expect they will be obsolete once the OpenGL code is > the default. > > jwe chat file. However the gnuplot command "pause mouse any" doesn't work in the Windows terminal.. In any case here is a patch that adds the waitforbuttonpress and gtext commands, fixes a few bugs in __gnuplot_ginput__ and adds a work around for missing mkfifo functions. Note I just assume that if ispc() is true then we don't have the mkfifo function. I suppose we should do something cleaner than that. We'll soon find out if these work on Macs I imagine :-) D. # HG changeset patch # User David Bateman <dbateman@...> # Date 1207000141 -7200 # Node ID fb76ce55d6bd4c249cab45b7ee8a82c1027f519c # Parent 3523775b196695ac07913009b940ea1f573dc35d Add gtext, waitforbuttonpress. Attempt to get ginput working under windows diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,5 +1,12 @@ 2008-03-31 David Bateman <dbateman@fre 2008-03-31 David Bateman <dbateman@...> + * plot/gtext.m: New function to place text on a plot. + * plot/waitforbuttonpress.m: New function. + * plot/Makefile.in (SOURCES): Add them to the list. + * plot/__gnuplot_ginput__.m: Bug fix for nargin==1. Workaround for + missing mkfifo under windows. + * plot/ginput.m: Eliminate setting og n. + * plot/newplot.m: Treat the case of plotyy. * plot/__go_draw_axes__.m: Set the tick direction in the main call the set tics rather than separately to avoid issues with multiple diff --git a/scripts/plot/Makefile.in b/scripts/plot/Makefile.in --- a/scripts/plot/Makefile.in +++ b/scripts/plot/Makefile.in @@ -110,6 +110,7 @@ SOURCES = \ gcf.m \ ginput.m \ grid.m \ + gtext.m \ hidden.m \ hist.m \ hold.m \ @@ -165,6 +166,7 @@ SOURCES = \ text.m \ title.m \ view.m \ + waitforbuttonpress.m \ xlabel.m \ xlim.m \ ylabel.m \ diff --git a/scripts/plot/__gnuplot_ginput__.m b/scripts/plot/__gnuplot_ginput__.m --- a/scripts/plot/__gnuplot_ginput__.m +++ b/scripts/plot/__gnuplot_ginput__.m @@ -16,6 +16,11 @@ ## along with Octave; see the file COPYING. If not, see ## <http://www.gnu.org/licenses/>. +## -*- texinfo -*- +## @deftypefn {Function File} {[@var{x}, @var{y}, @var{buttons}] =} __gnuplot_ginput__ (@var{f}, @var{n}) +## Undocumented internal function. +## @end deftypefn + ## This is ginput.m implementation for gnuplot and X11. ## It requires gnuplot 4.1 and later. @@ -24,12 +29,9 @@ ## History: June 2006; August 2005; June 2004; April 2004 ## License: public domain -## -*- texinfo -*- -## @deftypefn {Function File} {[@var{x}, @var{y}, @var{buttons}] =} __gnuplot_ginput__ (@var{f}, @var{n}) -## Undocumented internal function. -## @end deftypefn +function [x, y, button] = __gnuplot_ginput__ (f, n) -function [x, y, button] = __gnuplot_ginput__ (f, n) + persistent have_mkfifo = ! ispc (); stream = get (f, "__plot_stream__"); @@ -37,10 +39,10 @@ function [x, y, button] = __gnuplot_ginp error ("ginput: version %s of gnuplot not supported", gnuplot_version ()); endif - if (nargin == 0) - x = zeros (n, 1); - y = zeros (n, 1); - button = zeros (n, 1); + if (nargin == 1) + x = zeros (100, 1); + y = zeros (100, 1); + button = zeros (100, 1); else x = zeros (n, 1); y = zeros (n, 1); @@ -49,11 +51,14 @@ function [x, y, button] = __gnuplot_ginp gpin_name = tmpnam (); - ## 6*8*8 == 0600 - [err, msg] = mkfifo (gpin_name, 6*8*8); - if (err != 0) - error ("ginput: Can not open fifo (%s)", msg); - endif + if (have_mkfifo) + ## Use pipes if not on Windows. Mode: 6*8*8 == 0600 + [err, msg] = mkfifo(gpin_name, 6*8*8); + + if (err != 0) + error ("ginput: Can not open fifo (%s)", msg); + endif + endif unwind_protect @@ -62,7 +67,12 @@ function [x, y, button] = __gnuplot_ginp k++; fprintf (stream, "set print \"%s\";\n", gpin_name); fflush (stream); - gpin = fopen (gpin_name, "r"); + if (have_mkfifo) + [gpin, err] = fopen (gpin_name, "r"); + if (err != 0) + error ("ginput: Can not open fifo (%s)", msg); + endif + endif fputs (stream, "pause mouse any;\n\n"); ## Notes: MOUSE_* can be undefined if user closes gnuplot by "q" @@ -74,8 +84,27 @@ function [x, y, button] = __gnuplot_ginp fputs (stream, "set print;\n"); fflush (stream); - ## Now read from fifo. - [x(k), y(k), button(k), count] = fscanf (gpin, "%f %f %d", "C"); + if (! have_mkfifo) + while (exist (gpin_name, "file") == 0) + endwhile + [gpin, msg] = fopen (gpin_name, "r"); + + if (gpin < 0) + error ("ginput: Can not open file (%s)", msg); + endif + + ## Now read from file + count = 0; + while (count == 0) + [xk, yk, buttonk, count] = fscanf (gpin, "%f %f %d", "C"); + endwhile + x(k) = xk; + y(k) = yk; + button (k) = buttonk; + else + ## Now read from fifo. + [x(k), y(k), button(k), count] = fscanf (gpin, "%f %f %d", "C"); + endif fclose (gpin); if ([x(k), y(k), button(k)] == [0, 0, -1]) @@ -83,7 +112,7 @@ function [x, y, button] = __gnuplot_ginp break; endif - if (nargin > 0) + if (nargin > 1) ## Input argument n was given => stop when k == n. if (k == n) break; diff --git a/scripts/plot/ginput.m b/scripts/plot/ginput.m --- a/scripts/plot/ginput.m +++ b/scripts/plot/ginput.m @@ -28,9 +28,6 @@ function varargout = ginput (n) if (nargin > 1) print_usage (); - elseif (nargin == 0) - ## A startup-value - n = 100; endif f = gcf (); diff --git a/scripts/plot/gtext.m b/scripts/plot/gtext.m new file mode 100644 --- /dev/null +++ b/scripts/plot/gtext.m @@ -0,0 +1,53 @@ +## Copyright (C) 2008 David Bateman +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} gtext (@var{s}) +## @deftypefnx {Function File} {} gtext (@dots{}, @var{prop}, @var{val}) +## Places text on the current figure. The text can be defined by the +## string @var{s}. If @var{s} is a cell array, each element of the cell +## array is written to a separate line. +## +## Additional arguments are passed to the underlying text object as +## properties. +## @seealso{ginput} +## @end deftypefn + +function gtext (s, varargin) + + if (nargin < 1) + print_usage (); + endif + + if (iscell (s)) + s = s(:); + if (all (cellfun (@ischar, s))) + tmp(1:2:2*length(s)) = s; + tmp(2:2:2*length(s)) = "\n"; + s = strcat (tmp{:}); + else + error ("gtext: expecting a string or cell array of strings"); + endif + elseif (!ischar (s)) + error ("gtext: expecting a string or cell array of strings"); + endif + + [x, y] = ginput (1); + text (x, y, s, varargin{:}); +endfunction + diff --git a/scripts/plot/waitforbuttonpress.m b/scripts/plot/waitforbuttonpress.m new file mode 100644 --- /dev/null +++ b/scripts/plot/waitforbuttonpress.m @@ -0,0 +1,46 @@ +## Copyright (C) 2004, 2006, 2008 Petr Mikulik +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{b} =} waitforbuttonpress () +## Wait for button or mouse press.over a figure window. The value of +## @var{b} returns 0 if a mouse button was pressed or 1 is a key was +## pressed. +## @seealso{ginput} +## @end deftypefn + +## The original version of this code bore the copyright +## Author: Petr Mikulik +## License: public domain + +function a = waitforbuttonpress () + + if (nargin != 0 || nargout > 1) + print_usage (); + endif + + [x, y, k] = ginput(1); + + if (nargout == 1) + if (k <= 5) + a = 0; + else + a = 1; + endif + endif +endfunction _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Re: fopen doesn't return when opening a fifo!!On 31-Mar-2008, David Bateman wrote:
| In any case here is a patch that adds the waitforbuttonpress and gtext | commands, fixes a few bugs in __gnuplot_ginput__ and adds a work around | for missing mkfifo functions. Note I just assume that if ispc() is true | then we don't have the mkfifo function. I suppose we should do something | cleaner than that. We'll soon find out if these work on Macs I imagine :-) OK. Before I add it and commit, is there a reason to prefer | + if (iscell (s)) | + s = s(:); | + if (all (cellfun (@ischar, s))) | + tmp(1:2:2*length(s)) = s; | + tmp(2:2:2*length(s)) = "\n"; | + s = strcat (tmp{:}); over if (iscellstr (s)) s = sprintf ("%s\n", s{:}); endif ? jwe _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Re: fopen doesn't return when opening a fifo!!John W. Eaton wrote:
> On 31-Mar-2008, David Bateman wrote: > > | In any case here is a patch that adds the waitforbuttonpress and gtext > | commands, fixes a few bugs in __gnuplot_ginput__ and adds a work around > | for missing mkfifo functions. Note I just assume that if ispc() is true > | then we don't have the mkfifo function. I suppose we should do something > | cleaner than that. We'll soon find out if these work on Macs I imagine :-) > > OK. Before I add it and commit, is there a reason to prefer > > | + if (iscell (s)) > | + s = s(:); > | + if (all (cellfun (@ischar, s))) > | + tmp(1:2:2*length(s)) = s; > | + tmp(2:2:2*length(s)) = "\n"; > | + s = strcat (tmp{:}); > > over > > if (iscellstr (s)) > s = sprintf ("%s\n", s{:}); > endif > > ? > > jwe No reason. Your version is better.. D. _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Re: fopen doesn't return when opening a fifo!!> > | Oppps, ok I figured it out.. I need to flush the stream to gnuplot
> > | otherwise gnuplot doesn't open the fifo and its blocked as you say.. The > > | attached version of ginput.m works with Octave 3.1.x and versions of > > | gnuplot newer than 4.1.x. Great! I've downloaded ginput.m from http://www.octave.org/hg/octave and have it working in Octave 3.0. It works fine. Some comments: - You can remove this: ## This file initially bore the copyright statement ## Petr Mikulik ## History: June 2006; August 2005; June 2004; April 2004 ## License: public domain - Remove this code, otherwise ginput (without input arguments) does not work: else x = zeros (n, 1); y = zeros (n, 1); button = zeros (n, 1); - > the gnuplot command "pause mouse any" doesn't work in > the Windows terminal.. It works correctly. - The Windows binary distribution by Tatsuro MATSUOKA prefers to be run under cygwin, and the recommended terminal is X11. Does that mean that within cygwin's bash, mkfifo() in Octave may work? Or is mkfifo() not at all available in Octave's binary for MSW? --- Petr Mikulik _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Re: fopen doesn't return when opening a fifo!!On 1-Apr-2008, David Bateman wrote:
| John W. Eaton wrote: | > On 31-Mar-2008, David Bateman wrote: | > | > | In any case here is a patch that adds the waitforbuttonpress and gtext | > | commands, fixes a few bugs in __gnuplot_ginput__ and adds a work around | > | for missing mkfifo functions. Note I just assume that if ispc() is true | > | then we don't have the mkfifo function. I suppose we should do something | > | cleaner than that. We'll soon find out if these work on Macs I imagine :-) | > | > OK. Before I add it and commit, is there a reason to prefer | > | > | + if (iscell (s)) | > | + s = s(:); | > | + if (all (cellfun (@ischar, s))) | > | + tmp(1:2:2*length(s)) = s; | > | + tmp(2:2:2*length(s)) = "\n"; | > | + s = strcat (tmp{:}); | > | > over | > | > if (iscellstr (s)) | > s = sprintf ("%s\n", s{:}); | > endif | > | > ? | > | > jwe | | No reason. Your version is better.. OK. I applied the patch with this change and a few more to handle empty cell and string arguments. Thanks, jwe _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Re: fopen doesn't return when opening a fifo!!Petr Mikulik wrote:
>>> | Oppps, ok I figured it out.. I need to flush the stream to gnuplot >>> | otherwise gnuplot doesn't open the fifo and its blocked as you say.. The >>> | attached version of ginput.m works with Octave 3.1.x and versions of >>> | gnuplot newer than 4.1.x. >>> > > Great! I've downloaded ginput.m from http://www.octave.org/hg/octave and > have it working in Octave 3.0. It works fine. > > Some comments: > > - You can remove this: > ## This file initially bore the copyright statement > ## Petr Mikulik > ## History: June 2006; August 2005; June 2004; April 2004 > ## License: public domain > remove it if you're ok with that. > - Remove this code, otherwise ginput (without input arguments) > does not work: > > else > x = zeros (n, 1); > y = zeros (n, 1); > button = zeros (n, 1); > Yes, I noticed and fixed that.. The fact is the version of ginput.m hat John originally committed was sent in the couple of minutes before I packed up and left, and as it was the first working version I wanted to get it out there.. The latest version in the repository should be fine. > - > the gnuplot command "pause mouse any" doesn't work in > > the Windows terminal.. > It works correctly. > I tried these functions with Michael's MSVC binary using gnuplot 4.2.2 and had issues. I had to modify ginput.m to force the "backend" variable to be "gnuplot" as this property doesn't exist in Octave 3.0. However, it caused some issues, and the ginput command locked up. I then tried to use "pause mouse any" directly from gnuplot without using Octave at all with the same result.. Were there some mouse support fixes for the Windows terminal in gnuplot 4.2.3? Did you test this with Windows? Basically, I think these function must work under the default terminal types on Windows, Unix and Mac systems to be truly useful. And so hope that with an upgrade to gnuplot 4.2.3 that this is possible. > - The Windows binary distribution by Tatsuro MATSUOKA prefers to be run > under cygwin, and the recommended terminal is X11. > Does that mean that within cygwin's bash, mkfifo() in Octave may work? > Or is mkfifo() not at all available in Octave's binary for MSW? > Doing a quick google search for "cygwin mkfifo" and found http://lists.mplayerhq.hu/pipermail/mplayer-users/2007-July/068030.html so cygwin doesn't implement the mkfifo function, or rather it does but as a dummy function. So I don't expect the mkfifo will work with cygwin. That's why I was happy enough with the test "have_mkfifo = !ispc();" Regards David > --- > Petr Mikulik > > -- David Bateman David.Bateman@... Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob) 91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax) The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Re: fopen doesn't return when opening a fifo!!> > - > the gnuplot command "pause mouse any" doesn't work in
> > > the Windows terminal.. > > It works correctly. > > > I tried these functions with Michael's MSVC binary using gnuplot 4.2.2 > and had issues. I had to modify ginput.m to force the "backend" variable > to be "gnuplot" as this property doesn't exist in Octave 3.0. However, > it caused some issues, and the ginput command locked up. I then tried to > use "pause mouse any" directly from gnuplot without using Octave at all > with the same result.. Were there some mouse support fixes for the > Windows terminal in gnuplot 4.2.3? Did you test this with Windows? > > Basically, I think these function must work under the default terminal > types on Windows, Unix and Mac systems to be truly useful. And so hope > that with an upgrade to gnuplot 4.2.3 that this is possible. They do work correctly. I've tried the Windows binary from the gnuplot's Download section, then: plot x pause mouse any ... now click or hit a key show var > I tried these functions with Michael's MSVC binary using gnuplot 4.2.2 I don't know this binary. Wherefrom have you got it? --- Petr Mikulik _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Windows ginput function [Was: fopen doesn't return when opening a fifo!!]Petr Mikulik wrote:
> They do work correctly. I've tried the Windows binary from the gnuplot's > Download section, then: > plot x > pause mouse any ... now click or hit a key > show var > > I presume that is a 4.2.3 binary. In any case that is good news. >> I tried these functions with Michael's MSVC binary using gnuplot 4.2.2 >> > > I don't know this binary. Wherefrom have you got it? > > This is the windows binary installer of Octave from sourceforge. This is what the vast majority of Windows users are installing and it is pre-packaged with a version of gnuplot. It can be found at http://sourceforge.net/project/showfiles.php?group_id=2888&package_id=40078 Thinking about the issue of how to get around the lack of mkfifo on Windows, why can't we use the existing stream that is open to the gnuplot process to pass the data back from gnuplot to Octave rather than opening another fifo or chat file? This would mean that the plot_stream would be opened with popen2 rather than popen and we'd have both an input and output stream. The major advantage of this is that there is no loop probing the contents of a chat file under windows that causes Octave to run at 100% during a ginput operation. However, one issue I see is that any output that going to the output stream needs to be read by Octave, where currently it just ends up on the stdout.. So we'd have to tag the data we want to have gnuplot print and get accepted by Octave with a tag of some sort, so that we can find the date we want and throw away the rest. Also how do we store the input and output plot stream descriptors.. At the moment there is a single property __plot_stream__ in the figure and its used for the pipe opened with popen. Do we make that a two element matrix, or add a new property? What would other backends expect? I'm tempted to try this modification to Octave out as the advantages seem to be large for Windows users. D. -- David Bateman David.Bateman@... Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob) 91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax) The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Re: Windows ginput function [Was: fopen doesn't return when opening a fifo!!]David Bateman wrote:
> Petr Mikulik wrote: > >> They do work correctly. I've tried the Windows binary from the gnuplot's >> Download section, then: >> plot x >> pause mouse any ... now click or hit a key >> show var >> >> >> > I presume that is a 4.2.3 binary. In any case that is good news. > I forgot to mention the MSVC binary uses the WXT terminal.. Does "pause mouse any" work with this terminal? Or did you test only with the X11 terminal under Windows? D. -- David Bateman David.Bateman@... Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob) 91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax) The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
pause mouse on windows-wxt - Re: Windows ginput function>>> They do work correctly. I've tried the Windows binary from the gnuplot's
>>> Download section, then: >>> plot x >>> pause mouse any ... now click or hit a key >>> show var >>> >> I presume that is a 4.2.3 binary. yes, the Windows terminal supports "pause mouse" correctly > I forgot to mention the MSVC binary uses the WXT terminal.. Does "pause > mouse any" work with this terminal? Or did you test only with the X11 > terminal under Windows? OK, now it's more clear. I've tried this MSVC gnuplot under Wine on Linux, and it seems "pause mouse" does not work on WXT terminal on Windows (on Linux, it's OK). So it's a question to Michael Goffioul to fix this issue with the author of WXT. BTW, I would expect some contact information in the binary packager octave-3.0.0-setup.exe (e.g. in README.txt), however, there are no information whom to contact. I've found the Michael's contact according to his email to gnuplot mailing list. --- Petr Mikulik _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Re: fopen doesn't return when opening a fifo!!Hello Petr and an original questioner
Current pnguplot by oridinariy distubuted does not work at all for octave for windows because octave send binary data via pipe to set terminal color. Hi Petr Do not you really know Michael's pgnuplot ? It is bundled to the distirbution octave-MSVC which can be dowmload from http://sourceforge.net/project/showfiles.php?group_id=2888 Please see my site http://www.geocities.jp/tmoctwin/octmingw.html and see ReadmeMingwOct3.0.xx.txt In that page, please see, ================================================== 2.1.1 gnuplot bundled with MSVC-octave ================================================== This pgnuplot is known amang the gnuplot deveplopers. I have once done the discussion about Michael's gnuplot with HBB. This is a cosole mode pgnuplot for octave for windows. Its version is 4.2.2. I think that Michael will upgrade gnuplot for next release. If the questioner do not wait until next release, please use gnuplot 4.3 (cygwin) introduced in my page. http://www.geocities.jp/tmoctwin/ Regards Tatsuro --- Petr Mikulik <mikulik@...> wrote: > > > - > the gnuplot command "pause mouse any" doesn't work in > > > > the Windows terminal.. > > > It works correctly. > > > > > I tried these functions with Michael's MSVC binary using gnuplot 4.2.2 > > and had issues. I had to modify ginput.m to force the "backend" variable > > to be "gnuplot" as this property doesn't exist in Octave 3.0. However, > > it caused some issues, and the ginput command locked up. I then tried to > > use "pause mouse any" directly from gnuplot without using Octave at all > > with the same result.. Were there some mouse support fixes for the > > Windows terminal in gnuplot 4.2.3? Did you test this with Windows? > > > > Basically, I think these function must work under the default terminal > > types on Windows, Unix and Mac systems to be truly useful. And so hope > > that with an upgrade to gnuplot 4.2.3 that this is possible. > > They do work correctly. I've tried the Windows binary from the gnuplot's > Download section, then: > plot x > pause mouse any ... now click or hit a key > show var > > > I tried these functions with Michael's MSVC binary using gnuplot 4.2.2 > > I don't know this binary. Wherefrom have you got it? > > --- > Petr Mikulik > _______________________________________________ > Bug-octave mailing list > Bug-octave@... > https://www.cae.wisc.edu/mailman/listinfo/bug-octave > -------------------------------------- Easy + Joy + Powerful = Yahoo! Bookmarks x Toolbar http://pr.mail.yahoo.co.jp/toolbar/ _______________________________________________ Bug-octave mailing list Bug-octave@... https://www.cae.wisc.edu/mailman/listinfo/bug-octave |
| < Prev | 1 - 2 - 3 | Next > |
| Free embeddable forum powered by Nabble | Forum Help |