[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "save" to and "load" from file descriptor
From: |
Olaf Till |
Subject: |
Re: "save" to and "load" from file descriptor |
Date: |
Wed, 13 Jun 2007 11:34:08 +0200 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
On Tue, Jun 12, 2007 at 06:37:44PM -0400, John W. Eaton wrote:
> On 12-Jun-2007, David Bateman wrote:
>
> | In fact a change like that wouldn't be too difficult as the prototypes
> | for octave's binary format
> |
> | extern bool
> | save_binary_data (std::ostream& os, const octave_value& tc,
> | const std::string& name, const std::string& doc,
> | bool mark_as_global, bool save_as_floats);
> |
> | extern std::string
> | read_binary_data (std::istream& is, bool swap,
> | oct_mach_info::float_format fmt,
> | const std::string& filename, bool& global,
> | octave_value& tc, std::string& doc);
> |
> | would tell you. You just need a wrapper to setup the iostreams on both
> | sides and then install the variables into memory on the reader's side...
> | Should be relatively easy..
>
> So how would these be used?
>
> fid = fopen ("foo.mat", "w");
> fsave (fid, "var1", "var2");
> fclose (fid);
>
> or would you pass the value itself? If you pass the value, what name
> would be used in the save/load functions?
>
> Would it be possible to write
>
> fid = fopen ("foo.mat", "w");
> fsave (fid, "var1");
> fsave (fid, "var2");
> fclose (fid);
>
> What would happen on the second call to fsave? How would fsave know
> to omit the header info (for example, for the MAT binary formats)?
>
> Because of these issues, I think maybe what you want to do is use the
> exported functions to write specialized functions that send and
> receive data using a particular transport method rather than writing
> fsend/fsave that accept file IDs.
>
> jwe
Think you are right ... would take save_binary_data() and
read_binary_data() as suggested above ... since it is for a pipe,
there is no need for more than one (the Octave binary) format. But I
would _have_ to make the specialized function accept file ids to use a
pipe ... ? (Of course, if someone should use this on Windows with
file ids of real files, and the mode is not binary, it will not
work. I cannot enforce binary mode since pipes have only "w" or "r".)
There is shurely no reason to pass variable names, or even to pass
more than a single variable in one call. Since both sides of the pipe
are usually programmed by the same person, if he/she likes, multiple
variables and variable names can be put into a cell array or a
structure before.
So I would accept only a single variable to pass, and pass its value
itself, and in loading return the value, not install the named
variable into memory. The name used with save_binary_data() would be
an arbitrary one than.
...
psend (pid{2}, var1);
psend (pid{2}, var2);
...
pclose (pid{2});
would be allowed than, and the corresponding prcv (pid{1}) would have
to be called several times in this case.
Since e.g.
psend (pid{2}, var1);
fprintf (pid{2}, "something", ...);
...
pclose (pid{2})
should also be possible, and the other side has to parse the stream
"manually" in this case, there should also be a pendant to "prcv()"
that reads from a string.
I would try to write something like that for dynamically loaded
functions. If it works for me, I'll let you know ...
Regards, Olaf
- Re: "save" to and "load" from file descriptor, David Bateman, 2007/06/12
- Re: "save" to and "load" from file descriptor, Thomas Geiger, 2007/06/12
- Re: "save" to and "load" from file descriptor, John W. Eaton, 2007/06/12
- Re: "save" to and "load" from file descriptor,
Olaf Till <=
- Re: "save" to and "load" from file descriptor, John W. Eaton, 2007/06/13
- RE: "save" to and "load" from file descriptor, Aaron Birenboim, 2007/06/13
- Re: "save" to and "load" from file descriptor, Michael Goffioul, 2007/06/14
- Re: "save" to and "load" from file descriptor, John W. Eaton, 2007/06/14
- Re: "save" to and "load" from file descriptor, Michael Goffioul, 2007/06/14
- Re: "save" to and "load" from file descriptor, John W. Eaton, 2007/06/14
- Re: "save" to and "load" from file descriptor, Michael Goffioul, 2007/06/15
- Re: "save" to and "load" from file descriptor, Olaf Till, 2007/06/14
- Re: "save" to and "load" from file descriptor, Olaf Till, 2007/06/16