Re: Can't save structures?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: Can't save structures?

Joao Cardoso-8


John W. Eaton wrote:
 | On 19-Feb-1997, [hidden email] <[hidden email]> wrote:
 |
 | | In octave-2.0.2 I can't save structures or structure elements. Is
 | | this normal? Is there any work-around?
 |
 | For now, you have to do something like this, to save the elements
 | individually:
...
 | Fixing this is in the PROJECTS file.  Any volunteers?

I'm sorry, as I don't know C++. Meanwhile, I wrote two m files that allow
one to read and save structures, as long as a member structure is not a
structure itself.

This showed a bug in 2.0.3 that did not appear in 2.0.2; it is
related, I supose, to the changes done in sighandlers.cc to block
signals.

        a=system("ls")

don't block in 2.0.2 and block in 2.0.3. An assignment must be done,
system() itself don't block.

Thanks,
Joao

____________________________________________________________
function struct = load_struct(file)

# struct = load_struct(file)
#
# load a structure from a file; structure members can't be structures.


a=system(["awk '{ORS=\" \"};/name:/ {print $3}' " file]); # block in 2.0.3

eval(["load " file " " a]);

b = split(a," ");

for i=1:rows(b)-1
        eval(["struct." b(i,:) "=" b(i,:) ";"]);
endfor

endfunction

____________________________________________________________
function save_struct(file, struct)

# save_struct(file, struct)
#
# save a structure to a file; structure members can't be structures.

cmd = sprintf("save %s ", file);

for [val, nam] = struct
        eval(sprintf("%s=val;",nam));
        cmd = sprintf("%s %s ",cmd, nam);
endfor

eval(cmd)

endfunction
____________________________________________________________
--
Joao Cardoso, INESC  |  e-mail: [hidden email]
R. Jose Falcao 110   |  tel:    + 351 2 2094345
4050 Porto, Portugal |  fax:    + 351 2 2008487