*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#define XDR_INT_SIZE 4
/* same order as the definition of xdr_datatype */
-const char *xdr_datatype_names[] =
-{
- "int",
- "float",
- "double",
- "large int",
- "char",
- "string"
-};
+const char* xdr_datatype_names[] = { "int", "float", "double", "large int", "char", "string" };
/*___________________________________________________________________________
| with some routines to assist in this task (those are marked
| static and cannot be called from user programs)
*/
-#define MAXABS (INT_MAX-2)
+#define MAXABS (INT_MAX - 2)
#ifndef SQR
-#define SQR(x) ((x)*(x))
+# define SQR(x) ((x) * (x))
#endif
static const int magicints[] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 8, 10, 12, 16, 20, 25, 32, 40, 50, 64,
- 80, 101, 128, 161, 203, 256, 322, 406, 512, 645,
- 812, 1024, 1290, 1625, 2048, 2580, 3250, 4096, 5060, 6501,
- 8192, 10321, 13003, 16384, 20642, 26007, 32768, 41285, 52015, 65536,
- 82570, 104031, 131072, 165140, 208063, 262144, 330280, 416127, 524287, 660561,
- 832255, 1048576, 1321122, 1664510, 2097152, 2642245, 3329021, 4194304, 5284491, 6658042,
- 8388607, 10568983, 13316085, 16777216
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
+ 10, 12, 16, 20, 25, 32, 40, 50, 64, 80,
+ 101, 128, 161, 203, 256, 322, 406, 512, 645, 812,
+ 1024, 1290, 1625, 2048, 2580, 3250, 4096, 5060, 6501, 8192,
+ 10321, 13003, 16384, 20642, 26007, 32768, 41285, 52015, 65536, 82570,
+ 104031, 131072, 165140, 208063, 262144, 330280, 416127, 524287, 660561, 832255,
+ 1048576, 1321122, 1664510, 2097152, 2642245, 3329021, 4194304, 5284491, 6658042, 8388607,
+ 10568983, 13316085, 16777216
};
#define FIRSTIDX 9
static void sendbits(int buf[], int num_of_bits, int num)
{
- unsigned int cnt, lastbyte;
- int lastbits;
- unsigned char * cbuf;
+ unsigned int cnt, lastbyte;
+ int lastbits;
+ unsigned char* cbuf;
- cbuf = (reinterpret_cast<unsigned char *>(buf)) + 3 * sizeof(*buf);
+ cbuf = (reinterpret_cast<unsigned char*>(buf)) + 3 * sizeof(*buf);
cnt = static_cast<unsigned int>(buf[0]);
lastbits = buf[1];
lastbyte = static_cast<unsigned int>(buf[2]);
while (num_of_bits >= 8)
{
- lastbyte = (lastbyte << 8) | ((num >> (num_of_bits -8)) /* & 0xff*/);
- cbuf[cnt++] = lastbyte >> lastbits;
+ lastbyte = (lastbyte << 8) | ((num >> (num_of_bits - 8)) /* & 0xff*/);
+ cbuf[cnt++] = lastbyte >> lastbits;
num_of_bits -= 8;
}
if (num_of_bits > 0)
{
- lastbyte = (lastbyte << num_of_bits) | num;
+ lastbyte = (lastbyte << num_of_bits) | num;
lastbits += num_of_bits;
if (lastbits >= 8)
{
- lastbits -= 8;
+ lastbits -= 8;
cbuf[cnt++] = lastbyte >> lastbits;
}
}
| So I don't need to call 'sizeofints for those calls.
*/
-static int sizeofints( const int num_of_ints, const unsigned int sizes[])
+static int sizeofints(const int num_of_ints, const unsigned int sizes[])
{
int i, num;
int bytes[32];
{
tmp = bytes[bytecnt] * sizes[i] + tmp;
bytes[bytecnt] = tmp & 0xff;
- tmp >>= 8;
+ tmp >>= 8;
}
while (tmp != 0)
{
bytes[bytecnt++] = tmp & 0xff;
- tmp >>= 8;
+ tmp >>= 8;
}
num_of_bytes = bytecnt;
}
num *= 2;
}
return num_of_bits + num_of_bytes * 8;
-
}
/*____________________________________________________________________________
|
*/
-static void sendints(int buf[], const int num_of_ints, const int num_of_bits,
- unsigned int sizes[], unsigned int nums[])
+static void sendints(int buf[],
+ const int num_of_ints,
+ const int num_of_bits,
+ unsigned int sizes[],
+ unsigned int nums[])
{
int i, num_of_bytes, bytecnt;
do
{
bytes[num_of_bytes++] = tmp & 0xff;
- tmp >>= 8;
- }
- while (tmp != 0);
+ tmp >>= 8;
+ } while (tmp != 0);
for (i = 1; i < num_of_ints; i++)
{
if (nums[i] >= sizes[i])
{
- fprintf(stderr, "major breakdown in sendints num %u doesn't "
- "match size %u\n", nums[i], sizes[i]);
+ fprintf(stderr,
+ "major breakdown in sendints num %u doesn't "
+ "match size %u\n",
+ nums[i], sizes[i]);
exit(1);
}
/* use one step multiply */
{
tmp = bytes[bytecnt] * sizes[i] + tmp;
bytes[bytecnt] = tmp & 0xff;
- tmp >>= 8;
+ tmp >>= 8;
}
while (tmp != 0)
{
bytes[bytecnt++] = tmp & 0xff;
- tmp >>= 8;
+ tmp >>= 8;
}
num_of_bytes = bytecnt;
}
}
else
{
- for (i = 0; i < num_of_bytes-1; i++)
+ for (i = 0; i < num_of_bytes - 1; i++)
{
sendbits(buf, 8, bytes[i]);
}
- sendbits(buf, num_of_bits- (num_of_bytes -1) * 8, bytes[i]);
+ sendbits(buf, num_of_bits - (num_of_bytes - 1) * 8, bytes[i]);
}
}
static int receivebits(int buf[], int num_of_bits)
{
- int cnt, num, lastbits;
- unsigned int lastbyte;
- unsigned char * cbuf;
- int mask = (1 << num_of_bits) -1;
+ int cnt, num, lastbits;
+ unsigned int lastbyte;
+ unsigned char* cbuf;
+ int mask = (1 << num_of_bits) - 1;
- cbuf = reinterpret_cast<unsigned char *>(buf) + 3 * sizeof(*buf);
+ cbuf = reinterpret_cast<unsigned char*>(buf) + 3 * sizeof(*buf);
cnt = buf[0];
lastbits = static_cast<unsigned int>(buf[1]);
lastbyte = static_cast<unsigned int>(buf[2]);
num = 0;
while (num_of_bits >= 8)
{
- lastbyte = ( lastbyte << 8 ) | cbuf[cnt++];
- num |= (lastbyte >> lastbits) << (num_of_bits - 8);
+ lastbyte = (lastbyte << 8) | cbuf[cnt++];
+ num |= (lastbyte >> lastbits) << (num_of_bits - 8);
num_of_bits -= 8;
}
if (num_of_bits > 0)
if (lastbits < num_of_bits)
{
lastbits += 8;
- lastbyte = (lastbyte << 8) | cbuf[cnt++];
+ lastbyte = (lastbyte << 8) | cbuf[cnt++];
}
lastbits -= num_of_bits;
- num |= (lastbyte >> lastbits) & ((1 << num_of_bits) -1);
+ num |= (lastbyte >> lastbits) & ((1 << num_of_bits) - 1);
}
- num &= mask;
+ num &= mask;
buf[0] = cnt;
buf[1] = lastbits;
buf[2] = lastbyte;
|
*/
-static void receiveints(int buf[], const int num_of_ints, int num_of_bits,
- const unsigned int sizes[], int nums[])
+static void receiveints(int buf[], const int num_of_ints, int num_of_bits, const unsigned int sizes[], int nums[])
{
int bytes[32];
int i, j, num_of_bytes, p, num;
- bytes[0] = bytes[1] = bytes[2] = bytes[3] = 0;
- num_of_bytes = 0;
+ bytes[0] = bytes[1] = bytes[2] = bytes[3] = 0;
+ num_of_bytes = 0;
while (num_of_bits > 8)
{
bytes[num_of_bytes++] = receivebits(buf, 8);
- num_of_bits -= 8;
+ num_of_bits -= 8;
}
if (num_of_bits > 0)
{
bytes[num_of_bytes++] = receivebits(buf, num_of_bits);
}
- for (i = num_of_ints-1; i > 0; i--)
+ for (i = num_of_ints - 1; i > 0; i--)
{
num = 0;
- for (j = num_of_bytes-1; j >= 0; j--)
+ for (j = num_of_bytes - 1; j >= 0; j--)
{
num = (num << 8) | bytes[j];
p = num / sizes[i];
|
*/
-int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision)
+int xdr3dfcoord(XDR* xdrs, float* fp, int* size, float* precision)
{
- int *ip = nullptr;
- int *buf = nullptr;
+ int* ip = nullptr;
+ int* buf = nullptr;
gmx_bool bRead;
/* preallocate a small buffer and ip on the stack - if we need more
we can always malloc(). This is faster for small values of size: */
- unsigned prealloc_size = 3*16;
- int prealloc_ip[3*16], prealloc_buf[3*20];
- int we_should_free = 0;
+ unsigned prealloc_size = 3 * 16;
+ int prealloc_ip[3 * 16], prealloc_buf[3 * 20];
+ int we_should_free = 0;
int minint[3], maxint[3], mindiff, *lip, diff;
int lint1, lint2, lint3, oldlint1, oldlint2, oldlint3, smallidx;
unsigned sizeint[3], sizesmall[3], bitsizeint[3], size3, *luip;
int flag, k;
int smallnum, smaller, larger, i, is_small, is_smaller, run, prevrun;
- float *lfp, lf;
- int tmp, *thiscoord, prevcoord[3];
+ float * lfp, lf;
+ int tmp, *thiscoord, prevcoord[3];
unsigned int tmpcoord[30];
int bufsize, lsize;
bRead = (xdrs->x_op == XDR_DECODE);
bitsizeint[0] = bitsizeint[1] = bitsizeint[2] = 0;
- prevcoord[0] = prevcoord[1] = prevcoord[2] = 0;
+ prevcoord[0] = prevcoord[1] = prevcoord[2] = 0;
// The static analyzer warns about garbage values for thiscoord[] further
// down. It might be thrown off by all the reinterpret_casts, but we might
*/
if (*size <= 9)
{
- return (xdr_vector(xdrs, reinterpret_cast<char *>(fp), static_cast<unsigned int>(size3),
- static_cast<unsigned int>(sizeof(*fp)), reinterpret_cast<xdrproc_t>(xdr_float)));
+ return (xdr_vector(xdrs, reinterpret_cast<char*>(fp), static_cast<unsigned int>(size3),
+ static_cast<unsigned int>(sizeof(*fp)),
+ reinterpret_cast<xdrproc_t>(xdr_float)));
}
if (xdr_float(xdrs, precision) == 0)
{
we_should_free = 1;
bufsize = static_cast<int>(size3 * 1.2);
- ip = reinterpret_cast<int *>(malloc(size3 * sizeof(*ip)));
- buf = reinterpret_cast<int *>(malloc(bufsize * sizeof(*buf)));
+ ip = reinterpret_cast<int*>(malloc(size3 * sizeof(*ip)));
+ buf = reinterpret_cast<int*>(malloc(bufsize * sizeof(*buf)));
if (ip == nullptr || buf == nullptr)
{
fprintf(stderr, "malloc failed\n");
}
}
/* buf[0-2] are special and do not contain actual data */
- buf[0] = buf[1] = buf[2] = 0;
+ buf[0] = buf[1] = buf[2] = 0;
minint[0] = minint[1] = minint[2] = INT_MAX;
maxint[0] = maxint[1] = maxint[2] = INT_MIN;
- prevrun = -1;
- lfp = fp;
- lip = ip;
- mindiff = INT_MAX;
- oldlint1 = oldlint2 = oldlint3 = 0;
+ prevrun = -1;
+ lfp = fp;
+ lip = ip;
+ mindiff = INT_MAX;
+ oldlint1 = oldlint2 = oldlint3 = 0;
while (lfp < fp + size3)
{
/* find nearest integer */
}
*lip++ = lint3;
lfp++;
- diff = std::abs(oldlint1-lint1)+std::abs(oldlint2-lint2)+std::abs(oldlint3-lint3);
+ diff = std::abs(oldlint1 - lint1) + std::abs(oldlint2 - lint2) + std::abs(oldlint3 - lint3);
if (diff < mindiff && lfp > fp + 3)
{
mindiff = diff;
oldlint2 = lint2;
oldlint3 = lint3;
}
- if ( (xdr_int(xdrs, &(minint[0])) == 0) ||
- (xdr_int(xdrs, &(minint[1])) == 0) ||
- (xdr_int(xdrs, &(minint[2])) == 0) ||
- (xdr_int(xdrs, &(maxint[0])) == 0) ||
- (xdr_int(xdrs, &(maxint[1])) == 0) ||
- (xdr_int(xdrs, &(maxint[2])) == 0))
+ if ((xdr_int(xdrs, &(minint[0])) == 0) || (xdr_int(xdrs, &(minint[1])) == 0)
+ || (xdr_int(xdrs, &(minint[2])) == 0) || (xdr_int(xdrs, &(maxint[0])) == 0)
+ || (xdr_int(xdrs, &(maxint[1])) == 0) || (xdr_int(xdrs, &(maxint[2])) == 0))
{
if (we_should_free)
{
return 0;
}
- if (static_cast<float>(maxint[0]) - static_cast<float>(minint[0]) >= MAXABS ||
- static_cast<float>(maxint[1]) - static_cast<float>(minint[1]) >= MAXABS ||
- static_cast<float>(maxint[2]) - static_cast<float>(minint[2]) >= MAXABS)
+ if (static_cast<float>(maxint[0]) - static_cast<float>(minint[0]) >= MAXABS
+ || static_cast<float>(maxint[1]) - static_cast<float>(minint[1]) >= MAXABS
+ || static_cast<float>(maxint[2]) - static_cast<float>(minint[2]) >= MAXABS)
{
/* turning value in unsigned by subtracting minint
* would cause overflow
*/
errval = 0;
}
- sizeint[0] = maxint[0] - minint[0]+1;
- sizeint[1] = maxint[1] - minint[1]+1;
- sizeint[2] = maxint[2] - minint[2]+1;
+ sizeint[0] = maxint[0] - minint[0] + 1;
+ sizeint[1] = maxint[1] - minint[1] + 1;
+ sizeint[2] = maxint[2] - minint[2] + 1;
/* check if one of the sizes is to big to be multiplied */
- if ((sizeint[0] | sizeint[1] | sizeint[2] ) > 0xffffff)
+ if ((sizeint[0] | sizeint[1] | sizeint[2]) > 0xffffff)
{
bitsizeint[0] = sizeofint(sizeint[0]);
bitsizeint[1] = sizeofint(sizeint[1]);
{
bitsize = sizeofints(3, sizeint);
}
- luip = reinterpret_cast<unsigned int *>(ip);
+ luip = reinterpret_cast<unsigned int*>(ip);
smallidx = FIRSTIDX;
while (smallidx < LASTIDX && magicints[smallidx] < mindiff)
{
maxidx = std::min(LASTIDX, smallidx + 8);
minidx = maxidx - 8; /* often this equal smallidx */
- smaller = magicints[std::max(FIRSTIDX, smallidx-1)] / 2;
+ smaller = magicints[std::max(FIRSTIDX, smallidx - 1)] / 2;
smallnum = magicints[smallidx] / 2;
sizesmall[0] = sizesmall[1] = sizesmall[2] = magicints[smallidx];
- larger = magicints[maxidx] / 2;
- i = 0;
+ larger = magicints[maxidx] / 2;
+ i = 0;
while (i < *size)
{
is_small = 0;
- thiscoord = reinterpret_cast<int *>(luip) + i * 3;
- if (smallidx < maxidx && i >= 1 &&
- std::abs(thiscoord[0] - prevcoord[0]) < larger &&
- std::abs(thiscoord[1] - prevcoord[1]) < larger &&
- std::abs(thiscoord[2] - prevcoord[2]) < larger)
+ thiscoord = reinterpret_cast<int*>(luip) + i * 3;
+ if (smallidx < maxidx && i >= 1 && std::abs(thiscoord[0] - prevcoord[0]) < larger
+ && std::abs(thiscoord[1] - prevcoord[1]) < larger
+ && std::abs(thiscoord[2] - prevcoord[2]) < larger)
{
is_smaller = 1;
}
}
if (i + 1 < *size)
{
- if (std::abs(thiscoord[0] - thiscoord[3]) < smallnum &&
- std::abs(thiscoord[1] - thiscoord[4]) < smallnum &&
- std::abs(thiscoord[2] - thiscoord[5]) < smallnum)
+ if (std::abs(thiscoord[0] - thiscoord[3]) < smallnum
+ && std::abs(thiscoord[1] - thiscoord[4]) < smallnum
+ && std::abs(thiscoord[2] - thiscoord[5]) < smallnum)
{
/* interchange first with second atom for better
* compression of water molecules
*/
- tmp = thiscoord[0]; thiscoord[0] = thiscoord[3];
+ tmp = thiscoord[0];
+ thiscoord[0] = thiscoord[3];
thiscoord[3] = tmp;
- tmp = thiscoord[1]; thiscoord[1] = thiscoord[4];
+ tmp = thiscoord[1];
+ thiscoord[1] = thiscoord[4];
thiscoord[4] = tmp;
- tmp = thiscoord[2]; thiscoord[2] = thiscoord[5];
+ tmp = thiscoord[2];
+ thiscoord[2] = thiscoord[5];
thiscoord[5] = tmp;
is_small = 1;
}
-
}
tmpcoord[0] = thiscoord[0] - minint[0];
tmpcoord[1] = thiscoord[1] - minint[1];
{
is_smaller = 0;
}
- while (is_small && run < 8*3)
+ while (is_small && run < 8 * 3)
{
- if (is_smaller == -1 && (
- SQR(thiscoord[0] - prevcoord[0]) +
- SQR(thiscoord[1] - prevcoord[1]) +
- SQR(thiscoord[2] - prevcoord[2]) >= smaller * smaller))
+ if (is_smaller == -1
+ && (SQR(thiscoord[0] - prevcoord[0]) + SQR(thiscoord[1] - prevcoord[1])
+ + SQR(thiscoord[2] - prevcoord[2])
+ >= smaller * smaller))
{
is_smaller = 0;
}
i++;
thiscoord = thiscoord + 3;
is_small = 0;
- if (i < *size &&
- abs(thiscoord[0] - prevcoord[0]) < smallnum &&
- abs(thiscoord[1] - prevcoord[1]) < smallnum &&
- abs(thiscoord[2] - prevcoord[2]) < smallnum)
+ if (i < *size && abs(thiscoord[0] - prevcoord[0]) < smallnum
+ && abs(thiscoord[1] - prevcoord[1]) < smallnum
+ && abs(thiscoord[2] - prevcoord[2]) < smallnum)
{
is_small = 1;
}
{
prevrun = run;
sendbits(buf, 1, 1); /* flag the change in run-length */
- sendbits(buf, 5, run+is_smaller+1);
+ sendbits(buf, 5, run + is_smaller + 1);
}
else
{
if (is_smaller < 0)
{
smallnum = smaller;
- smaller = magicints[smallidx-1] / 2;
+ smaller = magicints[smallidx - 1] / 2;
}
else
{
}
- rc = errval * (xdr_opaque(xdrs, reinterpret_cast<char *>(&(buf[3])), static_cast<unsigned int>(buf[0])));
+ rc = errval
+ * (xdr_opaque(xdrs, reinterpret_cast<char*>(&(buf[3])), static_cast<unsigned int>(buf[0])));
if (we_should_free)
{
free(ip);
free(buf);
}
return rc;
-
}
else
{
}
if (*size != 0 && lsize != *size)
{
- fprintf(stderr, "wrong number of coordinates in xdr3dfcoord; "
- "%d arg vs %d in file", *size, lsize);
+ fprintf(stderr,
+ "wrong number of coordinates in xdr3dfcoord; "
+ "%d arg vs %d in file",
+ *size, lsize);
}
*size = lsize;
size3 = *size * 3;
if (*size <= 9)
{
*precision = -1;
- return (xdr_vector(xdrs, reinterpret_cast<char *>(fp), static_cast<unsigned int>(size3),
- static_cast<unsigned int>(sizeof(*fp)), reinterpret_cast<xdrproc_t>(xdr_float)));
+ return (xdr_vector(xdrs, reinterpret_cast<char*>(fp), static_cast<unsigned int>(size3),
+ static_cast<unsigned int>(sizeof(*fp)),
+ reinterpret_cast<xdrproc_t>(xdr_float)));
}
if (xdr_float(xdrs, precision) == 0)
{
{
we_should_free = 1;
bufsize = static_cast<int>(size3 * 1.2);
- ip = reinterpret_cast<int *>(malloc(size3 * sizeof(*ip)));
- buf = reinterpret_cast<int *>(malloc(bufsize * sizeof(*buf)));
+ ip = reinterpret_cast<int*>(malloc(size3 * sizeof(*ip)));
+ buf = reinterpret_cast<int*>(malloc(bufsize * sizeof(*buf)));
if (ip == nullptr || buf == nullptr)
{
fprintf(stderr, "malloc failed\n");
buf[0] = buf[1] = buf[2] = 0;
- if ( (xdr_int(xdrs, &(minint[0])) == 0) ||
- (xdr_int(xdrs, &(minint[1])) == 0) ||
- (xdr_int(xdrs, &(minint[2])) == 0) ||
- (xdr_int(xdrs, &(maxint[0])) == 0) ||
- (xdr_int(xdrs, &(maxint[1])) == 0) ||
- (xdr_int(xdrs, &(maxint[2])) == 0))
+ if ((xdr_int(xdrs, &(minint[0])) == 0) || (xdr_int(xdrs, &(minint[1])) == 0)
+ || (xdr_int(xdrs, &(minint[2])) == 0) || (xdr_int(xdrs, &(maxint[0])) == 0)
+ || (xdr_int(xdrs, &(maxint[1])) == 0) || (xdr_int(xdrs, &(maxint[2])) == 0))
{
if (we_should_free)
{
return 0;
}
- sizeint[0] = maxint[0] - minint[0]+1;
- sizeint[1] = maxint[1] - minint[1]+1;
- sizeint[2] = maxint[2] - minint[2]+1;
+ sizeint[0] = maxint[0] - minint[0] + 1;
+ sizeint[1] = maxint[1] - minint[1] + 1;
+ sizeint[2] = maxint[2] - minint[2] + 1;
/* check if one of the sizes is to big to be multiplied */
- if ((sizeint[0] | sizeint[1] | sizeint[2] ) > 0xffffff)
+ if ((sizeint[0] | sizeint[1] | sizeint[2]) > 0xffffff)
{
bitsizeint[0] = sizeofint(sizeint[0]);
bitsizeint[1] = sizeofint(sizeint[1]);
return 0;
}
- smaller = magicints[std::max(FIRSTIDX, smallidx-1)] / 2;
+ smaller = magicints[std::max(FIRSTIDX, smallidx - 1)] / 2;
smallnum = magicints[smallidx] / 2;
sizesmall[0] = sizesmall[1] = sizesmall[2] = magicints[smallidx];
}
- if (xdr_opaque(xdrs, reinterpret_cast<char *>(&(buf[3])), static_cast<unsigned int>(buf[0])) == 0)
+ if (xdr_opaque(xdrs, reinterpret_cast<char*>(&(buf[3])), static_cast<unsigned int>(buf[0])) == 0)
{
if (we_should_free)
{
}
-
buf[0] = buf[1] = buf[2] = 0;
lfp = fp;
lip = ip;
while (i < lsize)
{
- thiscoord = reinterpret_cast<int *>(lip) + i * 3;
+ thiscoord = reinterpret_cast<int*>(lip) + i * 3;
if (bitsize == 0)
{
{
run = receivebits(buf, 5);
is_smaller = run % 3;
- run -= is_smaller;
+ run -= is_smaller;
is_smaller--;
}
if (run > 0)
/* interchange first with second atom for better
* compression of water molecules
*/
- tmp = thiscoord[0]; thiscoord[0] = prevcoord[0];
+ tmp = thiscoord[0];
+ thiscoord[0] = prevcoord[0];
prevcoord[0] = tmp;
- tmp = thiscoord[1]; thiscoord[1] = prevcoord[1];
+ tmp = thiscoord[1];
+ thiscoord[1] = prevcoord[1];
prevcoord[1] = tmp;
- tmp = thiscoord[2]; thiscoord[2] = prevcoord[2];
+ tmp = thiscoord[2];
+ thiscoord[2] = prevcoord[2];
prevcoord[2] = tmp;
*lfp++ = prevcoord[0] * inv_precision;
*lfp++ = prevcoord[1] * inv_precision;
smallnum = smaller;
if (smallidx > FIRSTIDX)
{
- smaller = magicints[smallidx - 1] /2;
+ smaller = magicints[smallidx - 1] / 2;
}
else
{
}
-
/******************************************************************
XTC files have a relatively simple structure.
/* Must match definition in xtcio.c */
#ifndef XTC_MAGIC
-#define XTC_MAGIC 1995
+# define XTC_MAGIC 1995
#endif
static const int header_size = 16;
/* Check if we are at the header start.
At the same time it will also read 1 int */
-static int xtc_at_header_start(FILE *fp, XDR *xdrs,
- int natoms, int * timestep, float * time)
+static int xtc_at_header_start(FILE* fp, XDR* xdrs, int natoms, int* timestep, float* time)
{
int i_inp[3];
float f_inp[10];
{
if (!xdr_int(xdrs, &(i_inp[i])))
{
- gmx_fseek(fp, off+XDR_INT_SIZE, SEEK_SET);
+ gmx_fseek(fp, off + XDR_INT_SIZE, SEEK_SET);
return -1;
}
}
/* quick return */
if (i_inp[0] != XTC_MAGIC)
{
- if (gmx_fseek(fp, off+XDR_INT_SIZE, SEEK_SET))
+ if (gmx_fseek(fp, off + XDR_INT_SIZE, SEEK_SET))
{
return -1;
}
{
if (!xdr_float(xdrs, &(f_inp[i])))
{
- gmx_fseek(fp, off+XDR_INT_SIZE, SEEK_SET);
+ gmx_fseek(fp, off + XDR_INT_SIZE, SEEK_SET);
return -1;
}
}
/* This check makes use of the fact that the box matrix has 3 zeroes on the upper
right triangle and that the first element must be nonzero unless the entire matrix is zero
*/
- if (i_inp[1] == natoms &&
- ((f_inp[1] != 0 && f_inp[6] == 0) ||
- (f_inp[1] == 0 && f_inp[5] == 0 && f_inp[9] == 0)))
+ if (i_inp[1] == natoms
+ && ((f_inp[1] != 0 && f_inp[6] == 0) || (f_inp[1] == 0 && f_inp[5] == 0 && f_inp[9] == 0)))
{
- if (gmx_fseek(fp, off+XDR_INT_SIZE, SEEK_SET))
+ if (gmx_fseek(fp, off + XDR_INT_SIZE, SEEK_SET))
{
return -1;
}
*timestep = i_inp[2];
return 1;
}
- if (gmx_fseek(fp, off+XDR_INT_SIZE, SEEK_SET))
+ if (gmx_fseek(fp, off + XDR_INT_SIZE, SEEK_SET))
{
return -1;
}
return 0;
}
-static int
-xtc_get_next_frame_number(FILE *fp, XDR *xdrs, int natoms)
+static int xtc_get_next_frame_number(FILE* fp, XDR* xdrs, int natoms)
{
gmx_off_t off;
int step;
}
-static float xtc_get_next_frame_time(FILE *fp, XDR *xdrs, int natoms,
- gmx_bool * bOK)
+static float xtc_get_next_frame_time(FILE* fp, XDR* xdrs, int natoms, gmx_bool* bOK)
{
gmx_off_t off;
float time;
}
-static float
-xtc_get_current_frame_time(FILE *fp, XDR *xdrs, int natoms, gmx_bool * bOK)
+static float xtc_get_current_frame_time(FILE* fp, XDR* xdrs, int natoms, gmx_bool* bOK)
{
gmx_off_t off;
int step;
else if (ret == 0)
{
/*Go back.*/
- if (gmx_fseek(fp, -2*XDR_INT_SIZE, SEEK_CUR))
+ if (gmx_fseek(fp, -2 * XDR_INT_SIZE, SEEK_CUR))
{
return -1;
}
}
/* Currently not used, just for completeness */
-static int
-xtc_get_current_frame_number(FILE *fp, XDR *xdrs, int natoms, gmx_bool * bOK)
+static int xtc_get_current_frame_number(FILE* fp, XDR* xdrs, int natoms, gmx_bool* bOK)
{
gmx_off_t off;
int ret;
return -1;
}
return -1;
-
}
else if (ret == 0)
{
/*Go back.*/
- if (gmx_fseek(fp, -2*XDR_INT_SIZE, SEEK_CUR))
+ if (gmx_fseek(fp, -2 * XDR_INT_SIZE, SEEK_CUR))
{
return -1;
}
}
-
-static gmx_off_t xtc_get_next_frame_start(FILE *fp, XDR *xdrs, int natoms)
+static gmx_off_t xtc_get_next_frame_start(FILE* fp, XDR* xdrs, int natoms)
{
gmx_off_t res;
int ret;
}
-static
-float
-xdr_xtc_estimate_dt(FILE *fp, XDR *xdrs, int natoms, gmx_bool * bOK)
+static float xdr_xtc_estimate_dt(FILE* fp, XDR* xdrs, int natoms, gmx_bool* bOK)
{
float res;
float tinit;
gmx_off_t off;
*bOK = false;
- if ((off = gmx_ftell(fp)) < 0)
+ if ((off = gmx_ftell(fp)) < 0)
{
return -1;
}
return res;
}
-int
-xdr_xtc_seek_frame(int frame, FILE *fp, XDR *xdrs, int natoms)
+int xdr_xtc_seek_frame(int frame, FILE* fp, XDR* xdrs, int natoms)
{
gmx_off_t low = 0;
gmx_off_t high, pos;
/* round to 4 bytes */
- int fr;
- gmx_off_t offset;
+ int fr;
+ gmx_off_t offset;
if (gmx_fseek(fp, 0, SEEK_END))
{
return -1;
}
/* round to 4 bytes */
- high /= XDR_INT_SIZE;
- high *= XDR_INT_SIZE;
- offset = ((high/2)/XDR_INT_SIZE)*XDR_INT_SIZE;
+ high /= XDR_INT_SIZE;
+ high *= XDR_INT_SIZE;
+ offset = ((high / 2) / XDR_INT_SIZE) * XDR_INT_SIZE;
if (gmx_fseek(fp, offset, SEEK_SET))
{
{
return -1;
}
- if (fr != frame && llabs(low-high) > header_size)
+ if (fr != frame && llabs(low - high) > header_size)
{
if (fr < frame)
{
high = offset;
}
/* round to 4 bytes */
- offset = (((high+low)/2)/4)*4;
+ offset = (((high + low) / 2) / 4) * 4;
if (gmx_fseek(fp, offset, SEEK_SET))
{
}
-
-int xdr_xtc_seek_time(real time, FILE *fp, XDR *xdrs, int natoms, gmx_bool bSeekForwardOnly)
+int xdr_xtc_seek_time(real time, FILE* fp, XDR* xdrs, int natoms, gmx_bool bSeekForwardOnly)
{
float t;
float dt;
if (bSeekForwardOnly)
{
- low = gmx_ftell(fp)-header_size;
+ low = gmx_ftell(fp) - header_size;
}
if (gmx_fseek(fp, 0, SEEK_END))
{
return -1;
}
/* round to int */
- high /= XDR_INT_SIZE;
- high *= XDR_INT_SIZE;
- offset = (((high-low) / 2) / XDR_INT_SIZE) * XDR_INT_SIZE;
+ high /= XDR_INT_SIZE;
+ high *= XDR_INT_SIZE;
+ offset = (((high - low) / 2) / XDR_INT_SIZE) * XDR_INT_SIZE;
if (gmx_fseek(fp, offset, SEEK_SET))
{
/*
- * No need to call xdr_xtc_estimate_dt here - since xdr_xtc_estimate_dt is called first thing in the loop
- dt = xdr_xtc_estimate_dt(fp, xdrs, natoms, &bOK);
+ * No need to call xdr_xtc_estimate_dt here - since xdr_xtc_estimate_dt is called first thing in
+ the loop dt = xdr_xtc_estimate_dt(fp, xdrs, natoms, &bOK);
if (!bOK)
{
/* If we are before the target time and the time step is positive or 0, or we have
after the target time and the time step is negative, or the difference between
- the current time and the target time is bigger than dt and above all the distance between high
- and low is bigger than 1 frame, then do another step of binary search. Otherwise stop and check
- if we reached the solution */
- if ((((t < time && dt_sign >= 0) || (t > time && dt_sign == -1)) ||
- ((t - time) >= dt && dt_sign >= 0) || ((time - t) >= -dt && dt_sign < 0)) &&
- (llabs(low - high) > header_size))
+ the current time and the target time is bigger than dt and above all the distance between
+ high and low is bigger than 1 frame, then do another step of binary search. Otherwise
+ stop and check if we reached the solution */
+ if ((((t < time && dt_sign >= 0) || (t > time && dt_sign == -1))
+ || ((t - time) >= dt && dt_sign >= 0) || ((time - t) >= -dt && dt_sign < 0))
+ && (llabs(low - high) > header_size))
{
if (dt >= 0 && dt_sign != -1)
{
return 0;
}
-float
-xdr_xtc_get_last_frame_time(FILE *fp, XDR *xdrs, int natoms, gmx_bool * bOK)
+float xdr_xtc_get_last_frame_time(FILE* fp, XDR* xdrs, int natoms, gmx_bool* bOK)
{
- float time;
- gmx_off_t off;
+ float time;
+ gmx_off_t off;
*bOK = true;
off = gmx_ftell(fp);
if (off < 0)
return -1;
}
- if (gmx_fseek(fp, -3*XDR_INT_SIZE, SEEK_END) != 0)
+ if (gmx_fseek(fp, -3 * XDR_INT_SIZE, SEEK_END) != 0)
{
*bOK = false;
return -1;
}
-int
-xdr_xtc_get_last_frame_number(FILE *fp, XDR *xdrs, int natoms, gmx_bool * bOK)
+int xdr_xtc_get_last_frame_number(FILE* fp, XDR* xdrs, int natoms, gmx_bool* bOK)
{
- int frame;
- gmx_off_t off;
+ int frame;
+ gmx_off_t off;
*bOK = true;
if ((off = gmx_ftell(fp)) < 0)
}
- if (gmx_fseek(fp, -3*XDR_INT_SIZE, SEEK_END))
+ if (gmx_fseek(fp, -3 * XDR_INT_SIZE, SEEK_END))
{
*bOK = false;
return -1;