Subject: Octave <-> Matlab Compatibility Database Date: Tue, 11 Sep 2001 02:15:40 +0100 From: Joćo Cardoso To: pkienzle@kienzle.powernet.co.uk Hi Paul, As you might know, I have made available a save-load.cc patch to Octave that supports saving and reading, in ascii or binary, structures and cells. As I believe that you are currently more involved with Octave, and your mapcompact is certainly the best place to search for patches and new functions, I wonder if you don't want to include the above load-save.cc patch in your package. In case you want, I enclose it. Bye, Joao --- /src/cvs/octave/src/load-save.cc Fri Apr 20 01:27:51 2001 *************** *** 83,88 **** --- 83,90 ---- // no newline characters. static std::string Vsave_header_format_string; + #include "ov-struct.h" + // The number of decimal digits to use when writing ascii data. static int Vsave_precision; *************** *** 693,698 **** --- 695,702 ---- if (! error_state) tc = octave_value (chm, true); } + else if ( elements == 0 ) + tc = octave_value ("",true); else error ("load: failed to extract number of string elements"); } *************** *** 731,736 **** --- 735,786 ---- else error ("load: failed to load range constant"); } + else if (strncmp (ptr, "list", 4) == 0) + { + int ne = 0; + + if (extract_keyword (is, "elements", ne) && ne-- > 0) + { + octave_value_list tmp; + //avoid those useless copies when resizing the list + //another way to do this is to reverse the save order of the + //list elements... easy... but looks better in the file this way + tmp(ne)=octave_value(true); + for( int elem=0;elem<=ne;elem++ ) + if(!read_ascii_data(is,filename,global,tmp(elem), count)) + { + error ("load: list element `%s' missing", tag); + break; + } + tc=tmp; + } + else + panic_impossible (); + } + else if (strncmp (ptr, "struct", 6) == 0) + { + int ne = 0; + + if (extract_keyword (is, "elements", ne) && ne > 0) + { + Octave_map om; + char* s; + + for( int elem=0;elem=0;elem-- ) + if(!read_binary_data(is,swap,fmt,filename,global,tmp(elem),ldoc)) + { + error ("load: list element `%s' missing", name); + break; + } + tc=tmp; + } + break; + case 9: + { + FOUR_BYTE_INT ne; + if (! is.read (&ne, 4)) + goto data_read_error; + if (swap) + swap_4_bytes (X_CAST (char *, &ne)); + Octave_map om; + char *s; + char *ldoc=""; + for( int elem=0;elem=0;elem-- ) + { + octave_value ov = ovl(elem); + save_binary_data ( os, ov, string("_"), string(""), + mark_as_global, save_as_floats); + } + } + else if (tc.is_map ()) + { + tmp = 9; + os.write (&tmp, 1); + Octave_map om = tc.map_value(); + FOUR_BYTE_INT elements = om.length(); + os.write (&elements, 4); + for( Pix elem=om.first();elem!=0;om.next(elem) ) + { + octave_value ov = om.contents(elem); + string s = om.key(elem); + save_binary_data ( os, ov, s, string(""), + mark_as_global, save_as_floats); + } + } else gripe_wrong_type_arg ("save", tc, false); *************** *** 4489,4494 **** --- 4612,4647 ---- << tmp.base () << " " << tmp.limit () << " " << tmp.inc () << "\n"; + } + else if (tc.is_list ()) + { + octave_value_list ovl = tc.list_value(); + int elements = ovl.length(); + ascii_save_type (os, "list", mark_as_global); + os << "# elements: " << elements << "\n"; + for( int elem=0;elem