Skip to content

Commit

Permalink
make jsave and jload work on octave
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Jun 2, 2020
1 parent b56fc6b commit 7f2cbc4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion jload.m
Expand Up @@ -25,7 +25,7 @@
% vars [{'var1','var2',...}]: list of variables to be saved
%
% all options for loadubjson/loadjson (depends on file suffix)
% can be used to adjust the output file
% can be used to adjust the parsing options
%
% output:
% varlist: a list of variables loaded
Expand Down
14 changes: 7 additions & 7 deletions jsave.m
Expand Up @@ -5,16 +5,16 @@ function jsave(filename, varargin)
% jsave(fname)
% varlist=jsave(fname,'param1',value1,'param2',value2,...)
%
% Store all variables in a workspace to a JSON or binary JSON file
% Store variables in a workspace to a JSON or binary JSON file
%
% authors:Qianqian Fang (q.fang <at> neu.edu)
% created on 2020/05/31
%
% input:
% fname: (optional) input file name; if not given, load 'jamdata.jamm'
% fname: (optional) output file name; if not given, save to 'jamdata.jamm'
% if fname has a '.json' or '.jdt' suffix, a text-based
% JSON/JData file will be created; if the suffix is '.jamm' or
% '.jdb', a Binary JData file will be created.
% JSON/JData file will be created (slow); if the suffix is '.jamm' or
% '.jdb', a Binary JData (https://github.com/fangq/bjdata/) file will be created.
% opt: (optional) a struct to store parsing options, opt can be replaced by
% a list of ('param',value) pairs - the param string is equivallent
% to a field in opt. opt can have the following
Expand All @@ -25,7 +25,7 @@ function jsave(filename, varargin)
% vars [{'var1','var2',...}]: list of variables to be saved
%
% all options for saveubjson/savejson (depends on file suffix)
% can be used to adjust the output file
% can be used to adjust the output
%
% output:
% varlist: a list of variables loaded
Expand Down Expand Up @@ -67,8 +67,8 @@ function jsave(filename, varargin)

vers=ver('MATLAB');
if(isempty(vers))
[verstr, releasedate]=version
vers=struct('Name','GNU Octave','Version',verstr);
vers=ver('Octave');
[verstr, releasedate]=version;
vers.Release=verstr;
vers.Date=releasedate;
end
Expand Down
11 changes: 8 additions & 3 deletions savejson.m
Expand Up @@ -261,8 +261,7 @@
elseif(isnumeric(item) || islogical(item))
txt=mat2json(name,item,level,varargin{:});
elseif(ischar(item))
if(numel(item)>=varargin{1}.compressstringsize && ...
~strcmp(name,encodevarname('_ArrayZipData_',varargin{:})))
if(numel(item)>=varargin{1}.compressstringsize)
txt=mat2json(name,item,level,varargin{:});
else
txt=str2json(name,item,level,varargin{:});
Expand Down Expand Up @@ -399,8 +398,14 @@
end
if(~isempty(names))
for e=1:length(names)
if(varargin{1}.nosubstruct_ && ischar(item(i,j).(names{e})) || ...
strcmp(names{e},encodevarname('_ByteStream_')))
txt{end+1}=str2json(names{e},item(i,j).(names{e}),...
level+(dim(1)>1)+1+forcearray,varargin{:});
else
txt{end+1}=obj2json(names{e},item(i,j).(names{e}),...
level+(dim(1)>1)+1+forcearray,varargin{:});
level+(dim(1)>1)+1+forcearray,varargin{:});
end
if(e<length(names))
txt{end+1}=',';
end
Expand Down
2 changes: 1 addition & 1 deletion saveubjson.m
Expand Up @@ -259,7 +259,7 @@
if(jsonopt('Append',0,opt))
writemode='a';
end
if((exist('OCTAVE_VERSION','builtin')~=0))
if(~exist('OCTAVE_VERSION','builtin'))
fid = fopen(filename, writemode, endian, encoding);
else
fid = fopen(filename, writemode, endian);
Expand Down

0 comments on commit 7f2cbc4

Please sign in to comment.