source: XIOS3/branches/xios-3.0-beta/src/io/onetcdf4_plugin.hpp @ 2530

Last change on this file since 2530 was 2530, checked in by jderouillat, 12 months ago

Enable parallel compression regarding NetCDF & HDF5 configurations at compile time. Implement an API to use HDF5 lossy compression plugins (SZ is available for now).

File size: 1.7 KB
Line 
1#ifndef __XIOS_ONETCDF4_PLUGIN__
2#define __XIOS_ONETCDF4_PLUGIN__
3
4#include "xios_spl.hpp"
5
6#if !defined(USING_NETCDF_PAR)
7#include "exception.hpp"
8#endif
9
10#include "mpi.hpp"
11namespace xios
12{
13  /*!
14  \class CONetCDF4Plugin
15   This class computes parameters for HDF5 plugin compression filters : SZ, ZFP ...
16  */
17  class CONetCDF4Plugin
18  {
19  public:
20    //! Compute HDF5 plugin parameters from SZ parameters
21    static void interpretParametersSZ(const CArray<double,1>& inParams, size_t* nOutParams, unsigned int **outParams)
22    {
23      if (inParams.numElements()!=5)
24      {
25          ERROR("CONetCDF4Plugin::interpretParametersSZ(...)", "The SZ compressor requires 5 parameters : "
26                << "compression_params=\"(0,4)[mode abs_err rel_err pw_rel_err psnr]\" must be specified,"
27                << " see details in https://www.mcs.anl.gov/~shdi/download/sz-2.0-user-guide.pdf" );
28      }
29      *nOutParams = 9;
30      *outParams = new unsigned int[*nOutParams];
31     
32      for (size_t iParam=0 ; iParam<(*nOutParams) ; iParam++) (*outParams)[iParam] = 0;
33
34      // 1st parameter is the SZ error bound mode
35      //   https://github.com/szcompressor/SZ/blob/master/hdf5-filter/H5Z-SZ/docs/H5Z-SZ-Guide.pdf
36      (*outParams)[0] = (unsigned int)(inParams(0));
37     
38      // 1 double -> 2 unsigned int
39      for (size_t iParam=0 ; iParam<4 ; iParam++)
40      {
41        memcpy( &((*outParams)[1+iParam*2]), &(inParams(1+iParam)), sizeof(double) );
42        unsigned int tmp_swap      = (*outParams)[1+iParam*2  ];
43        (*outParams)[1+iParam*2  ] = (*outParams)[1+iParam*2+1];
44        (*outParams)[1+iParam*2+1] = tmp_swap;
45      }
46    }
47     
48  };
49}
50
51
52#endif // __XIOS_ONETCDF4_PLUGIN__
Note: See TracBrowser for help on using the repository browser.