From bug-request at octave dot org Fri May 27 09:00:50 2005 Subject: Re: general load/save (in)compatibility From: Ben Barrowes To: David dot Bateman at motorola dot com CC: bug at octave dot org Date: Fri, 27 May 2005 07:59:44 -0600 David, I appreciate your reply. I wasn't sure if these items were intentional or not, but it looks like most of them are. David Bateman wrote: > Ben Barrowes wrote: > >> There are a number of compatibility problems regarding load/save >> between octave/matlab: > > > > Ben, > > Not to rain on your parade, but we are talking about Octave and not > Matlab. Octave has no obligation to use the matlab defaults. Though > I'll address all of your complaints. > I understand. Many of the posts I have seen in the mailing lists call for fairly strict compatibility standards in order to make things matlab compatible, so I thought I would point a few things out. >> - matlab's default save filetype is a matfile, instead of an >> octave -text file (octave's default), why is default_save_options = >> "-text"? Wouldn't it make sense to be compatible with matlab? Fix=> >> set default_save_options = "-mat"; > > > Why... Octave has its own formats, why should a competitors file > format be the default... Octave gives you the default_save_options > variable so set it to "-mat" in your .octaverc file and you will have > the behaviour you want while not penalizing other users. > >> - matlab appends a ".mat" onto saved files if there is no >> extension on the save filename and no filetype switch is given. Fix=> >> make octave add ".mat" in cases where the save filename has no file >> extension and no filetype switch is given *and* if >> default_save_options points to a matfile type. This extra test is >> required because matlab currently has no way to default to saving as >> ascii files. > > > Third option the user explictly adds the ".mat" extension when they > want it... Ok, it probably makes sense to add ".mat" to filenames when > we are talking about matlab formats. Supply a patch and I'm sure JWE > would accept it, though not if it does it for all file types. > What file would I patch... load-save.cc ? >> - octave's -text and -ascii (are these different?) save in a >> format incompatible with matlab. I think it would be compatible if >> the # comment character in octave's save format was changed to %. >> Then both matlab and octave could load the file. > > > -ascii is on its way out and being replaced by "-text" exactly for > this reason. Wait till 3.0 and this will be address. Till then use > -mat-ascii... > I don't see the -mat-ascii switch available in the load/save helps. Also, it doesn't seem to be recognized in 2.9.3: octave:13> save -mat-ascii test1 aa warning: save: no such variable `test1' octave:14> will this be in 3.0? >> - when loading a file with no file extension. matlab assumes it is >> an ascii file, while octave tries to figure out(??). octave may have >> more functionality in this case, but the behavior is different with >> no warning issued. Fix=> perhaps none required. > > > Report to the bug to Mathworks.. > >> >> - octave apparently has no way to load ascii files containing >> numbers only. For example, if test2 contains: >> $ more test2 >> 8.0000000e+00 1.0000000e+00 6.0000000e+00 >> 3.0000000e+00 5.0000000e+00 7.0000000e+00 >> 4.0000000e+00 9.0000000e+00 2.0000000e+00 >> matlab will put this into a variable called test2 when called with >> >> load test2 >> However, in octave load with either -text or -ascii both produce the >> error: >> octave:45> load -text test2 >> error: load: empty name keyword or no data found in file `test2' >> octave:45> > > > -text will be the octave text file format below... -ascii will become > the -mat-ascii flag which is what you want, see the above. > Just wait, the change you want is in the process of happening but is > slow due to the need to force existing users to change their > behaviour, so a forced delay with the wraning you see is the result. > >> apparently octave is looking for variable header information written >> when using octave's save -text, such as: >> # Created by Octave 2.9.3, Wed May 25 11:00:05 2005 MDT >> >> # name: aa >> # type: matrix >> # rows: 3 >> # columns: 3 >> 8 1 6 >> 3 5 7 >> 4 9 2 >> Even if octave is changed in the future according to the warning: >> *WARNING: the meaning of this option will change in a future >> version of Octave to be compatible with MATLAB. To keep the >> meaning of your code the same across this change, use the >> `-text' option instead.* >> the default text save should be set to this matlab compatible -ascii >> and not -text (unless the fix above is applied and # is changed to % >> in save -text files. > > > Again we are talking about octave, not matlab. We have no > responsibility to make the defaults of octave those of matlab, though > the capablity to do this is gie to the user with octave option flags > as you've identified. > >> Note that in octave: >> load test2 >> load('test2') >> produce no results and no errors, and > > >> octave:59> a1=load('test2') >> error: value on right hand side of assignment is undefined >> error: evaluating assignment expression near line 59, column 3 >> octave:59> >> fails. > > > See Dmitri's response... > > D. > I read Dmitri's response, but he only reported that the above worked in 2.1.71. Have you tried to load a file like test2 in 2.9.3? Ben ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------