Mercurial > forge
changeset 12178:25f9c66d40bf octave-forge
CACHED_DECOMPRESS_DIR defaults now to a temporary directory in /tmp and add xz support
author | abarth93 |
---|---|
date | Mon, 25 Nov 2013 09:56:29 +0000 |
parents | 4b8983151509 |
children | e7d3e0ab78c2 |
files | extra/ncArray/inst/@ncBaseArray/ncBaseArray.m extra/ncArray/inst/cached_decompress.m extra/ncArray/inst/ncCatArray.m extra/ncArray/inst/test_ncarray.m |
diffstat | 4 files changed, 22 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/extra/ncArray/inst/@ncBaseArray/ncBaseArray.m Mon Nov 18 09:45:30 2013 +0000 +++ b/extra/ncArray/inst/@ncBaseArray/ncBaseArray.m Mon Nov 25 09:56:29 2013 +0000 @@ -4,7 +4,7 @@ % Ths object is a helper object. Users should normally call ncArray. % % For read access filename can be compressed if it has the extensions -% ".gz" or ".bz2". It use the function cache_decompress to cache to +% ".gz", ".bz2" or ".xz". It use the function cache_decompress to cache to % decompressed files. % % Data is loaded by ncread and saved by ncwrite. Values equal to _FillValue
--- a/extra/ncArray/inst/cached_decompress.m Mon Nov 18 09:45:30 2013 +0000 +++ b/extra/ncArray/inst/cached_decompress.m Mon Nov 25 09:56:29 2013 +0000 @@ -9,7 +9,7 @@ % fname: the filename of the uncompressed file % % Global variables: -% CACHED_DECOMPRESS_DIR (default fullfile(getenv('HOME'),'tmp','Cache')): +% CACHED_DECOMPRESS_DIR (default is the result of tempname) % cache directory of decompressed files % CACHED_DECOMPRESS_LOG_FID (default 1): file id for log message % CACHED_DECOMPRESS_MAX_SIZE (default 1e10): maximum size of cache in bytes. @@ -24,21 +24,26 @@ global CACHED_DECOMPRESS_MAX_SIZE cache_dir = CACHED_DECOMPRESS_DIR; + if isempty(cache_dir) - cache_dir = fullfile(getenv('HOME'),'tmp','Cache'); + cache_dir = tempname; + CACHED_DECOMPRESS_DIR = cache_dir; + mkdir(cache_dir); + fprintf('creating directory %s for temporary files.\n',cache_dir); end -if beginswith(url,'http:') || ~(endswith(url,'.gz') || endswith(url,'.bz2')) +if beginswith(url,'http:') || ... + ~(endswith(url,'.gz') || endswith(url,'.bz2') || endswith(url,'.xz')) % opendap url or not compressed file fname = url; return end -if exist(cache_dir,'dir') ~= 7 - error(['cache directory for compressed files does not exist. '... - 'Please create the directory %s or change le value of the '... - 'global variable CACHED_DECOMPRESS_DIR'],cache_dir); -end +%if exist(cache_dir,'dir') ~= 7 +% error(['cache directory for compressed files does not exist. '... +% 'Please create the directory %s or change le value of the '... +% 'global variable CACHED_DECOMPRESS_DIR'],cache_dir); +%end % where to print logs? default to screen @@ -60,8 +65,10 @@ if exist(fname,'file') ~= 2 if endswith(url,'.gz') syscmd('gunzip --stdout "%s" > "%s"',url,fname); + elseif endswith(url,'.bz2') + syscmd('bunzip2 --stdout "%s" > "%s"',url,fname); else - syscmd('bunzip2 --stdout "%s" > "%s"',url,fname); + syscmd('unxz --stdout "%s" > "%s"',url,fname); end else % fprintf(fid,'retrieve from cache %s\n',url); @@ -134,7 +141,7 @@ end -% Copyright (C) 2012 Alexander Barth <barth.alexander@gmail.com> +% Copyright (C) 2012-2013 Alexander Barth <barth.alexander@gmail.com> % % This program is free software; you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by
--- a/extra/ncArray/inst/ncCatArray.m Mon Nov 18 09:45:30 2013 +0000 +++ b/extra/ncArray/inst/ncCatArray.m Mon Nov 25 09:56:29 2013 +0000 @@ -75,7 +75,7 @@ d = rdir(pattern); filenames = {d(:).name}; catch - error(['The function rdir or glob (octave) is not available. '... + error(['The function rdir or glob (octave) is not available. '... 'rdir can be installed from '... 'http://www.mathworks.com/matlabcentral/fileexchange/19550']); end
--- a/extra/ncArray/inst/test_ncarray.m Mon Nov 18 09:45:30 2013 +0000 +++ b/extra/ncArray/inst/test_ncarray.m Mon Nov 25 09:56:29 2013 +0000 @@ -327,6 +327,9 @@ zname = [tmpfname '.gz']; system(['gzip --stdout ' tmpfname ' > ' zname]); +%zname = [tmpfname '.xz']; +%system(['xz --stdout ' tmpfname ' > ' zname]); + SST = ncArray(zname,'SST'); SST_ref = ncread(tmpfname,'SST'); assert(isequalwithequalnans(SST(),SST_ref))