Javi please update the SConsript files as well On Jan 28, 2009, at 3:26 PM, Notification of IMP commits wrote:
> Author: javi@SALILAB.ORG > Date: 2009-01-28 15:26:55 -0800 (Wed, 28 Jan 2009) > New Revision: 1333 > > Added: > trunk/modules/em/include/endian.h > trunk/modules/em/src/endian.cpp > Log: > Some small change to complete ImageHeader class > > Added: trunk/modules/em/include/endian.h > =================================================================== > --- trunk/modules/em/include/endian.h (rev 0) > +++ trunk/modules/em/include/endian.h 2009-01-28 23:26:55 UTC (rev > 1333) > @@ -0,0 +1,61 @@ > +/** > + * \file endian.h > + * \brief functions to deal with endian of EM images > + * \author Javier Velazquez-Muriel > + * Copyright 2007-8 Sali Lab. All rights reserved. > +*/ > + > +#ifndef IMPEM_ENDIAN_H > +#define IMPEM_ENDIAN_H > + > +#include "em_exports.h" > +#include <iostream> > +#include <fstream> > +#include <cstring> > +#include <cstdio> > + > +IMPEM_BEGIN_NAMESPACE > + > +//! Reads from file in normal or reverse order > +/** \ingroup LittleBigEndian > + * \param[in] reverse If true, the data will be read in reverse > order. > + */ > +void reversed_read(void *dest, size_t size, size_t nitems, > std::ifstream& f, > + bool reverse); > + > +//! Writes to a file in normal or reversed order > +/** > + * \ingroup LittleBigEndian > + * > + * This function is the same as fread from C, but at the end there > is a flag > + * saying if data should be read in reverse order or not. > + * > + * \param[in] reverse If true, the data will be read in reverse > order. > + */ > +void reversed_write(const void* src,size_t size,size_t nitems, > + std::ofstream& f,bool reverse = false); > + > + > +//! Conversion between little and big endian. Goes both ways > +/** > + * \ingroup LittleBigEndian > + */ > +#define little22bigendian(x) byte_swap((unsigned char*)& x,sizeof(x)) > +void byte_swap(unsigned char* b, int n); > + > +//! Returns 1 if machine is big endian else 0 > +/** > + * \ingroup LittleBigEndian > + */ > +bool is_big_endian(void); > + > +//! Returns 1 if machine is little endian else 0 > +/** > + * \ingroup LittleBigEndian > + */ > +bool is_little_endian(void); > + > + > +IMPEM_END_NAMESPACE > + > +#endif /* IMPEM_ENDIAN_H */ > > Added: trunk/modules/em/src/endian.cpp > =================================================================== > --- trunk/modules/em/src/endian.cpp (rev 0) > +++ trunk/modules/em/src/endian.cpp 2009-01-28 23:26:55 UTC (rev 1333) > @@ -0,0 +1,85 @@ > +/** > + * \file endian.cpp > + * \brief Calculate score based on fit to EM map. > + * Copyright 2007-8 Sali Lab. All rights reserved. > +*/ > + > +#include <IMP/em/endian.h> > + > +IMPEM_BEGIN_NAMESPACE > + > +void reversed_read(void *dest, size_t size, size_t nitems, > std::ifstream& f, > + bool reverse) > +{ > + if (!reverse) { > + char *ptr = (char *)dest; > + f.read(ptr,size*nitems); > + } else { > + char *ptr = (char *)dest; > + bool end = false; > + for (size_t n = 0; n < nitems; n++) { > + for (int i = size - 1; i >= 0; i--) { > + f.get(ptr + i,1); > + if (f.eof() || f.bad()) { > + end = true; > + break; > + } > + } > + if (end) { > + break; > + } > + ptr += size; > + } > + } > +} > + > +void reversed_write(const void *src, size_t size, size_t nitems, > + std::ofstream& f,bool reverse) > +{ > + if (!reverse) { > + char *ptr = (char *)src; > + f.write(ptr,size*nitems); > + } > + else { > + char *ptr = (char *)src; > + bool end = false; > + for (size_t n = 0; n < nitems; n++) { > + for (int i = size - 1; i >= 0; i--) { > + f.put(*(ptr + i)); > + if(f.bad()) { > + end = true; > + break; > + } > + } > + if (end) { > + break; > + } > + ptr += size; > + } > + } > +} > + > +void byte_swap(unsigned char * b, int n) > +{ > + register int i = 0; > + register int j = n - 1; > + while (i < j) { > + std::swap(b[i], b[j]); > + i++, j--; > + } > +} > + > +bool is_little_endian(void) > +{ > + static const unsigned long ul = 0x00000001; > + return ((int)(*((unsigned char *) &ul))) != 0; > +} > + > + > +bool is_big_endian(void) > +{ > + static const unsigned long ul = 0x01000000; > + return ((int)(*((unsigned char *) &ul))) != 0; > +} > + > +IMPEM_END_NAMESPACE > > _______________________________________________ > IMP-commits mailing list > IMP-commits@salilab.org > https://salilab.org/mailman/listinfo/imp-commits