From 5471d638899dbf3f52178f8840d0016b0f76f4b2 Mon Sep 17 00:00:00 2001 From: Bihemo Kimasa Date: Mon, 7 Feb 2011 15:50:15 +0100 Subject: Message: Addition of optional hdf functionality on rasdaman. Please see documentation for more information. --- configure.ac | 26 +- conversion/convfactory.cc | 278 ++++++++--------- conversion/hdf.cc | 555 +++++++++++++++++----------------- new_functionality_on_rasdaman_doc.txt | 112 +++++++ 4 files changed, 553 insertions(+), 418 deletions(-) mode change 100644 => 100755 conversion/convfactory.cc mode change 100644 => 100755 conversion/hdf.cc create mode 100644 new_functionality_on_rasdaman_doc.txt diff --git a/configure.ac b/configure.ac index f3174dc..53aa17e 100644 --- a/configure.ac +++ b/configure.ac @@ -34,7 +34,7 @@ AC_CHECK_PROGS(YACC, bison, [${am_missing_run} bison]) AC_CHECK_LIB([crypt], [main], , [AC_MSG_FAILURE([libcrypt.a not found! Please install.])]) AC_CHECK_LIB([crypto], [EVP_DigestFinal], , [AC_MSG_FAILURE([libcrypto.a not found! Please install.])]) # FIXME: Replace `main' with a function in `-ldf': -AC_CHECK_LIB([df], [main], , [AC_MSG_FAILURE([libdf.a not found! Please install.])]) +#AC_CHECK_LIB([df], [main], , [AC_MSG_FAILURE([libdf.a not found! Please install.])]) # FIXME: Replace `main' with a function in `-ldl': AC_CHECK_LIB([dl], [main], , [AC_MSG_FAILURE([libdl.a not found! Please install.])]) # FIXME: Replace `main' with a function in `-lfl': @@ -42,9 +42,9 @@ AC_CHECK_LIB([fl], [main], , [AC_MSG_FAILURE([libfl.a not found! Please install. # FIXME: Replace `main' with a function in `-ljpeg': AC_CHECK_LIB([jpeg], [main], , [AC_MSG_FAILURE([libjpeg.a not found! Please install.])]) # FIXME: Replace `main' with a function in `-lm': -AC_CHECK_LIB([m], [main], , [AC_MSG_FAILURE([libm.a not found! Please install.])]) +#AC_CHECK_LIB([m], [main], , [AC_MSG_FAILURE([libm.a not found! Please install.])]) # FIXME: Replace `main' with a function in `-lmfhdf': -AC_CHECK_LIB([mfhdf], [main], , [AC_MSG_FAILURE([libmfhdf.a not found! Please install.])]) +#AC_CHECK_LIB([mfhdf], [main], , [AC_MSG_FAILURE([libmfhdf.a not found! Please install.])]) # FIXME: Replace `main' with a function in `-lncurses': AC_CHECK_LIB([ncurses], [main], , [AC_MSG_FAILURE([libncurses.a not found! Please install.])]) AC_CHECK_LIB([png], [png_write_row], , [AC_MSG_FAILURE([libpng.a not found! Please install.])]) @@ -140,6 +140,7 @@ AC_CONFIG_FILES([Makefile #################################################################### AH_TEMPLATE([DEBUG], [Enables debug functionality]) AH_TEMPLATE([RMANDEBUG], [Enables debug functionality]) +AH_TEMPLATE([HAVE_HDF], [Checks whether HDF is installed]) AH_TEMPLATE([RMANVERSION], [The version of Rasdaman currently compiled]) AH_TEMPLATE([BASEDB_PGSQL], [If defined we are compiling over PostgreSQL]) AH_TEMPLATE([__NO_MATH_INLINES], [Used by some performance implementaion of math libraries.]) @@ -157,6 +158,21 @@ AH_TEMPLATE([CONFDIR], [The directory where the installed programs will find the # --------------- Parameter Definition ----------------------------- #################################################################### AC_PRESERVE_HELP_ORDER +AC_ARG_WITH([hdf], + [AS_HELP_STRING([--with-hdf], + [this feature enables the inclusion of hdf library during installation.])], + [], + [with_hdf=no]) + +AC_MSG_NOTICE(using hdf library...$with_hdf) + +if test "$with_hdf" == yes; then + AC_CHECK_LIB([df], [main], ,[AC_MSG_FAILURE([--with-hdf was given but libdf.a was not found! Please install.])]) + AC_CHECK_LIB([mfhdf], [main], ,[AC_MSG_FAILURE([--with-hdf was given but libmfhdf.a was not found! Please install.])]) + AC_DEFINE([HAVE_HDF], [1]) +fi + + AC_ARG_WITH([default-rasmgr-port], [AS_HELP_STRING([--with-default-rasmgr-port], [change the default RasMgr port (7001)])], @@ -341,4 +357,8 @@ CXXFLAGS="$CXXFLAGS -DLOGDIR=\\\"\$(logdir)/\\\"" AC_OUTPUT +if test "$with_hdf" == no; then +AC_MSG_NOTICE(Warning: presence of hdf libraries not checked. To run rasdaman you will need to have them installed!) +fi + AC_MSG_NOTICE([Rasdaman successfully configured, installation path is '${prefix}'.]) diff --git a/conversion/convfactory.cc b/conversion/convfactory.cc old mode 100644 new mode 100755 index 31f27ae..6f12957 --- a/conversion/convfactory.cc +++ b/conversion/convfactory.cc @@ -1,24 +1,24 @@ /* -* This file is part of rasdaman community. -* -* Rasdaman community is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* Rasdaman community is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with rasdaman community. If not, see . -* -* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / + * This file is part of rasdaman community. + * + * Rasdaman community is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Rasdaman community is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with rasdaman community. If not, see . + * + * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / rasdaman GmbH. -* -* For more information please see -* or contact Peter Baumann via . + * + * For more information please see + * or contact Peter Baumann via . / /** * SOURCE: convertor.cc @@ -30,7 +30,7 @@ rasdaman GmbH. * * COMMENTS: * - temporary, for debugging -*/ + */ #include "raslib/rminit.hh" #include "debug.hh" @@ -54,136 +54,136 @@ rasdaman GmbH. bool r_Convertor_Factory::is_supported( r_Data_Format fmt ) { - ENTER( "r_Convertor_Factory::is_supported( " << fmt << " )" ); - - bool retval=false; - switch (fmt) - { - case r_TIFF: - case r_PNG: - case r_JPEG: - case r_BMP: - case r_VFF: - case r_TOR: - case r_DEM: - case r_ECW: -#ifndef DISABLE_HDF - case r_HDF: + ENTER( "r_Convertor_Factory::is_supported( " << fmt << " )" ); + + bool retval=false; + switch (fmt) + { + case r_TIFF: + case r_PNG: + case r_JPEG: + case r_BMP: + case r_VFF: + case r_TOR: + case r_DEM: + case r_ECW: +#ifdef HAVE_HDF + case r_HDF: #endif - // case r_NTF: - retval=true; - break; - default: - retval=false; - break; - } - - LEAVE( "r_Convertor_Factory::is_supported() -> " << retval ); - return retval; + // case r_NTF: + retval=true; + break; + default: + retval=false; + break; + } + + LEAVE( "r_Convertor_Factory::is_supported() -> " << retval ); + return retval; } r_Convertor *r_Convertor_Factory::create( r_Data_Format fmt, const char *src, const r_Minterval &interv, const r_Type *tp) throw(r_Error) { - ENTER( "r_Convertor_Factory::create( fmt=" << fmt << ", &src=" << ((r_Ptr) src) << ", interval=" << interv << ", &type=" << ((r_Ptr) tp) << " )" ); - r_Convertor *result = NULL; - - switch (fmt) - { - case r_TIFF: - result = new r_Conv_TIFF(src, interv, tp); - break; - case r_PNG: - result = new r_Conv_PNG(src, interv, tp); - break; - case r_CSV: - result = new r_Conv_CSV(src, interv, tp); - break; - case r_JPEG: - result = new r_Conv_JPEG(src, interv, tp); - break; - case r_BMP: - result = new r_Conv_BMP(src, interv, tp); - break; - case r_VFF: - result = new r_Conv_VFF(src, interv, tp); - break; - case r_TOR: - result = new r_Conv_TOR(src, interv, tp); - break; - case r_DEM: - result = new r_Conv_DEM(src, interv, tp); - break; - case r_ECW: - result = new r_Conv_ECW(src, interv, tp); - break; -#ifndef DISABLE_HDF - case r_HDF: - result = new r_Conv_HDF(src, interv, tp); - break; + ENTER( "r_Convertor_Factory::create( fmt=" << fmt << ", &src=" << ((r_Ptr) src) << ", interval=" << interv << ", &type=" << ((r_Ptr) tp) << " )" ); + r_Convertor *result = NULL; + + switch (fmt) + { + case r_TIFF: + result = new r_Conv_TIFF(src, interv, tp); + break; + case r_PNG: + result = new r_Conv_PNG(src, interv, tp); + break; + case r_CSV: + result = new r_Conv_CSV(src, interv, tp); + break; + case r_JPEG: + result = new r_Conv_JPEG(src, interv, tp); + break; + case r_BMP: + result = new r_Conv_BMP(src, interv, tp); + break; + case r_VFF: + result = new r_Conv_VFF(src, interv, tp); + break; + case r_TOR: + result = new r_Conv_TOR(src, interv, tp); + break; + case r_DEM: + result = new r_Conv_DEM(src, interv, tp); + break; + case r_ECW: + result = new r_Conv_ECW(src, interv, tp); + break; +#ifdef HAVE_HDF + case r_HDF: + result = new r_Conv_HDF(src, interv, tp); + break; #endif - // case r_NTF: - // TALK( "creating NTF converter..." ); - // result = new r_Conv_NTF(src, interv, tp); - // break; - default: - RMInit::logOut << "Error: in conversion factory during create: unsupported format: " << fmt << endl; - r_Error err(CONVERSIONFORMATNOTSUPPORTED); - throw(err); - } - - LEAVE( "r_Convertor_Factory::create() -> " << result ); - return result; + // case r_NTF: + // TALK( "creating NTF converter..." ); + // result = new r_Conv_NTF(src, interv, tp); + // break; + default: + RMInit::logOut << "Error: in conversion factory during create: unsupported format: " << fmt << endl; + r_Error err(CONVERSIONFORMATNOTSUPPORTED); + throw(err); + } + + LEAVE( "r_Convertor_Factory::create() -> " << result ); + return result; } r_Convertor *r_Convertor_Factory::create( r_Data_Format fmt, const char *src, const r_Minterval &interv, int type ) throw(r_Error) { - ENTER( "r_Convertor_Factory::create( fmt=" << fmt << ", &src=" << ((r_Ptr) src) << ", interval=" << interv << ", type=" << type << " )" ); - - r_Convertor *result = NULL; - - switch (fmt) - { - case r_TIFF: - result = new r_Conv_TIFF(src, interv, type); - break; - case r_PNG: - result = new r_Conv_PNG(src, interv, type); - break; - case r_JPEG: - result = new r_Conv_JPEG(src, interv, type); - break; - case r_BMP: - result = new r_Conv_BMP(src, interv, type); - break; - case r_VFF: - result = new r_Conv_VFF(src, interv, type); - break; - case r_TOR: - result = new r_Conv_TOR(src, interv, type); - break; - case r_DEM: - result = new r_Conv_DEM(src, interv, type); - break; - case r_ECW: - result = new r_Conv_ECW(src, interv, type); - break; -#ifndef DISABLE_HDF - case r_HDF: - result = new r_Conv_HDF(src, interv, type); - break; + ENTER( "r_Convertor_Factory::create( fmt=" << fmt << ", &src=" << ((r_Ptr) src) << ", interval=" << interv << ", type=" << type << " )" ); + + r_Convertor *result = NULL; + + switch (fmt) + { + case r_TIFF: + result = new r_Conv_TIFF(src, interv, type); + break; + case r_PNG: + result = new r_Conv_PNG(src, interv, type); + break; + case r_JPEG: + result = new r_Conv_JPEG(src, interv, type); + break; + case r_BMP: + result = new r_Conv_BMP(src, interv, type); + break; + case r_VFF: + result = new r_Conv_VFF(src, interv, type); + break; + case r_TOR: + result = new r_Conv_TOR(src, interv, type); + break; + case r_DEM: + result = new r_Conv_DEM(src, interv, type); + break; + case r_ECW: + result = new r_Conv_ECW(src, interv, type); + break; +#ifdef HAVE_HDF + case r_HDF: + result = new r_Conv_HDF(src, interv, type); + break; #endif - // case r_NTF: - // TALK( "creating NTF converter..." ); - // result = new r_Conv_NTF(src, interv, type); - // break; - default: - RMInit::logOut << "Error: in conversion factory during create: unsupported format: " << fmt << endl; - r_Error err(CONVERSIONFORMATNOTSUPPORTED); - throw(err); - } - - LEAVE( "r_Convertor_Factory::create() -> " << result ); - return result; + // case r_NTF: + // TALK( "creating NTF converter..." ); + // result = new r_Conv_NTF(src, interv, type); + // break; + default: + RMInit::logOut << "Error: in conversion factory during create: unsupported format: " << fmt << endl; + r_Error err(CONVERSIONFORMATNOTSUPPORTED); + throw(err); + } + + LEAVE( "r_Convertor_Factory::create() -> " << result ); + return result; } diff --git a/conversion/hdf.cc b/conversion/hdf.cc old mode 100644 new mode 100755 index 3cf8bf7..adb4d56 --- a/conversion/hdf.cc +++ b/conversion/hdf.cc @@ -1,24 +1,24 @@ /* -* This file is part of rasdaman community. -* -* Rasdaman community is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* Rasdaman community is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with rasdaman community. If not, see . -* -* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / + * This file is part of rasdaman community. + * + * Rasdaman community is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Rasdaman community is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with rasdaman community. If not, see . + * + * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / rasdaman GmbH. -* -* For more information please see -* or contact Peter Baumann via . + * + * For more information please see + * or contact Peter Baumann via . / /** * SOURCE: hdf.cc @@ -31,13 +31,16 @@ rasdaman GmbH. * * Provides functions to convert data to HDF SD and back. * -*/ + */ /* Added by Sorin Stancu-Mara. Definition clashed for type int8, define in both -* /usr/include/hdf.h and in /usr/include/tiff.h -* This will supress the tiff.h definition. -* Both definitions are similar -*/ + * /usr/include/hdf.h and in /usr/include/tiff.h + * This will supress the tiff.h definition. + * Both definitions are similar + */ + +#ifdef HAVE_HDF + #define HAVE_INT8 #include "conversion/hdf.hh" @@ -46,27 +49,26 @@ rasdaman GmbH. #include "raslib/parseparams.hh" #include "raslib/primitivetype.hh" - #ifdef HAVE_HDF_H - #include "hdf.h" +#include "hdf.h" #elif HAVE_HDF_HDF_H - #include "hdf/hdf.h" +#include "hdf/hdf.h" #else - #error "No hdf.h header available." +#error "No hdf.h header available." #endif #ifdef HAVE_MFHDF_H - #include "mfhdf.h" +#include "mfhdf.h" #elif HAVE_HDF_MFHDF_H - #include "hdf/mfhdf.h" +#include "hdf/mfhdf.h" #else - #error "No mfhdf.h header available." +#error "No mfhdf.h header available." #endif // HDF changed from MAX_VAR_DIMS to H4_MAX_VAR_DIMS around 9/5/2007 // to avoid potential conflicts with NetCDF-3 library #ifndef H4_MAX_VAR_DIMS - #define H4_MAX_VAR_DIMS MAX_VAR_DIMS +#define H4_MAX_VAR_DIMS MAX_VAR_DIMS #endif #include @@ -74,15 +76,15 @@ rasdaman GmbH. // make this code robust against different HDF versions and trouble: #ifndef MAX_VAR_DIMS - #define MAX_VAR_DIMS 32 +#define MAX_VAR_DIMS 32 #endif const r_Convertor::convert_string_t r_Conv_HDF::compNames[] = { - {"none", COMP_CODE_NONE}, - {"rle", COMP_CODE_RLE}, - {"huffman", COMP_CODE_SKPHUFF}, - {"deflate", COMP_CODE_DEFLATE}, - {NULL, COMP_CODE_NONE} + {"none", COMP_CODE_NONE}, + {"rle", COMP_CODE_RLE}, + {"huffman", COMP_CODE_SKPHUFF}, + {"deflate", COMP_CODE_DEFLATE}, + {NULL, COMP_CODE_NONE} }; // Buffer used for switching the majorness (column <--> row) of the array data @@ -93,62 +95,62 @@ const int r_Conv_HDF::MaxSwapBufferSize = 0x10000; void r_Conv_HDF::initHDF( void ) { - compType = NULL; - quality = 80; - skiphuff = 0; + compType = NULL; + quality = 80; + skiphuff = 0; - if (params == NULL) - params = new r_Parse_Params; + if (params == NULL) + params = new r_Parse_Params; - params->add("comptype", &compType, r_Parse_Params::param_type_string); - params->add("quality", &quality, r_Parse_Params::param_type_int); - params->add("skiphuff", &skiphuff, r_Parse_Params::param_type_int); + params->add("comptype", &compType, r_Parse_Params::param_type_string); + params->add("quality", &quality, r_Parse_Params::param_type_int); + params->add("skiphuff", &skiphuff, r_Parse_Params::param_type_int); } int r_Conv_HDF::getHDFtype(int intType, int &size) { - int result=0; - - switch (intType) - { - case ctype_int8: result = DFNT_CHAR8; size = 1; break; - case ctype_uint8: - case ctype_char: - case ctype_bool: result = DFNT_UCHAR8; size = 1; break; - case ctype_int16: result = DFNT_INT16; size = 2; break; - case ctype_uint16: result = DFNT_UINT16; size = 2; break; - case ctype_int32: result = DFNT_INT32; size = 4; break; - case ctype_uint32: result = DFNT_UINT32; size = 4; break; - case ctype_int64: result = DFNT_INT64; size = 8; break; - case ctype_uint64: result = DFNT_UINT64; size = 8; break; - case ctype_float32: result = DFNT_FLOAT32; size = 4; break; - case ctype_float64: result = DFNT_FLOAT64; size = 8; break; - default: result = 0; size = 1; break; - } - return result; + int result=0; + + switch (intType) + { + case ctype_int8: result = DFNT_CHAR8; size = 1; break; + case ctype_uint8: + case ctype_char: + case ctype_bool: result = DFNT_UCHAR8; size = 1; break; + case ctype_int16: result = DFNT_INT16; size = 2; break; + case ctype_uint16: result = DFNT_UINT16; size = 2; break; + case ctype_int32: result = DFNT_INT32; size = 4; break; + case ctype_uint32: result = DFNT_UINT32; size = 4; break; + case ctype_int64: result = DFNT_INT64; size = 8; break; + case ctype_uint64: result = DFNT_UINT64; size = 8; break; + case ctype_float32: result = DFNT_FLOAT32; size = 4; break; + case ctype_float64: result = DFNT_FLOAT64; size = 8; break; + default: result = 0; size = 1; break; + } + return result; } int r_Conv_HDF::getIntType( int hdfType, int &size ) { - int result=0; - - switch (hdfType) - { - case DFNT_CHAR8: result = ctype_int8; size = 1; break; - case DFNT_UCHAR8: result = ctype_uint8; size = 1; break; - case DFNT_INT16: result = ctype_int16; size = 2; break; - case DFNT_UINT16: result = ctype_uint16; size = 2; break; - case DFNT_INT32: result = ctype_int32; size = 4; break; - case DFNT_UINT32: result = ctype_uint32; size = 4; break; - case DFNT_INT64: result = ctype_int64; size = 8; break; - case DFNT_UINT64: result = ctype_uint64; size = 8; break; - case DFNT_FLOAT32: result = ctype_float32; size = 4; break; - case DFNT_FLOAT64: result = ctype_float64; size = 8; break; - default: result = ctype_void; size = 1; break; - } - return result; + int result=0; + + switch (hdfType) + { + case DFNT_CHAR8: result = ctype_int8; size = 1; break; + case DFNT_UCHAR8: result = ctype_uint8; size = 1; break; + case DFNT_INT16: result = ctype_int16; size = 2; break; + case DFNT_UINT16: result = ctype_uint16; size = 2; break; + case DFNT_INT32: result = ctype_int32; size = 4; break; + case DFNT_UINT32: result = ctype_uint32; size = 4; break; + case DFNT_INT64: result = ctype_int64; size = 8; break; + case DFNT_UINT64: result = ctype_uint64; size = 8; break; + case DFNT_FLOAT32: result = ctype_float32; size = 4; break; + case DFNT_FLOAT64: result = ctype_float64; size = 8; break; + default: result = ctype_void; size = 1; break; + } + return result; } @@ -156,13 +158,13 @@ int r_Conv_HDF::getIntType( int hdfType, int &size ) r_Conv_HDF::r_Conv_HDF(const char *src, const r_Minterval &interv, const r_Type *tp) throw(r_Error) : r_Convertor(src, interv, tp, true) { - initHDF(); + initHDF(); - if (tp->isStructType()) - { - RMInit::logOut << "r_Conv_HDF::r_Conv_HDF(): structured types not supported." << endl; - throw r_Error(r_Error::r_Error_General); - } + if (tp->isStructType()) + { + RMInit::logOut << "r_Conv_HDF::r_Conv_HDF(): structured types not supported." << endl; + throw r_Error(r_Error::r_Error_General); + } } @@ -170,226 +172,227 @@ r_Conv_HDF::r_Conv_HDF(const char *src, const r_Minterval &interv, const r_Type r_Conv_HDF::r_Conv_HDF(const char *src, const r_Minterval &interv, int tp) throw(r_Error) : r_Convertor(src, interv, tp) { - initHDF(); + initHDF(); } r_Conv_HDF::~r_Conv_HDF(void) { - if (compType != NULL) - { - delete [] compType; - compType = NULL; - } + if (compType != NULL) + { + delete [] compType; + compType = NULL; + } } r_convDesc &r_Conv_HDF::convertTo( const char *options ) throw(r_Error) { - char name[256]; - int32 handle=0, sds_id=0, rank=0; - comp_coder_t comp_type=COMP_CODE_NONE; - int32 *dimsizes=NULL, *start=NULL; - size_t filesize=0; - int i=0, j=0; - FILE *fp=NULL; - comp_info c_info; - - strncpy(name, tmpnam(NULL), 256); - //name = "testfile.hdf"; - - if ((handle = SDstart(name, DFACC_CREATE)) == FAIL) - { - RMInit::logOut << "r_Conv_HDF::convertTo(): unable to open output file." << endl; - throw r_Error(r_Error::r_Error_General); - } - rank = desc.srcInterv.dimension(); - - dimsizes = new int32[rank]; start = new int32[rank]; - datatype = getHDFtype(desc.baseType, datasize); - - for (i=0; iprocess(options); - - comp_type = COMP_CODE_DEFLATE; - if (compType != NULL) - { - for (i=0; compNames[i].key != NULL; i++) - { - if (strcasecmp(compNames[i].key, compType) == 0) - { - comp_type = (comp_coder_t)compNames[i].id; - break; - } - } - if (compNames[i].key == NULL) - { - RMInit::logOut << "r_Conv_HDF::convertTo(): unsupported compression type " << compType << endl; - } - } - c_info.skphuff.skp_size = skiphuff; - c_info.deflate.level = quality; - - SDsetcompress(sds_id, comp_type, &c_info); - - SDwritedata(sds_id, start, NULL, dimsizes, (VOIDP)(desc.src)); - - delete [] dimsizes; dimsizes=NULL; - delete [] start; start=NULL; - - SDendaccess(sds_id); - - SDend(handle); - - if ((fp = fopen(name, "rb")) == NULL) - { - RMInit::logOut << "r_Conv_HDF::convertTo(): unable to read back file." << endl; - throw r_Error(r_Error::r_Error_General); - } - fseek(fp, 0, SEEK_END); - filesize = ftell(fp); - - desc.destInterv = r_Minterval(1); - desc.destInterv << r_Sinterval((r_Range)0, (r_Range)filesize - 1); - - if ((desc.dest = (char*)mystore.storage_alloc(filesize)) == NULL) - { - RMInit::logOut << "r_Conv_HDF::convertTo(): out of memory error" << endl; - fclose(fp); - throw r_Error(MEMMORYALLOCATIONERROR); - } - fseek(fp, 0, SEEK_SET); - fread(desc.dest, 1, filesize, fp); - - fclose(fp); - - remove(name); - - // Result is just a bytestream - desc.destType = r_Type::get_any_type("char"); - - return desc; + char name[256]; + int32 handle=0, sds_id=0, rank=0; + comp_coder_t comp_type=COMP_CODE_NONE; + int32 *dimsizes=NULL, *start=NULL; + size_t filesize=0; + int i=0, j=0; + FILE *fp=NULL; + comp_info c_info; + + strncpy(name, tmpnam(NULL), 256); + //name = "testfile.hdf"; + + if ((handle = SDstart(name, DFACC_CREATE)) == FAIL) + { + RMInit::logOut << "r_Conv_HDF::convertTo(): unable to open output file." << endl; + throw r_Error(r_Error::r_Error_General); + } + rank = desc.srcInterv.dimension(); + + dimsizes = new int32[rank]; start = new int32[rank]; + datatype = getHDFtype(desc.baseType, datasize); + + for (i=0; iprocess(options); + + comp_type = COMP_CODE_DEFLATE; + if (compType != NULL) + { + for (i=0; compNames[i].key != NULL; i++) + { + if (strcasecmp(compNames[i].key, compType) == 0) + { + comp_type = (comp_coder_t)compNames[i].id; + break; + } + } + if (compNames[i].key == NULL) + { + RMInit::logOut << "r_Conv_HDF::convertTo(): unsupported compression type " << compType << endl; + } + } + c_info.skphuff.skp_size = skiphuff; + c_info.deflate.level = quality; + + SDsetcompress(sds_id, comp_type, &c_info); + + SDwritedata(sds_id, start, NULL, dimsizes, (VOIDP)(desc.src)); + + delete [] dimsizes; dimsizes=NULL; + delete [] start; start=NULL; + + SDendaccess(sds_id); + + SDend(handle); + + if ((fp = fopen(name, "rb")) == NULL) + { + RMInit::logOut << "r_Conv_HDF::convertTo(): unable to read back file." << endl; + throw r_Error(r_Error::r_Error_General); + } + fseek(fp, 0, SEEK_END); + filesize = ftell(fp); + + desc.destInterv = r_Minterval(1); + desc.destInterv << r_Sinterval((r_Range)0, (r_Range)filesize - 1); + + if ((desc.dest = (char*)mystore.storage_alloc(filesize)) == NULL) + { + RMInit::logOut << "r_Conv_HDF::convertTo(): out of memory error" << endl; + fclose(fp); + throw r_Error(MEMMORYALLOCATIONERROR); + } + fseek(fp, 0, SEEK_SET); + fread(desc.dest, 1, filesize, fp); + + fclose(fp); + + remove(name); + + // Result is just a bytestream + desc.destType = r_Type::get_any_type("char"); + + return desc; } r_convDesc &r_Conv_HDF::convertFrom(const char *options) throw(r_Error) { - char name[256]; - int32 handle=0, sds_id=0, rank=0, dtype=0, numattr=0, array_size=0; - int32 dimsizes[H4_MAX_VAR_DIMS]; - int32 *start=NULL; - int dsize=0; - size_t filesize=0; - FILE *fp=NULL; - int i=0; - - if (desc.srcInterv.dimension() != 1) - { - RMInit::logOut << "r_Conv_HDF::convertFrom(): source data must be a bytestream!" << endl; - throw r_Error(r_Error::r_Error_General); - } - - strncpy(name, tmpnam(NULL), 256); - if ((fp = fopen(name, "wb")) == NULL) - { - RMInit::logOut << "r_Conv_HDF::convertFrom(): unable to write temporary file!" << endl; - throw r_Error(r_Error::r_Error_General); - } - filesize = desc.srcInterv[0].high() - desc.srcInterv[0].low() + 1; - if ((i = fwrite(desc.src, 1, filesize, fp)) != filesize) - { - RMInit::logOut << "r_Conv_HDF::convertFrom(): error writing to temporary file (" - << i << " / " << filesize << ')' << endl; - throw r_Error(r_Error::r_Error_General); - } - fclose(fp); - - if ((handle = SDstart(name, DFACC_READ)) == FAIL) - { - RMInit::logOut << "r_Conv_HDF::convertFrom(): can't read temporary file!" << endl; - throw r_Error(r_Error::r_Error_General); - } - // Only read the first object in the file - if ((sds_id = SDselect(handle, 0)) == FAIL) - { - RMInit::logOut << "r_Conv_HDF::convertFrom(): unable to open first object" << endl; - SDend(handle); remove(name); - throw r_Error(r_Error::r_Error_General); - } - - SDgetinfo(sds_id, NULL, &rank, dimsizes, &dtype, &numattr); - - // Ignore native datatype flag - dtype &= ~DFNT_NATIVE; - - desc.destType = get_external_type(getIntType(dtype, dsize)); - - start = new int32[rank]; - desc.destInterv = r_Minterval(rank); - array_size = (int32)dsize; - for (i=0; i