Skip to content

Commit

Permalink
Add set_compression_level(int level) to the NCFile API
Browse files Browse the repository at this point in the history
  • Loading branch information
ckhroulev committed Aug 20, 2020
1 parent 8e3b020 commit a557fdf
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 12 deletions.
7 changes: 6 additions & 1 deletion src/util/io/NC3File.cc
@@ -1,4 +1,4 @@
// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2019 PISM Authors
// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2020 PISM Authors
//
// This file is part of PISM.
//
Expand Down Expand Up @@ -66,6 +66,11 @@ NC3File::~NC3File() {
}
}

void NC3File::set_compression_level_impl(int level) const {
(void) level;
// NetCDF-3 does not support compression.
}

// open/create/close
void NC3File::open_impl(const std::string &fname, IO_Mode mode) {
int stat = NC_NOERR;
Expand Down
4 changes: 3 additions & 1 deletion src/util/io/NC3File.hh
@@ -1,4 +1,4 @@
// Copyright (C) 2012, 2013, 2014, 2015, 2017, 2019 PISM Authors
// Copyright (C) 2012, 2013, 2014, 2015, 2017, 2019, 2020 PISM Authors
//
// This file is part of PISM.
//
Expand Down Expand Up @@ -86,6 +86,8 @@ protected:

void inq_varname_impl(unsigned int j, std::string &result) const;

void set_compression_level_impl(int level) const;

// att
void get_att_double_impl(const std::string &variable_name, const std::string &att_name, std::vector<double> &result) const;

Expand Down
5 changes: 3 additions & 2 deletions src/util/io/NC4File.hh
@@ -1,4 +1,4 @@
// Copyright (C) 2012, 2013, 2014, 2015, 2017, 2019 PISM Authors
// Copyright (C) 2012, 2013, 2014, 2015, 2017, 2019, 2020 PISM Authors
//
// This file is part of PISM.
//
Expand Down Expand Up @@ -109,7 +109,8 @@ protected:
const std::vector<unsigned int> &imap, double *ip,
bool get,
bool mapped) const;
unsigned int m_compression_level;

mutable unsigned int m_compression_level;

int get_varid(const std::string &variable_name) const;
};
Expand Down
5 changes: 4 additions & 1 deletion src/util/io/NC4_Par.cc
@@ -1,4 +1,4 @@
// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2019 PISM Authors
// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2020 PISM Authors
//
// This file is part of PISM.
//
Expand Down Expand Up @@ -79,6 +79,9 @@ void NC4_Par::set_access_mode(int varid, bool transposed) const {
}
}

void NC4_Par::set_compression_level_impl(int level) const {
m_compression_level = level;
}


} // end of namespace io
Expand Down
4 changes: 3 additions & 1 deletion src/util/io/NC4_Par.hh
@@ -1,4 +1,4 @@
// Copyright (C) 2012, 2013, 2014, 2015, 2017, 2019 PISM Authors
// Copyright (C) 2012, 2013, 2014, 2015, 2017, 2019, 2020 PISM Authors
//
// This file is part of PISM.
//
Expand Down Expand Up @@ -37,6 +37,8 @@ protected:
virtual void create_impl(const std::string &filename);

virtual void set_access_mode(int varid, bool mapped) const;

virtual void set_compression_level_impl(int level) const;
};


Expand Down
11 changes: 10 additions & 1 deletion src/util/io/NCFile.cc
@@ -1,4 +1,4 @@
// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 PISM Authors
// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 PISM Authors
//
// This file is part of PISM.
//
Expand Down Expand Up @@ -45,6 +45,15 @@ std::string NCFile::filename() const {
return m_filename;
}

void NCFile::set_compression_level(int level) const {
set_compression_level_impl(level);
}

void NCFile::set_compression_level_impl(int level) const {
(void) level;
// the default implementation does nothing
}

void NCFile::def_var_chunking_impl(const std::string &name,
std::vector<size_t> &dimensions) const {
(void) name;
Expand Down
6 changes: 5 additions & 1 deletion src/util/io/NCFile.hh
@@ -1,4 +1,4 @@
// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2019 PISM Authors
// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2020 PISM Authors
//
// This file is part of PISM.
//
Expand Down Expand Up @@ -122,6 +122,8 @@ public:

void inq_varname(unsigned int j, std::string &result) const;

void set_compression_level(int level) const;

// att
void get_att_double(const std::string &variable_name, const std::string &att_name,
std::vector<double> &result) const;
Expand Down Expand Up @@ -208,6 +210,8 @@ protected:

virtual void inq_varname_impl(unsigned int j, std::string &result) const = 0;

virtual void set_compression_level_impl(int level) const = 0;

// att
virtual void get_att_double_impl(const std::string &variable_name, const std::string &att_name, std::vector<double> &result) const = 0;

Expand Down
7 changes: 6 additions & 1 deletion src/util/io/PNCFile.cc
@@ -1,4 +1,4 @@
// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2019 PISM Authors
// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2020 PISM Authors
//
// This file is part of PISM.
//
Expand Down Expand Up @@ -454,5 +454,10 @@ void PNCFile::init_hints() {
}
}

void PNCFile::set_compression_level_impl(int level) const {
(void) level;
// NetCDF-3 does not support compression.
}

} // end of namespace io
} // end of namespace pism
4 changes: 3 additions & 1 deletion src/util/io/PNCFile.hh
@@ -1,4 +1,4 @@
// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2019 PISM Authors
// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2020 PISM Authors
//
// This file is part of PISM.
//
Expand Down Expand Up @@ -88,6 +88,8 @@ protected:

void inq_varname_impl(unsigned int j, std::string &result) const;

void set_compression_level_impl(int level) const;

// att
void get_att_double_impl(const std::string &variable_name, const std::string &att_name,
std::vector<double> &result) const;
Expand Down
7 changes: 6 additions & 1 deletion src/util/io/ParallelIO.cc
@@ -1,4 +1,4 @@
/* Copyright (C) 2019 PISM Authors
/* Copyright (C) 2019, 2020 PISM Authors
*
* This file is part of PISM.
*
Expand Down Expand Up @@ -84,6 +84,11 @@ ParallelIO::~ParallelIO() {
// empty
}

void ParallelIO::set_compression_level_impl(int level) const {
(void) level;
// FIXME: it may make sense to implement this for PIO IO types using HDF5.
}

void ParallelIO::open_impl(const std::string &filename, IO_Mode mode) {
int open_mode = mode == PISM_READONLY ? PIO_NOWRITE : PIO_WRITE;

Expand Down
4 changes: 3 additions & 1 deletion src/util/io/ParallelIO.hh
@@ -1,4 +1,4 @@
/* Copyright (C) 2019 PISM Authors
/* Copyright (C) 2019, 2020 PISM Authors
*
* This file is part of PISM.
*
Expand Down Expand Up @@ -36,6 +36,8 @@ protected:
void sync_impl() const;
void close_impl();

void set_compression_level_impl(int level) const;

// redef/enddef
void enddef_impl() const;

Expand Down

0 comments on commit a557fdf

Please sign in to comment.