[Index for tmp_for_tar/dumper]
[Return to Master Index]
any2m
(tmp_for_tar/dumper/any2m.m)
Function Synopsis
any2m(name,...)
Help text
any2m('name',matrices, structs or strings) - Save to file of octave code
Saves one or more variable in a .m file of the kind 'name = [ ... ] ;'
This function uses octave 2.1.XX's argn(i) function, that returns
the name of the i'th argument.
For some reason, octave 2.1.1[4-9] is sometimes very slow (>30
seconds) at loading very big (>300k) files created by any2m().
See also any2str, cmpany, list2str, mat2str, struct2str.
Last modified: August 2001
Listing of function file tmp_for_tar/dumper/any2m.m
## any2m('name',matrices, structs or strings) - Save to file of octave code
##
## Saves one or more variable in a .m file of the kind 'name = [ ... ] ;'
##
## This function uses octave 2.1.XX's argn(i) function, that returns
## the name of the i'th argument.
##
## For some reason, octave 2.1.1[4-9] is sometimes very slow (>30
## seconds) at loading very big (>300k) files created by any2m().
##
## See also any2str, cmpany, list2str, mat2str, struct2str.
## Author: Etienne Grossmann <etienne@isr.ist.utl.pt>
## Last modified: August 2001
function any2m(name,...)
vernum = split (OCTAVE_VERSION, ".") ;
if any( str2num(deblank(vernum(:,:))) < [2;1;14] ) ,
printf("any2m needs at least octave 2.1.14\n");
keyboard
end
if ! isstr(name) ,
printf("any2m wants a string as first arg\n");
keyboard
end
name = strrep(name,".m",""); # No suffix.
fname = sprintf("%s.m",name); # Add suffix.
# No path.
if findstr(name,"/"),
name = name(max(findstr(name,"/"))+1:size(name,2)) ;
end
[fid,msg] = fopen(fname,"w"); # Saving.
if fid == -1 ,
error(sprintf("unable to open %s\nError msg is :%s",fname,msg));
end
# Put header.
fprintf(fid,"%% \n%% %s , created by any2m.m on %s \n",fname,ctime(time));
# ###################### Write data. ###################################
j = 1 ;
while j<nargin,
# matname = deblank(argn(j+1,:)); # Doesn't work. BUG???
matname = sprintf("%s",argn(j+1,:));
# printf("Found argument called %s\n",matname) ;
m2 = strrep(matname,"_","x") ; # Check for valid name
if ! isalpha(m2(1)) || ! all( isalnum(m2) ) ,
printf("non-variable passed to any2m\n");
keyboard ;
else
## mat = va_arg() ;
## str = any2str(mat);
## lhs = "" ;
## Avoid temp variables
fprintf(fid,[matname," = "]) ;
fprintf(fid,any2str(va_arg())) ;
fprintf(fid," ;\n\n") ;
end
## lhs = sprintf("%s = ",matname) ;
## fprintf(fid,"%s%s ;\n\n",lhs,str) ;
j = j+1;
end
fclose(fid);
Produced by oct2html on Tue Aug 7 17:33:07 2001
Cross-Directory links are: ON