/****************************************************************************** * * Copyright (C) 2010 by * * CGTD ICARE * Université des Sciences et Technologies de Lille 1 * Polytech'Lille - Bâtiment Eydoux - Bureau E207 * Avenue Paul Langevin * 59650 Villeneuve d'Ascq Cedex * France * * Description : * ------------- * * This class duplicate the content of an input HDF file and compress its datasets, using the gzip compression * * Limitations : * ------------- * * - Only supports the GZip compression * - Only supports duplication of : * File attributes * SDS data and attributes * * Author : * -------- * * CGTD-ICARE/UDEV Nicolas PASCAL * * License : * --------- * * This file must be used under the terms of the CeCILL. * This source file is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt * * History : * -------- * * v0.0.0 : 04/01/2010 * - creation * *****************************************************************************/ #ifndef HDFCOMPRESSOR_H #define HDFCOMPRESSOR_H #include #include #include #include using namespace std; #include "mfhdf.h" #include "string_tools.h" #include "generic_exception.h" #define DEFAULT_COMPRESSION_LEVEL 6 class HDFCompressor { /** the path to the HDF file to duplicate and compress */ string infile; /** the path to the HDF file to write */ string outfile; /** GZIP compression level */ int comp_level; /** input file HDF ID */ int32 sd_id_src; /** output file HDF ID */ int32 sd_id_dest; /** * @brief retrieve the size in bytes of an HDF data type * @param data_type data type code * @return the size in bytes. -1 if type can be identified */ inline int16 get_data_type_size ( const int32 data_type ) { switch (data_type) { case (DFNT_UCHAR8 ) : case (DFNT_CHAR8 ) : case (DFNT_INT8 ) : case (DFNT_UINT8 ) : return 1; break; case (DFNT_INT16 ) : case (DFNT_UINT16 ) : return 2; break; case (DFNT_INT32 ) : case (DFNT_UINT32 ) : case (DFNT_FLOAT32) : return 4; break; case (DFNT_FLOAT64) : return 8; break; default : return -1; break; } } /** * @brief initialise the SD interfaces of both source and destination files * @throw g_exception in case of problem */ void init_sd_interface (); /** * @brief closes the SD interfaces of both source and destination files * @throw g_exception in case of problem */ void close_sd_interface (); /** * @brief copy the file attributes of a source file to a destination file * @throw g_exception in case of problem * @param sd_id_src source SD ID * @param sd_id_dest destination SD ID */ void copy_file_attr ( const int32 sd_id_src, const int32 sd_id_dest ); /** * @brief copy the attributes of a source object to a destination one * Those objects can be either a SDS ID or a SD ID * @throw g_exception in case of problem * @param obj_id_src source object ID * @param obj_id_dest destination object ID * @param n_attrs the number of attributes to copy. Must not exceed the number of source object attributes */ void copy_attrs ( const int32 obj_id_src, const int32 obj_id_dest, const int32 n_attrs ); /** * @brief copy one attribute of a source object to a destination one * Those objects can be either a SDS ID or a SD ID * @throw g_exception in case of problem * @param obj_id_src source object ID * @param obj_id_dest destination object ID * @param i_attr index of the attribute to copy. Must not exceed the number of source object attributes */ void copy_attr ( const int32 obj_id_src, const int32 obj_id_dest, const int32 i_attr ); /** * @brief copy and compress the datasets of a source file to a destination file * @throw g_exception in case of problem * @param sd_id_src source SD ID * @param sd_id_dest destination SD ID */ void copy_vars_data ( const int32 sd_id_src, const int32 sd_id_dest ); /** * @brief copy and compress one dataset of a source file to a destination file * @throw g_exception in case of problem * @param sd_id_src source SD ID * @param sd_id_dest destination SD ID * @param i_var index of the dataset to copy. Must not exceed the number of source object datasets * @return 1 in case of SUCCESS, 0 ( or FAIL ) else */ int copy_var_data ( const int32 sd_id_src, const int32 sd_id_dest, const int32 i_var ); /** * @brief read the data of a given dataset * @warning the allocation of the data buffer is done internally using a malloc. The responsability of the deallocation by a free is delegated to the caller * @throw g_exception in case of problem * @param sd_id [IN] source SD ID * @param i_var [IN] index of the dataset to read. Must not exceed the number of source object datasets * @param name [OUT] name of the SDS * @param rank [OUT] number of dimensions of the SDS * @param dim_sizes [OUT] size of each dimension * @param data_type [OUT] data type code * @return a pointer to the read data buffer, or NULL if failed */ VOIDP read_var_data ( const int32 sd_id, const int32 i_var, char name[MAX_NC_NAME], int32 & rank, int32 dim_sizes [MAX_VAR_DIMS], int32 & data_type ); /** * @brief copy all the datasets attributes of a source file to a destination file * @throw g_exception in case of problem * @param sd_id_src source SD ID * @param sd_id_dest destination SD ID */ void copy_vars_attr ( const int32 sd_id_src, const int32 sd_id_dest ); /** * @brief copy and compress one dataset of a source file to a destination file * @throw g_exception in case of problem * @param sd_id_src source SD ID * @param sd_id_dest destination SD ID * @param i_var index of the dataset that contains the attributes to copy. Must not exceed the number of source object datasets * @return 1 in case of SUCCESS, 0 ( or FAIL ) else */ int copy_var_attr ( const int32 sd_id_src, const int32 sd_id_dest, const int32 i_var ); public: /** * @brief constructor * @throw g_exception in case of problem */ HDFCompressor ( const string & infile = "", const string & outfile = "", const int comp_level = DEFAULT_COMPRESSION_LEVEL ); /** * @brief destructor */ ~HDFCompressor ( ); /** * @brief start the attributes duplication and the compression processes * @throw g_exception in case of problem */ void run ( ); /** * @brief print out the dictionnary data */ friend ostream &operator << ( ostream &stream, const HDFCompressor &self ); }; #endif