diff options
| -rw-r--r-- | CMakeLists.txt | 6 | ||||
| -rw-r--r-- | include/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | include/tng_io.h | 70 | ||||
| -rw-r--r-- | src/compression/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | src/compression/bwlzh.c | 8 | ||||
| -rw-r--r-- | src/compression/coder.c | 138 | ||||
| -rw-r--r-- | src/lib/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/lib/tng_io.c | 2 | 
8 files changed, 118 insertions, 117 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 496a830..f91d747 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,10 +2,10 @@ cmake_minimum_required(VERSION 2.8)  set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall") -project(TRAJECTORY) +project(TNG_IO)  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) -include_directories(${CMAKE_SOURCE_DIR}/include) +include_directories(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/include/compression)  option(BUILD_FORTRAN "Build Fortran compatible library and examples for testing" OFF) @@ -47,4 +47,4 @@ if(BUILD_DOCUMENTATION)                                          SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)    # IF you do NOT want the documentation to be generated EVERY time you build the project    # then leave out the 'ALL' keyword from the above command. -endif()
\ No newline at end of file +endif() diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt deleted file mode 100644 index 74d02ac..0000000 --- a/include/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(compression) diff --git a/include/tng_io.h b/include/tng_io.h index 30aa4fa..9443dd3 100644 --- a/include/tng_io.h +++ b/include/tng_io.h @@ -275,42 +275,52 @@  #ifdef USE_STD_INTTYPES_H  #include <inttypes.h>  #else -//  /* Visual Studio does not contain inttypes.h and stdint.h. Some defines and   * typedefs are used from the GNU C Library */ +#ifdef _MSC_VER -#ifndef _STDINT_H -/* This first part is from stdint.h (GNU C Library) */ -#ifndef __int8_t_defined -# define __int8_t_defined -typedef signed char             int8_t; -typedef short int               int16_t; -typedef int                     int32_t; -# if __WORDSIZE == 64 -typedef long int                int64_t; -# else -#ifdef __GNUC__ -__extension__ -#endif -typedef long long int           int64_t; -# endif -#endif +typedef __int32 int32_t; +typedef unsigned __int32 uint32_t; +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; -typedef unsigned char           uint8_t; -typedef unsigned short int      uint16_t; -#ifndef __uint32_t_defined -typedef unsigned int            uint32_t; -# define __uint32_t_defined -#endif -#if __WORDSIZE == 64 -typedef unsigned long int       uint64_t;  #else -#ifdef __GNUC__ -__extension__ -#endif -typedef unsigned long long int  uint64_t; -#endif +#include <stdint.h>  #endif +// + +// #ifndef _STDINT_H +// /* This first part is from stdint.h (GNU C Library) */ +// #ifndef __int8_t_defined +// # define __int8_t_defined +// typedef signed char             int8_t; +// typedef short int               int16_t; +// typedef int                     int32_t; +// # if __WORDSIZE == 64 +// typedef long int                int64_t; +// # else +// #ifdef __GNUC__ +// __extension__ +// #endif +// typedef long long int           int64_t; +// # endif +// #endif +//  +// typedef unsigned char           uint8_t; +// typedef unsigned short int      uint16_t; +// #ifndef __uint32_t_defined +// typedef unsigned int            uint32_t; +// # define __uint32_t_defined +// #endif +// #if __WORDSIZE == 64 +// typedef unsigned long int       uint64_t; +// #else +// #ifdef __GNUC__ +// __extension__ +// #endif +// typedef unsigned long long int  uint64_t; +// #endif +// #endif  /* This is from inttypes.h  (GNU C Library) */  /* The ISO C99 standard specifies that these macros must only be diff --git a/src/compression/CMakeLists.txt b/src/compression/CMakeLists.txt index 605dac7..91155e0 100644 --- a/src/compression/CMakeLists.txt +++ b/src/compression/CMakeLists.txt @@ -1,10 +1,4 @@ -set(COMP_INC_DIR ${CMAKE_SOURCE_DIR}/include/compression) - -include_directories(${COMP_INC_DIR}) - -set(HEADER_FILES ${COMP_INC_DIR}/bwlzh.h ${COMP_INC_DIR}/bwt.h ${COMP_INC_DIR}/coder.h ${COMP_INC_DIR}/dict.h ${COMP_INC_DIR}/fixpoint.h ${COMP_INC_DIR}/huffman.h ${COMP_INC_DIR}/lz77.h ${COMP_INC_DIR}/merge_sort.h ${COMP_INC_DIR}/mtf.h ${COMP_INC_DIR}/my64bit.h ${COMP_INC_DIR}/rle.h ${COMP_INC_DIR}/tng_compress.h ${COMP_INC_DIR}/vals16.h ${COMP_INC_DIR}/warnmalloc.h ${COMP_INC_DIR}/widemuldiv.h) - -add_library(tng_compress SHARED bwlzh.c bwt.c coder.c dict.c fixpoint.c huffman.c huffmem.c lz77.c merge_sort.c mtf.c rle.c tng_compress.c vals16.c warnmalloc.c widemuldiv.c xtc2.c xtc3.c) +add_library(tng_compress bwlzh.c bwt.c coder.c dict.c fixpoint.c huffman.c huffmem.c lz77.c merge_sort.c mtf.c rle.c tng_compress.c vals16.c warnmalloc.c widemuldiv.c xtc2.c xtc3.c)  if(UNIX)  target_link_libraries(tng_compress m)  endif() diff --git a/src/compression/bwlzh.c b/src/compression/bwlzh.c index e5eb499..88bee37 100644 --- a/src/compression/bwlzh.c +++ b/src/compression/bwlzh.c @@ -81,9 +81,6 @@ static void bwlzh_compress_gen(unsigned int *vals, int nvals,    int huffdatalen;    int nhufflen[N_HUFFMAN_ALGO];    int huffalgo; -#ifndef PARTIAL_MTF -  int ndict; -#endif    int bwt_index;    unsigned int *bwt=NULL;  #ifdef PARTIAL_MTF3 @@ -213,6 +210,7 @@ static void bwlzh_compress_gen(unsigned int *vals, int nvals,  #ifdef PARTIAL_MTF  	  Ptngc_comp_conv_to_mtf_partial(bwt,nvals16,mtf);  #else +      int ndict;  	  Ptngc_comp_canonical_dict(dict,&ndict);  	  Ptngc_comp_conv_to_mtf(bwt,nvals16,  			   dict,ndict,mtf); @@ -496,9 +494,6 @@ static void bwlzh_decompress_gen(unsigned char *input, int nvals,  {    unsigned int *vals16;    int nvals16; -#ifndef PARTIAL_MTF -  int ndict; -#endif    int bwt_index;    unsigned int *bwt=NULL;     unsigned int *mtf=NULL; @@ -748,6 +743,7 @@ static void bwlzh_decompress_gen(unsigned char *input, int nvals,  #ifdef PARTIAL_MTF        Ptngc_comp_conv_from_mtf_partial(mtf,nvals16,bwt);  #else +      int ndict;        Ptngc_comp_canonical_dict(dict,&ndict);              Ptngc_comp_conv_from_mtf(mtf,nvals16,dict,ndict,bwt);  #endif diff --git a/src/compression/coder.c b/src/compression/coder.c index be46c17..270e4d3 100644 --- a/src/compression/coder.c +++ b/src/compression/coder.c @@ -34,20 +34,20 @@  struct coder *Ptngc_coder_init(void)  { -    struct coder *coder=warnmalloc(sizeof *coder); -    coder->pack_temporary_bits=0; -    return coder; +    struct coder *coder_inst=warnmalloc(sizeof *coder_inst); +    coder_inst->pack_temporary_bits=0; +    return coder_inst;  } -void Ptngc_coder_deinit(struct coder *coder) +void Ptngc_coder_deinit(struct coder *coder_inst)  { -    free(coder); +    free(coder_inst);  } -TNG_INLINE void Ptngc_out8bits(struct coder *coder, unsigned char **output) +TNG_INLINE void Ptngc_out8bits(struct coder *coder_inst, unsigned char **output)  { -  int pack_temporary_bits=coder->pack_temporary_bits; -  unsigned int pack_temporary=coder->pack_temporary; +  int pack_temporary_bits=coder_inst->pack_temporary_bits; +  unsigned int pack_temporary=coder_inst->pack_temporary;    while (pack_temporary_bits>=8)      {        unsigned int mask=~(0xFFU<<(pack_temporary_bits-8)); @@ -57,40 +57,40 @@ TNG_INLINE void Ptngc_out8bits(struct coder *coder, unsigned char **output)        pack_temporary_bits-=8;        pack_temporary&=mask;      } -  coder->pack_temporary_bits=pack_temporary_bits; -  coder->pack_temporary=pack_temporary; +  coder_inst->pack_temporary_bits=pack_temporary_bits; +  coder_inst->pack_temporary=pack_temporary;  } -void Ptngc_write_pattern(struct coder *coder,unsigned int pattern, int nbits, unsigned char **output) +void Ptngc_write_pattern(struct coder *coder_inst,unsigned int pattern, int nbits, unsigned char **output)  {      unsigned int mask1,mask2;      mask1=1;      mask2=1<<(nbits-1); -    coder->pack_temporary<<=nbits; /* Make room for new data. */ -    coder->pack_temporary_bits+=nbits; +    coder_inst->pack_temporary<<=nbits; /* Make room for new data. */ +    coder_inst->pack_temporary_bits+=nbits;      while (nbits)      {  	if (pattern & mask1) -	    coder->pack_temporary|=mask2; +	    coder_inst->pack_temporary|=mask2;  	nbits--;  	mask1<<=1;  	mask2>>=1;      } -    Ptngc_out8bits(coder,output); +    Ptngc_out8bits(coder_inst,output);  }  /* Write up to 24 bits */ -TNG_INLINE void Ptngc_writebits(struct coder *coder,unsigned int value,int nbits, unsigned char **output_ptr) +TNG_INLINE void Ptngc_writebits(struct coder *coder_inst,unsigned int value,int nbits, unsigned char **output_ptr)  {    /* Make room for the bits. */ -  coder->pack_temporary<<=nbits; -  coder->pack_temporary_bits+=nbits; -  coder->pack_temporary|=value; -  Ptngc_out8bits(coder,output_ptr); +  coder_inst->pack_temporary<<=nbits; +  coder_inst->pack_temporary_bits+=nbits; +  coder_inst->pack_temporary|=value; +  Ptngc_out8bits(coder_inst,output_ptr);  }  /* Write up to 32 bits */ -void Ptngc_write32bits(struct coder *coder,unsigned int value,int nbits, unsigned char **output_ptr) +void Ptngc_write32bits(struct coder *coder_inst,unsigned int value,int nbits, unsigned char **output_ptr)  {    unsigned int mask;    if (nbits>=8) @@ -100,19 +100,19 @@ void Ptngc_write32bits(struct coder *coder,unsigned int value,int nbits, unsigne    while (nbits>8)      {        /* Make room for the bits. */ -      coder->pack_temporary<<=8; -      coder->pack_temporary_bits+=8; -      coder->pack_temporary|=(value&mask)>>(nbits-8); -      Ptngc_out8bits(coder,output_ptr); +      coder_inst->pack_temporary<<=8; +      coder_inst->pack_temporary_bits+=8; +      coder_inst->pack_temporary|=(value&mask)>>(nbits-8); +      Ptngc_out8bits(coder_inst,output_ptr);        nbits-=8;        mask>>=8;      }    if (nbits) -    Ptngc_writebits(coder,value&mask,nbits,output_ptr); +    Ptngc_writebits(coder_inst,value&mask,nbits,output_ptr);  }  /* Write "arbitrary" number of bits */ -void Ptngc_writemanybits(struct coder *coder,unsigned char *value,int nbits, unsigned char **output_ptr) +void Ptngc_writemanybits(struct coder *coder_inst,unsigned char *value,int nbits, unsigned char **output_ptr)  {    int vptr=0;    while (nbits>=24) @@ -120,23 +120,23 @@ void Ptngc_writemanybits(struct coder *coder,unsigned char *value,int nbits, uns        unsigned int v=((((unsigned int)value[vptr])<<16)|  		      (((unsigned int)value[vptr+1])<<8)|  		      (((unsigned int)value[vptr+2]))); -      Ptngc_writebits(coder,v,24,output_ptr); +      Ptngc_writebits(coder_inst,v,24,output_ptr);        vptr+=3;        nbits-=24;      }    while (nbits>=8)      { -      Ptngc_writebits(coder,(unsigned int)value[vptr],8,output_ptr); +      Ptngc_writebits(coder_inst,(unsigned int)value[vptr],8,output_ptr);        vptr++;        nbits-=8;      }    if (nbits)      { -      Ptngc_writebits(coder,(unsigned int)value[vptr],nbits,output_ptr); +      Ptngc_writebits(coder_inst,(unsigned int)value[vptr],nbits,output_ptr);      }  } -static int write_stop_bit_code(struct coder *coder, unsigned int s,unsigned int coding_parameter, unsigned char **output) +static int write_stop_bit_code(struct coder *coder_inst, unsigned int s,unsigned int coding_parameter, unsigned char **output)  {    do {      unsigned int extract=~(0xffffffffU<<coding_parameter); @@ -145,12 +145,12 @@ static int write_stop_bit_code(struct coder *coder, unsigned int s,unsigned int      if (s)        {  	this|=1U; -	coder->stat_overflow++; +	coder_inst->stat_overflow++;        } -    coder->pack_temporary<<=(coding_parameter+1); -    coder->pack_temporary_bits+=coding_parameter+1; -    coder->pack_temporary|=this; -    Ptngc_out8bits(coder,output); +    coder_inst->pack_temporary<<=(coding_parameter+1); +    coder_inst->pack_temporary_bits+=coding_parameter+1; +    coder_inst->pack_temporary|=this; +    Ptngc_out8bits(coder_inst,output);      if (s)        {  	coding_parameter>>=1; @@ -158,11 +158,11 @@ static int write_stop_bit_code(struct coder *coder, unsigned int s,unsigned int  	  coding_parameter=1;        }    } while (s); -  coder->stat_numval++; +  coder_inst->stat_numval++;    return 0;  } -static int pack_stopbits_item(struct coder *coder,int item, unsigned char **output, int coding_parameter) +static int pack_stopbits_item(struct coder *coder_inst,int item, unsigned char **output, int coding_parameter)  {      /* Find this symbol in table. */      int s=0; @@ -170,11 +170,11 @@ static int pack_stopbits_item(struct coder *coder,int item, unsigned char **outp  	s=1+(item-1)*2;      else if (item<0)  	s=2+(-item-1)*2; -    return write_stop_bit_code(coder,s,coding_parameter,output); +    return write_stop_bit_code(coder_inst,s,coding_parameter,output);      return 0;  } -static int pack_triplet(struct coder *coder,unsigned int *s, unsigned char **output, int coding_parameter, +static int pack_triplet(struct coder *coder_inst,unsigned int *s, unsigned char **output, int coding_parameter,  			unsigned int max_base, int maxbits)  {    /* Determine base for this triplet. */ @@ -199,23 +199,23 @@ static int pack_triplet(struct coder *coder,unsigned int *s, unsigned char **out        jbase=3;      }    /* 2 bits selects the base */ -  coder->pack_temporary<<=2; -  coder->pack_temporary_bits+=2; -  coder->pack_temporary|=jbase; -  Ptngc_out8bits(coder,output); +  coder_inst->pack_temporary<<=2; +  coder_inst->pack_temporary_bits+=2; +  coder_inst->pack_temporary|=jbase; +  Ptngc_out8bits(coder_inst,output);    for (i=0; i<3; i++) -    Ptngc_write32bits(coder,s[i],bits_per_value,output); +    Ptngc_write32bits(coder_inst,s[i],bits_per_value,output);    return 0;  } -void Ptngc_pack_flush(struct coder *coder,unsigned char **output) +void Ptngc_pack_flush(struct coder *coder_inst,unsigned char **output)  {    /* Zero-fill just enough. */ -  if (coder->pack_temporary_bits>0) -    Ptngc_write_pattern(coder,0,8-coder->pack_temporary_bits,output); +  if (coder_inst->pack_temporary_bits>0) +    Ptngc_write_pattern(coder_inst,0,8-coder_inst->pack_temporary_bits,output);  } -unsigned char *Ptngc_pack_array(struct coder *coder,int *input, int *length, int coding, int coding_parameter,int natoms, int speed) +unsigned char *Ptngc_pack_array(struct coder *coder_inst,int *input, int *length, int coding, int coding_parameter,int natoms, int speed)  {    if ((coding==TNG_COMPRESS_ALGO_BWLZH1) || (coding==TNG_COMPRESS_ALGO_BWLZH2))      { @@ -252,7 +252,7 @@ unsigned char *Ptngc_pack_array(struct coder *coder,int *input, int *length, int    else if (coding==TNG_COMPRESS_ALGO_POS_XTC3)      return Ptngc_pack_array_xtc3(input,length,natoms,speed);    else if (coding==TNG_COMPRESS_ALGO_POS_XTC2) -    return Ptngc_pack_array_xtc2(coder,input,length); +    return Ptngc_pack_array_xtc2(coder_inst,input,length);    else      {        unsigned char *output=NULL; @@ -260,8 +260,8 @@ unsigned char *Ptngc_pack_array(struct coder *coder,int *input, int *length, int        int i;        int output_length=0; -      coder->stat_numval=0; -      coder->stat_overflow=0; +      coder_inst->stat_numval=0; +      coder_inst->stat_overflow=0;        /* Allocate enough memory for output */        output=warnmalloc(8* *length*sizeof *output);        output_ptr=output; @@ -287,9 +287,9 @@ unsigned char *Ptngc_pack_array(struct coder *coder,int *input, int *length, int  		intmax=s;  	    }  	  /* Store intmax */ -	  coder->pack_temporary_bits=32; -	  coder->pack_temporary=intmax; -	  Ptngc_out8bits(coder,&output_ptr); +	  coder_inst->pack_temporary_bits=32; +	  coder_inst->pack_temporary=intmax; +	  Ptngc_out8bits(coder_inst,&output_ptr);  	  while (intmax>=max_base)  	    {  	      max_base*=2; @@ -309,7 +309,7 @@ unsigned char *Ptngc_pack_array(struct coder *coder,int *input, int *length, int  		  else if (item<0)  		    s[j]=2+(-item-1)*2;  		} -	      if (pack_triplet(coder,s,&output_ptr,coding_parameter,max_base,maxbits)) +	      if (pack_triplet(coder_inst,s,&output_ptr,coding_parameter,max_base,maxbits))  		{  		  free(output);  		  return NULL; @@ -318,21 +318,21 @@ unsigned char *Ptngc_pack_array(struct coder *coder,int *input, int *length, int  	}        else  	for (i=0; i<*length; i++) -	  if (pack_stopbits_item(coder,input[i],&output_ptr,coding_parameter)) +	  if (pack_stopbits_item(coder_inst,input[i],&output_ptr,coding_parameter))  	    {  	      free(output);  	      return NULL;  	    } -      Ptngc_pack_flush(coder,&output_ptr); +      Ptngc_pack_flush(coder_inst,&output_ptr);        output_length=(int)(output_ptr-output);        *length=output_length;        return output;      }  } -static int unpack_array_stop_bits(struct coder *coder,unsigned char *packed,int *output, int length, int coding_parameter) +static int unpack_array_stop_bits(struct coder *coder_inst,unsigned char *packed,int *output, int length, int coding_parameter)  { -  (void)coder; +  (void)coder_inst;    int i,j;    unsigned int extract_mask=0x80;    unsigned char *ptr=packed; @@ -383,9 +383,9 @@ static int unpack_array_stop_bits(struct coder *coder,unsigned char *packed,int    return 0;  } -static int unpack_array_triplet(struct coder *coder,unsigned char *packed,int *output, int length, int coding_parameter) +static int unpack_array_triplet(struct coder *coder_inst,unsigned char *packed,int *output, int length, int coding_parameter)  { -  (void)coder; +  (void)coder_inst;    int i,j;    unsigned int extract_mask=0x80;    unsigned char *ptr=packed; @@ -455,9 +455,9 @@ static int unpack_array_triplet(struct coder *coder,unsigned char *packed,int *o    return 0;  } -static int unpack_array_bwlzh(struct coder *coder,unsigned char *packed,int *output, int length, int natoms) +static int unpack_array_bwlzh(struct coder *coder_inst,unsigned char *packed,int *output, int length, int natoms)  { -  (void)coder; +  (void)coder_inst;    int i,j,k,n=length;    unsigned int *pval=warnmalloc(n*sizeof *pval);    int nframes=n/natoms/3; @@ -478,19 +478,19 @@ static int unpack_array_bwlzh(struct coder *coder,unsigned char *packed,int *out    return 0;  } -int Ptngc_unpack_array(struct coder *coder,unsigned char *packed,int *output, int length, int coding, int coding_parameter, int natoms) +int Ptngc_unpack_array(struct coder *coder_inst,unsigned char *packed,int *output, int length, int coding, int coding_parameter, int natoms)  {    if ((coding==TNG_COMPRESS_ALGO_STOPBIT) ||        (coding==TNG_COMPRESS_ALGO_VEL_STOPBIT_INTER)) -    return unpack_array_stop_bits(coder, packed, output, length, coding_parameter); +    return unpack_array_stop_bits(coder_inst, packed, output, length, coding_parameter);    else if ((coding==TNG_COMPRESS_ALGO_TRIPLET) ||  	   (coding==TNG_COMPRESS_ALGO_POS_TRIPLET_INTRA) ||  	   (coding==TNG_COMPRESS_ALGO_POS_TRIPLET_ONETOONE)) -    return unpack_array_triplet(coder, packed, output, length, coding_parameter); +    return unpack_array_triplet(coder_inst, packed, output, length, coding_parameter);    else if (coding==TNG_COMPRESS_ALGO_POS_XTC2) -    return Ptngc_unpack_array_xtc2(coder, packed, output, length); +    return Ptngc_unpack_array_xtc2(coder_inst, packed, output, length);    else if ((coding==TNG_COMPRESS_ALGO_BWLZH1) || (coding==TNG_COMPRESS_ALGO_BWLZH2)) -    return unpack_array_bwlzh(coder, packed, output, length,natoms); +    return unpack_array_bwlzh(coder_inst, packed, output, length,natoms);    else if (coding==TNG_COMPRESS_ALGO_POS_XTC3)      return Ptngc_unpack_array_xtc3(packed, output, length,natoms);    return 1; diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index ef59ed5..4e46c4e 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(tng_io SHARED tng_io.c md5.c) +add_library(tng_io tng_io.c md5.c)  if(HAVE_INTTYPES_H)    set_property(TARGET tng_io APPEND PROPERTY COMPILE_DEFINITIONS USE_STD_INTTYPES_H) diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index ecfb4c5..a4fe668 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -4100,6 +4100,7 @@ static tng_function_status tng_gzip_uncompress(tng_trajectory_t tng_data,                                                 void *start_pos,                                                 unsigned long uncompressed_len)  { +    (void)tng_data;      Bytef *dest;      char *temp;      unsigned long stat; @@ -4174,6 +4175,7 @@ static tng_function_status tng_allocate_particle_data_mem                   const int64_t n_particles,                   const int64_t n_values_per_frame)  { +    (void)tng_data;      void ***values;      int64_t i, j, k, size, frame_alloc;  | 
