mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-21 03:13:42 +08:00
Fix -d0 option to not do unwanted chunking or associated shuffle.
Add -c '/' option to specify changing layout for all variables from chunked to contiguous. Fix logic for chunking and compression depending on input and output formats.
This commit is contained in:
parent
5e3d265743
commit
d774e23bc1
@ -16,6 +16,7 @@ static struct {
|
||||
size_t ndims; /* number of dimensions in chunkspec string */
|
||||
int *dimids; /* ids for dimensions in chunkspec string */
|
||||
size_t *chunksizes; /* corresponding chunk sizes */
|
||||
bool_t omit; /* true if chunking to be turned off */
|
||||
} chunkspecs;
|
||||
|
||||
/*
|
||||
@ -30,6 +31,8 @@ static struct {
|
||||
* omitted, in which case it is assumed to be the entire
|
||||
* dimension size. That is also the default for dimensions
|
||||
* not mentioned in the string.
|
||||
* If the chunkspec string is "/", specifiying no dimensions or
|
||||
* chunk sizes, it indicates chunking to be turned off on output.
|
||||
*
|
||||
* Returns NC_NOERR if no error, NC_EINVAL if spec has consecutive
|
||||
* unescaped commas or no chunksize specified for dimension.
|
||||
@ -45,8 +48,13 @@ chunkspec_parse(int ncid, const char *spec) {
|
||||
int comma_seen = 0;
|
||||
|
||||
chunkspecs.ndims = 0;
|
||||
if (!spec || *spec == '\0')
|
||||
chunkspecs.omit = false;
|
||||
if (!spec || *spec == '\0') /* default chunking */
|
||||
return NC_NOERR;
|
||||
if (spec[0] == '/' && spec[1] == '\0') { /* no chunking */
|
||||
chunkspecs.omit = true;
|
||||
return NC_NOERR;
|
||||
}
|
||||
/* Count unescaped commas, handle consecutive unescaped commas as error */
|
||||
for(cp = spec; *cp; cp++) {
|
||||
if(*cp == ',' && *pp != '\\') {
|
||||
@ -141,4 +149,11 @@ chunkspec_ndims(void) {
|
||||
return chunkspecs.ndims;
|
||||
}
|
||||
|
||||
/* Return whether chunking should be omitted, due to explicit
|
||||
* command-line specification. */
|
||||
bool_t
|
||||
chunkspec_omit(void) {
|
||||
return chunkspecs.omit;
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,4 +23,9 @@ chunkspec_size(int dimid);
|
||||
extern int
|
||||
chunkspec_ndims(void);
|
||||
|
||||
/* Return whether chunking should be omitted, due to explicit
|
||||
* command-line specification. */
|
||||
extern bool_t
|
||||
chunkspec_omit(void);
|
||||
|
||||
#endif /* _CHUNKSPEC_H_ */
|
||||
|
@ -17,8 +17,8 @@
|
||||
#include <string.h>
|
||||
#include <netcdf.h>
|
||||
#include "nciter.h"
|
||||
#include "chunkspec.h"
|
||||
#include "utils.h"
|
||||
#include "chunkspec.h"
|
||||
#include "dimmap.h"
|
||||
#include "nccomps.h"
|
||||
|
||||
@ -520,8 +520,10 @@ copy_var_specials(int igrp, int varid, int ogrp, int o_varid)
|
||||
}
|
||||
/* Explicitly set chunking, even if default */
|
||||
/* If product of chunksizes is too small and no unlimited
|
||||
* dimensions used, don't chunk */
|
||||
if ((csprod < option_min_chunk_bytes && !is_unlimited) || contig == 1) {
|
||||
* dimensions used, don't chunk. Also if chunking
|
||||
* explicitly turned off with chunk spec, don't chunk. */
|
||||
if ((csprod < option_min_chunk_bytes && !is_unlimited) || contig == 1
|
||||
|| chunkspec_omit() == true) {
|
||||
NC_CHECK(nc_def_var_chunking(ogrp, o_varid, NC_CONTIGUOUS, NULL));
|
||||
} else {
|
||||
NC_CHECK(nc_def_var_chunking(ogrp, o_varid, NC_CHUNKED, chunkp));
|
||||
@ -532,19 +534,19 @@ copy_var_specials(int igrp, int varid, int ogrp, int o_varid)
|
||||
}
|
||||
{ /* handle compression parameters, copying from input, overriding
|
||||
* with command-line options */
|
||||
int shuffle, deflate, deflate_level;
|
||||
NC_CHECK(nc_inq_var_deflate(igrp, varid, &shuffle, &deflate, &deflate_level));
|
||||
if(deflate_level == 0 && deflate == 1) /* TODO: why is this needed?? Bug in nc_inq_var_deflate? */
|
||||
deflate = 0;
|
||||
if(option_deflate_level >= 0) { /* change output compression, if requested */
|
||||
deflate_level = option_deflate_level;
|
||||
deflate=1;
|
||||
}
|
||||
if(shuffle==0 && option_shuffle_vars != 0) {
|
||||
shuffle = option_shuffle_vars;
|
||||
}
|
||||
if(deflate != 0 || shuffle != 0) {
|
||||
NC_CHECK(nc_def_var_deflate(ogrp, o_varid, shuffle, deflate_level > 0, deflate_level));
|
||||
int shuffle_in, deflate_in, deflate_level_in, shuffle_out, deflate_out, deflate_level_out;
|
||||
if(option_deflate_level != 0) {
|
||||
NC_CHECK(nc_inq_var_deflate(igrp, varid, &shuffle_in, &deflate_in, &deflate_level_in));
|
||||
if(option_deflate_level == -1) { /* not specified, copy input compression and shuffling */
|
||||
shuffle_out = shuffle_in;
|
||||
deflate_out = deflate_in;
|
||||
deflate_level_out = deflate_level_in;
|
||||
} else if(option_deflate_level > 0) { /* change to specified compression, shuffling */
|
||||
shuffle_out = option_shuffle_vars;
|
||||
deflate_out=1;
|
||||
deflate_level_out = option_deflate_level;
|
||||
}
|
||||
NC_CHECK(nc_def_var_deflate(ogrp, o_varid, shuffle_out, deflate_out, deflate_level_out));
|
||||
}
|
||||
}
|
||||
{ /* handle checksum parameters */
|
||||
@ -644,7 +646,7 @@ static int
|
||||
set_var_compressed(int ogrp, int o_varid)
|
||||
{
|
||||
int stat = NC_NOERR;
|
||||
if (option_deflate_level >= 0) {
|
||||
if (option_deflate_level > 0) {
|
||||
int deflate = 1;
|
||||
NC_CHECK(nc_def_var_deflate(ogrp, o_varid, option_shuffle_vars, deflate, option_deflate_level));
|
||||
}
|
||||
@ -838,9 +840,9 @@ copy_var(int igrp, int varid, int ogrp)
|
||||
} else {
|
||||
/* Set chunking if specified in command line option */
|
||||
NC_CHECK(set_var_chunked(ogrp, o_varid));
|
||||
/* Set compression if specified in command line option */
|
||||
NC_CHECK(set_var_compressed(ogrp, o_varid));
|
||||
}
|
||||
/* Set compression if specified in command line option */
|
||||
NC_CHECK(set_var_compressed(ogrp, o_varid));
|
||||
}
|
||||
}
|
||||
#endif /* USE_NETCDF4 */
|
||||
|
Loading…
Reference in New Issue
Block a user