changed reading hint
[gromacs/adressmacs.git] / src / gmxlib / lutab.c
blob1570876fd2fd524678eb2899b6606ae3134e37a6
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 2.0
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
16 * Please refer to:
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
23 * or e-mail to:
24 * gromacs@chem.rug.nl
26 * And Hey:
27 * Green Red Orange Magenta Azure Cyan Skyblue
29 static char *SRCID_lutab_c = "$Id$";
32 * Invsqrt lookup tables @(#) gentab.c 1.9 11/5/92
34 * Copyright (c) 1992, A. Sijbers, Groningen University
36 #include <math.h>
37 #include "lutab.h"
38 #include "callf77.h"
40 /* Global variable that is exported */
41 t_lutab lookup_table;
43 static void init_table(t_lutab *lookup_table)
45 word index,addr;
46 int new_exp,i,exp;
47 t_convert bit_in,bit_out;
49 for (i=0; i<EXP_SEED_SIZE; i++)
50 lookup_table->exp_seed[i]=NOT_INITIALISED;
51 for (i=0; i<FRACT_SEED_SIZE; i++)
52 lookup_table->fract_seed[i]=NOT_INITIALISED;
53 for (i=0; i<EXP_SEED_SIZE; i++)
55 if ((exp=(i-127))<0) new_exp=127-((exp+1)/2); else new_exp=127-(exp/2)-1;
56 lookup_table->exp_seed[i]=((new_exp)<<EXP_SHIFT)&EXP_MASK;
58 index=FRACT_FIRST;
59 for (i=0; i<FRACT_SEED_SIZE; i++)
61 bit_in.bval=(index<<FRACT_SHIFT);
62 addr=FRACT_ADDR(bit_in.bval);
63 bit_out.fval=(1.0/sqrt(bit_in.fval));
64 lookup_table->fract_seed[addr]=(bit_out.bval&FRACT_MASK);
65 if (lookup_table->fract_seed[addr]==0)
66 lookup_table->fract_seed[addr]=(MAX_FRACT&FRACT_MASK);
67 index++;
71 void init_lookup_table(FILE *log)
73 #ifdef CINVSQRT
74 if(log!=NULL)
75 fprintf(log,"Generating lookup table for invsqrt calculation in C\n");
76 init_table(&lookup_table);
77 #endif
78 #ifdef USEF77
79 #ifdef FINVSQRT
80 if(log!=NULL)
81 fprintf(log,"Generating lookup table for invsqrt calculation in Fortran\n");
82 fillbuf();
83 #endif
84 #endif