Skip to content
Snippets Groups Projects
Commit 6f21b9fd authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Moved set_compression_type() to cdo_settings.cc

parent 90214970
No related branches found
No related tags found
1 merge request!267M214003/develop
......@@ -168,41 +168,6 @@ cdo_init_is_tty()
if (S_ISCHR(statbuf.st_mode)) { cdo::stderrIsTerminal = true; }
}
static void
define_compress(const std::string &arg)
{
size_t len = arg.size();
if (arg == "szip")
{
Options::cdoCompType = CDI_COMPRESS_SZIP;
Options::cdoCompLevel = 0;
}
else if (arg == "aec" || arg == "ccsds")
{
Options::cdoCompType = CDI_COMPRESS_AEC;
Options::cdoCompLevel = 0;
}
else if (arg == "jpeg")
{
Options::cdoCompType = CDI_COMPRESS_JPEG;
Options::cdoCompLevel = 0;
}
else if (arg.starts_with("zip"))
{
Options::cdoCompType = CDI_COMPRESS_ZIP;
Options::cdoCompLevel = (len == 5 && arg[3] == '_' && std::isdigit(arg[4])) ? std::atoi(&arg.c_str()[4]) : 1;
}
else if (arg.starts_with("zstd"))
{
int filterIdZstd = 32015;
int zstdLevel = (len >= 6 && len <= 7 && arg[4] == '_' && std::isdigit(arg[5])) ? std::atoi(&arg.c_str()[5]) : 1;
if (Options::filterSpec.size() > 0) { cdo_abort("Filter specs already defined! Only one filter specs is allowed."); }
Options::filterSpec = std::to_string(filterIdZstd) + "," + std::to_string(zstdLevel);
}
else { cdo_abort("Compression type '%s' unsupported!", arg); }
}
static void
define_chunktype(const std::string &arg)
{
......@@ -927,7 +892,7 @@ setup_cli_options()
CLIOptions::option("compression_type", "z")
->describe_argument("aec|jpeg|zip[_1-9]|zstd[1-19]")
->set_category("Compression")
->add_effect([&](const std::string &argument) { define_compress(argument); })
->add_effect([&](const std::string &argument) { cdo::set_compression_type(argument); })
->add_help("aec AEC compression of GRIB2 records", "jpeg JPEG compression of GRIB2 records",
"zip[_1-9] Deflate compression of NetCDF4 variables", "zstd[_1-19] Zstandard compression of NetCDF4 variables");
......
......@@ -313,4 +313,39 @@ set_filterspec(const std::string &arg)
else { cdo_abort("Filter spec missing!"); }
}
void
set_compression_type(const std::string &arg)
{
size_t len = arg.size();
if (arg == "szip")
{
Options::cdoCompType = CDI_COMPRESS_SZIP;
Options::cdoCompLevel = 0;
}
else if (arg == "aec" || arg == "ccsds")
{
Options::cdoCompType = CDI_COMPRESS_AEC;
Options::cdoCompLevel = 0;
}
else if (arg == "jpeg")
{
Options::cdoCompType = CDI_COMPRESS_JPEG;
Options::cdoCompLevel = 0;
}
else if (arg.starts_with("zip"))
{
Options::cdoCompType = CDI_COMPRESS_ZIP;
Options::cdoCompLevel = (len == 5 && arg[3] == '_' && std::isdigit(arg[4])) ? std::atoi(&arg.c_str()[4]) : 1;
}
else if (arg.starts_with("zstd"))
{
int filterIdZstd = 32015;
int zstdLevel = (len >= 6 && len <= 7 && arg[4] == '_' && std::isdigit(arg[5])) ? std::atoi(&arg.c_str()[5]) : 1;
if (Options::filterSpec.size() > 0) { cdo_abort("Filter specs already defined! Only one filter specs is allowed."); }
Options::filterSpec = std::to_string(filterIdZstd) + "," + std::to_string(zstdLevel);
}
else { cdo_abort("Compression type '%s' unsupported!", arg); }
}
}; // namespace cdo
......@@ -20,6 +20,7 @@ void set_digits(const std::string &arg);
void set_default_filetype(std::string filetypeString);
void set_default_datatype(const std::string &datatypeString);
void set_filterspec(const std::string &arg);
void set_compression_type(const std::string &arg);
}; // namespace cdo
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment