NFFT Logo 3.0 API Reference
Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals

util.c

00001 
00006 #include "config.h"
00007 
00008 #include "util.h"
00009 
00010 #include <stdlib.h>
00011 #include <stdio.h>
00012 #include <math.h>
00013 #include <sys/time.h>
00014 #include <sys/resource.h>
00015 #ifdef HAVE_MALLOC_H
00016   #include <malloc.h>
00017 #endif
00018 
00019 /*#include <time.h>*/
00020 
00021 
00025 double nfft_second()
00026 {
00027   static struct rusage temp;
00028   double foo, foo1;
00029   
00030   getrusage(RUSAGE_SELF,&temp);
00031   foo     = temp.ru_utime.tv_sec;       /* seconds                           */
00032   foo1    = temp.ru_utime.tv_usec;      /* uSecs                             */
00033   return  foo  + (foo1/1000000.0);      /* milliseconds                      */
00034 }
00035 
00036 #ifdef HAVE_MALLOC_H
00037 int nfft_total_used_memory()
00038 {
00039   struct mallinfo m;
00040   m=mallinfo();
00041   return m.hblkhd + m.uordblks;
00042 }
00043 #else
00044 int nfft_total_used_memory()
00045 {
00046   fprintf(stderr,
00047     "\nWarning in util/total_used_memory: mallinfo() not available\n");
00048   return 0;
00049 }
00050 #endif
00051 
00052 int nfft_int_2_pow(int a)
00053 {
00054   return (1U<< a);
00055 }
00056 
00057 int nfft_ld(int m)
00058 {
00059   int l=0;
00060   int mm=m;
00061   
00062   while(mm>0)
00063     {
00064       mm=(mm>>1);
00065       l++;
00066     }
00067   return (l-1);
00068 }
00069 
00072 int nfft_next_power_of_2(int N)
00073 {
00074   int n,i,logn;
00075   int N_is_not_power_of_2=0;
00076 
00077   if (N == 0)
00078   {
00079     return 1;
00080   }
00081   else
00082   {
00083     n=N;
00084     logn=0;
00085     while (n != 1)
00086     {
00087       if (n%2 == 1)
00088       {
00089           N_is_not_power_of_2=1;
00090       }
00091       n = n/2;
00092       logn++;
00093     }
00094   
00095     if (!N_is_not_power_of_2)
00096     {
00097       logn--;
00098     }
00099   
00100     for (i = 0; i <= logn; i++)
00101     {
00102       n = n*2;
00103     }
00104   
00105     return n;
00106   }  
00107 }
00108  
00111 void nfft_next_power_of_2_exp(int N, int *N2, int *t)
00112 {
00113   int n,i,logn;
00114   int N_is_not_power_of_2=0;
00115 
00116   if (N == 0)
00117   {
00118     *N2 = 1;
00119     t = 0;
00120   }
00121   else
00122   {
00123     n=N;
00124     logn=0;
00125     while (n != 1)
00126     {
00127       if (n%2 == 1)
00128       {
00129           N_is_not_power_of_2=1;
00130       }
00131       n = n/2;
00132       logn++;
00133     }
00134   
00135     if (!N_is_not_power_of_2)
00136     {
00137       logn--;
00138     }
00139   
00140     for (i = 0; i <= logn; i++)
00141     {
00142       n = n*2;
00143     }
00144   
00145     *N2 = n;
00146     *t = logn+1;
00147   }  
00148 }
00149  
00152 int nfft_prod_int(int *vec, int d)
00153 {
00154   int t, prod;
00155 
00156   prod=1;
00157   for(t=0; t<d; t++)
00158     prod *= vec[t];
00159 
00160   return prod;
00161 }
00162 
00165 int nfct_prod_int(int *vec, int d)
00166 {
00167   return nfft_prod_int(vec, d);
00168 }
00169 
00172 int nfst_prod_minus_a_int(int *vec, int a, int d)
00173 {
00174   int t, prod;
00175 
00176   prod=1;
00177   for(t=0; t<d; t++)
00178     prod *= vec[t]-a;
00179 
00180   return prod;
00181 }
00182    
00183 
00186 int nfft_plain_loop(int *idx,int *N,int d)
00187 {
00188   int t,sum;
00189 
00190   sum=idx[0];
00191   for(t=1; t<d; t++)
00192     sum=sum*N[t]+idx[t];
00193 
00194   return sum;
00195 }
00196 
00199 double nfft_prod_real(double *vec,int d)
00200 {
00201   int t;
00202   double prod;
00203 
00204   prod=1.0;
00205   for(t=0; t<d; t++)
00206     prod*=vec[t];
00207 
00208   return prod;
00209 }
00210 
00211 double nfft_sinc(double x)
00212 {
00213   if (fabs(x) < 1e-20)
00214     return(1.0);
00215   else
00216     return((double)(sin(x)/x));
00217 } /* sinc */
00218 
00219 void bspline_help(int k, double x, double *scratch, int j, int ug, int og,
00220       int r)
00221 {
00222   int i;                                
00223   int index;                            
00224   double a;                             
00226   /* computation of one column */
00227   for(i=og+r-k+1, index=og; index>=ug; i--, index--)
00228     {
00229       a = ((double)(x - i)) / ((double)(k - j));
00230       scratch[index] = (1 - a) * scratch[index-1] + a * scratch[index];
00231     }
00232 } /* bspline_help */
00233 
00237 double nfft_bspline(int k, double x, double *scratch)
00238 {
00239   double result_value;                  
00240   int r;                                
00241   int g1,g2;                            
00242   int j,index,ug,og;                    
00243   double a;                             
00245   result_value=0.0;
00246   if(0<x && x<k)
00247     {
00248       /* using symmetry around k/2 */
00249       if((k-x)<x) x=k-x;
00250 
00251       r=(int)(ceil(x)-1.0);
00252       
00253       for(index=0; index<k; index++)
00254   scratch[index]=0.0;
00255   
00256       scratch[k-r-1]=1.0;
00257       
00258       /* bounds of the algorithm */
00259       g1 = r;
00260       g2 = k - 1 - r;
00261       ug = g2;
00262       
00263       /* g1<=g2 holds */
00264   
00265       for(j=1, og=g2+1; j<=g1; j++, og++)
00266   {
00267     a = (x - r + k - 1 - og)/(k - j);
00268     scratch[og] = (1 - a) * scratch[og-1];
00269     bspline_help(k,x,scratch,j,ug+1,og-1,r);
00270     a = (x - r + k - 1 - ug)/(k - j);
00271     scratch[ug] = a * scratch[ug];
00272   }
00273       for(og-- ; j<=g2; j++)
00274   {
00275     bspline_help(k,x,scratch,j,ug+1,og,r);
00276     a = (x - r + k - 1 - ug)/(k - j);
00277     scratch[ug] = a * scratch[ug];
00278   }
00279       for( ; j<k; j++)
00280   {
00281     ug++;
00282     bspline_help(k,x,scratch,j,ug,og,r);
00283   }
00284       result_value = scratch[k-1];
00285     }
00286   return(result_value);
00287 } /* bspline */
00288 
00289 /*              mconf.h
00290  *
00291  *  Common include file for math routines
00292  *
00293  *
00294  *
00295  * SYNOPSIS:
00296  *
00297  * #include "mconf.h"
00298  *
00299  *
00300  *
00301  * DESCRIPTION:
00302  *
00303  * This file contains definitions for error codes that are
00304  * passed to the common error handling routine mtherr()
00305  * (which see).
00306  *
00307  * The file also includes a conditional assembly definition
00308  * for the type of computer arithmetic (IEEE, DEC, Motorola
00309  * IEEE, or UNKnown).
00310  * 
00311  * For Digital Equipment PDP-11 and VAX computers, certain
00312  * IBM systems, and others that use numbers with a 56-bit
00313  * significand, the symbol DEC should be defined.  In this
00314  * mode, most floating point constants are given as arrays
00315  * of octal integers to eliminate decimal to binary conversion
00316  * errors that might be introduced by the compiler.
00317  *
00318  * For little-endian computers, such as IBM PC, that follow the
00319  * IEEE Standard for Binary Floating Point Arithmetic (ANSI/IEEE
00320  * Std 754-1985), the symbol IBMPC should be defined.  These
00321  * numbers have 53-bit significands.  In this mode, constants
00322  * are provided as arrays of hexadecimal 16 bit integers.
00323  *
00324  * Big-endian IEEE format is denoted MIEEE.  On some RISC
00325  * systems such as Sun SPARC, double precision constants
00326  * must be stored on 8-byte address boundaries.  Since integer
00327  * arrays may be aligned differently, the MIEEE configuration
00328  * may fail on such machines.
00329  *
00330  * To accommodate other types of computer arithmetic, all
00331  * constants are also provided in a normal decimal radix
00332  * which one can hope are correctly converted to a suitable
00333  * format by the available C language compiler.  To invoke
00334  * this mode, define the symbol UNK.
00335  *
00336  * An important difference among these modes is a predefined
00337  * set of machine arithmetic constants for each.  The numbers
00338  * MACHEP (the machine roundoff error), MAXNUM (largest number
00339  * represented), and several other parameters are preset by
00340  * the configuration symbol.  Check the file const.c to
00341  * ensure that these values are correct for your computer.
00342  *
00343  * Configurations NANS, INFINITIES, MINUSZERO, and DENORMAL
00344  * may fail on many systems.  Verify that they are supposed
00345  * to work on your computer.
00346  */
00347 /*
00348 Cephes Math Library Release 2.3:  June, 1995
00349 Copyright 1984, 1987, 1989, 1995 by Stephen L. Moshier
00350 */
00351 
00352 /* Define if the `long double' type works.  */
00353 #define HAVE_LONG_DOUBLE 1
00354 
00355 /* Define as the return type of signal handlers (int or void).  */
00356 #define RETSIGTYPE void
00357 
00358 /* Define if you have the ANSI C header files.  */
00359 #define STDC_HEADERS 1
00360 
00361 /* Define if your processor stores words with the most significant
00362    byte first (like Motorola and SPARC, unlike Intel and VAX).  */
00363 /* #undef WORDS_BIGENDIAN */
00364 
00365 /* Define if floating point words are bigendian.  */
00366 /* #undef FLOAT_WORDS_BIGENDIAN */
00367 
00368 /* The number of bytes in a int.  */
00369 #define SIZEOF_INT 4
00370 
00371 /* Define if you have the <string.h> header file.  */
00372 #define HAVE_STRING_H 1
00373 
00374 /* Name of package */
00375 //#define PACKAGE "cephes"
00376 
00377 /* Version number of package */
00378 //#define VERSION "2.7"
00379 
00380 /* Constant definitions for math error conditions
00381  */
00382 
00383 #define DOMAIN    1 /* argument domain error */
00384 #define SING    2 /* argument singularity */
00385 #define OVERFLOW  3 /* overflow range error */
00386 #define UNDERFLOW 4 /* underflow range error */
00387 #define TLOSS   5 /* total loss of precision */
00388 #define PLOSS   6 /* partial loss of precision */
00389 
00390 #define EDOM    33
00391 #define ERANGE    34
00392 
00393 /* Type of computer arithmetic */
00394 
00395 /* PDP-11, Pro350, VAX:
00396  */
00397 /* #define DEC 1 */
00398 
00399 /* Intel IEEE, low order words come first:
00400  */
00401 /* #define IBMPC 1 */
00402 
00403 /* Motorola IEEE, high order words come first
00404  * (Sun 680x0 workstation):
00405  */
00406 /* #define MIEEE 1 */
00407 
00408 /* UNKnown arithmetic, invokes coefficients given in
00409  * normal decimal format.  Beware of range boundary
00410  * problems (MACHEP, MAXLOG, etc. in const.c) and
00411  * roundoff problems in pow.c:
00412  * (Sun SPARCstation)
00413  */
00414 #define UNK 1
00415 
00416 /* If you define UNK, then be sure to set BIGENDIAN properly. */
00417 #ifdef FLOAT_WORDS_BIGENDIAN
00418 #define BIGENDIAN 1
00419 #else
00420 #define BIGENDIAN 0
00421 #endif
00422 /* Define this `volatile' if your compiler thinks
00423  * that floating point arithmetic obeys the associative
00424  * and distributive laws.  It will defeat some optimizations
00425  * (but probably not enough of them).
00426  *
00427  * #define VOLATILE volatile
00428  */
00429 #define VOLATILE
00430 
00431 /* For 12-byte long doubles on an i386, pad a 16-bit short 0
00432  * to the end of real constants initialized by integer arrays.
00433  *
00434  * #define XPD 0,
00435  *
00436  * Otherwise, the type is 10 bytes long and XPD should be
00437  * defined blank (e.g., Microsoft C).
00438  *
00439  * #define XPD
00440  */
00441 #define XPD 0,
00442 
00443 /* Define to support tiny denormal numbers, else undefine. */
00444 #define DENORMAL 1
00445 
00446 /* Define to ask for infinity support, else undefine. */
00447 #define INFINITIES 1
00448 
00449 /* Define to ask for support of numbers that are Not-a-Number,
00450    else undefine.  This may automatically define INFINITIES in some files. */
00451 #define NANS 1
00452 
00453 /* Define to distinguish between -0.0 and +0.0.  */
00454 #define MINUSZERO 1
00455 
00456 /* Define 1 for ANSI C atan2() function
00457    See atan.c and clog.c. */
00458 #define ANSIC 1
00459 
00460 /*              chbevl.c
00461  *
00462  *  Evaluate Chebyshev series
00463  *
00464  *
00465  *
00466  * SYNOPSIS:
00467  *
00468  * int N;
00469  * double x, y, coef[N], chebevl();
00470  *
00471  * y = chbevl( x, coef, N );
00472  *
00473  *
00474  *
00475  * DESCRIPTION:
00476  *
00477  * Evaluates the series
00478  *
00479  *        N-1
00480  *         - '
00481  *  y  =   >   coef[i] T (x/2)
00482  *         -            i
00483  *        i=0
00484  *
00485  * of Chebyshev polynomials Ti at argument x/2.
00486  *
00487  * Coefficients are stored in reverse order, i.e. the zero
00488  * order term is last in the array.  Note N is the number of
00489  * coefficients, not the order.
00490  *
00491  * If coefficients are for the interval a to b, x must
00492  * have been transformed to x -> 2(2x - b - a)/(b-a) before
00493  * entering the routine.  This maps x from (a, b) to (-1, 1),
00494  * over which the Chebyshev polynomials are defined.
00495  *
00496  * If the coefficients are for the inverted interval, in
00497  * which (a, b) is mapped to (1/b, 1/a), the transformation
00498  * required is x -> 2(2ab/x - b - a)/(b-a).  If b is infinity,
00499  * this becomes x -> 4a/x - 1.
00500  *
00501  *
00502  *
00503  * SPEED:
00504  *
00505  * Taking advantage of the recurrence properties of the
00506  * Chebyshev polynomials, the routine requires one more
00507  * addition per loop than evaluating a nested polynomial of
00508  * the same degree.
00509  *
00510  */
00511 
00512 /*              chbevl.c  */
00513 
00514 /*
00515 Cephes Math Library Release 2.0:  April, 1987
00516 Copyright 1985, 1987 by Stephen L. Moshier
00517 Direct inquiries to 30 Frost Street, Cambridge, MA 02140
00518 */
00519 
00520 double chbevl(double x, double array[], int n)
00521 {
00522   double b0, b1, b2, *p;
00523   int i;
00524   
00525   p = array;
00526   b0 = *p++;
00527   b1 = 0.0;
00528   i = n - 1;
00529   
00530   do
00531     {
00532       b2 = b1;
00533       b1 = b0;
00534       b0 = x * b1  -  b2  + *p++;
00535     }
00536   while( --i );
00537   
00538   return( 0.5*(b0-b2) );
00539 }
00540 
00541 /*              i0.c
00542  *
00543  *  Modified Bessel function of order zero
00544  *
00545  *
00546  *
00547  * SYNOPSIS:
00548  *
00549  * double x, y, i0();
00550  *
00551  * y = i0( x );
00552  *
00553  *
00554  *
00555  * DESCRIPTION:
00556  *
00557  * Returns modified Bessel function of order zero of the
00558  * argument.
00559  *
00560  * The function is defined as i0(x) = j0( ix ).
00561  *
00562  * The range is partitioned into the two intervals [0,8] and
00563  * (8, infinity).  Chebyshev polynomial expansions are employed
00564  * in each interval.
00565  *
00566  *
00567  *
00568  * ACCURACY:
00569  *
00570  *                      Relative error:
00571  * arithmetic   domain     # trials      peak         rms
00572  *    DEC       0,30         6000       8.2e-17     1.9e-17
00573  *    IEEE      0,30        30000       5.8e-16     1.4e-16
00574  *
00575  */
00576 
00577 /*
00578 Cephes Math Library Release 2.8:  June, 2000
00579 Copyright 1984, 1987, 2000 by Stephen L. Moshier
00580 */
00581 
00582 /* Chebyshev coefficients for exp(-x) I0(x)
00583  * in the interval [0,8].
00584  *
00585  * lim(x->0){ exp(-x) I0(x) } = 1.
00586  */
00587 
00588 #ifdef UNK
00589 static double A[] =
00590 {
00591 -4.41534164647933937950E-18,
00592  3.33079451882223809783E-17,
00593 -2.43127984654795469359E-16,
00594  1.71539128555513303061E-15,
00595 -1.16853328779934516808E-14,
00596  7.67618549860493561688E-14,
00597 -4.85644678311192946090E-13,
00598  2.95505266312963983461E-12,
00599 -1.72682629144155570723E-11,
00600  9.67580903537323691224E-11,
00601 -5.18979560163526290666E-10,
00602  2.65982372468238665035E-9,
00603 -1.30002500998624804212E-8,
00604  6.04699502254191894932E-8,
00605 -2.67079385394061173391E-7,
00606  1.11738753912010371815E-6,
00607 -4.41673835845875056359E-6,
00608  1.64484480707288970893E-5,
00609 -5.75419501008210370398E-5,
00610  1.88502885095841655729E-4,
00611 -5.76375574538582365885E-4,
00612  1.63947561694133579842E-3,
00613 -4.32430999505057594430E-3,
00614  1.05464603945949983183E-2,
00615 -2.37374148058994688156E-2,
00616  4.93052842396707084878E-2,
00617 -9.49010970480476444210E-2,
00618  1.71620901522208775349E-1,
00619 -3.04682672343198398683E-1,
00620  6.76795274409476084995E-1
00621 };
00622 #endif
00623 
00624 #ifdef DEC
00625 static unsigned short A[] = {
00626 0121642,0162671,0004646,0103567,
00627 0022431,0115424,0135755,0026104,
00628 0123214,0023533,0110365,0156635,
00629 0023767,0033304,0117662,0172716,
00630 0124522,0100426,0012277,0157531,
00631 0025254,0155062,0054461,0030465,
00632 0126010,0131143,0013560,0153604,
00633 0026517,0170577,0006336,0114437,
00634 0127227,0162253,0152243,0052734,
00635 0027724,0142766,0061641,0160200,
00636 0130416,0123760,0116564,0125262,
00637 0031066,0144035,0021246,0054641,
00638 0131537,0053664,0060131,0102530,
00639 0032201,0155664,0165153,0020652,
00640 0132617,0061434,0074423,0176145,
00641 0033225,0174444,0136147,0122542,
00642 0133624,0031576,0056453,0020470,
00643 0034211,0175305,0172321,0041314,
00644 0134561,0054462,0147040,0165315,
00645 0035105,0124333,0120203,0162532,
00646 0135427,0013750,0174257,0055221,
00647 0035726,0161654,0050220,0100162,
00648 0136215,0131361,0000325,0041110,
00649 0036454,0145417,0117357,0017352,
00650 0136702,0072367,0104415,0133574,
00651 0037111,0172126,0072505,0014544,
00652 0137302,0055601,0120550,0033523,
00653 0037457,0136543,0136544,0043002,
00654 0137633,0177536,0001276,0066150,
00655 0040055,0041164,0100655,0010521
00656 };
00657 #endif
00658 
00659 #ifdef IBMPC
00660 static unsigned short A[] = {
00661 0xd0ef,0x2134,0x5cb7,0xbc54,
00662 0xa589,0x977d,0x3362,0x3c83,
00663 0xbbb4,0x721e,0x84eb,0xbcb1,
00664 0x5eba,0x93f6,0xe6d8,0x3cde,
00665 0xfbeb,0xc297,0x5022,0xbd0a,
00666 0x2627,0x4b26,0x9b46,0x3d35,
00667 0x1af0,0x62ee,0x164c,0xbd61,
00668 0xd324,0xe19b,0xfe2f,0x3d89,
00669 0x6abc,0x7a94,0xfc95,0xbdb2,
00670 0x3c10,0xcc74,0x98be,0x3dda,
00671 0x9556,0x13ae,0xd4fe,0xbe01,
00672 0xcb34,0xa454,0xd903,0x3e26,
00673 0x30ab,0x8c0b,0xeaf6,0xbe4b,
00674 0x6435,0x9d4d,0x3b76,0x3e70,
00675 0x7f8d,0x8f22,0xec63,0xbe91,
00676 0xf4ac,0x978c,0xbf24,0x3eb2,
00677 0x6427,0xcba5,0x866f,0xbed2,
00678 0x2859,0xbe9a,0x3f58,0x3ef1,
00679 0x1d5a,0x59c4,0x2b26,0xbf0e,
00680 0x7cab,0x7410,0xb51b,0x3f28,
00681 0xeb52,0x1f15,0xe2fd,0xbf42,
00682 0x100e,0x8a12,0xdc75,0x3f5a,
00683 0xa849,0x201a,0xb65e,0xbf71,
00684 0xe3dd,0xf3dd,0x9961,0x3f85,
00685 0xb6f0,0xf121,0x4e9e,0xbf98,
00686 0xa32d,0xcea8,0x3e8a,0x3fa9,
00687 0x06ea,0x342d,0x4b70,0xbfb8,
00688 0x88c0,0x77ac,0xf7ac,0x3fc5,
00689 0xcd8d,0xc057,0x7feb,0xbfd3,
00690 0xa22a,0x9035,0xa84e,0x3fe5,
00691 };
00692 #endif
00693 
00694 #ifdef MIEEE
00695 static unsigned short A[] = {
00696 0xbc54,0x5cb7,0x2134,0xd0ef,
00697 0x3c83,0x3362,0x977d,0xa589,
00698 0xbcb1,0x84eb,0x721e,0xbbb4,
00699 0x3cde,0xe6d8,0x93f6,0x5eba,
00700 0xbd0a,0x5022,0xc297,0xfbeb,
00701 0x3d35,0x9b46,0x4b26,0x2627,
00702 0xbd61,0x164c,0x62ee,0x1af0,
00703 0x3d89,0xfe2f,0xe19b,0xd324,
00704 0xbdb2,0xfc95,0x7a94,0x6abc,
00705 0x3dda,0x98be,0xcc74,0x3c10,
00706 0xbe01,0xd4fe,0x13ae,0x9556,
00707 0x3e26,0xd903,0xa454,0xcb34,
00708 0xbe4b,0xeaf6,0x8c0b,0x30ab,
00709 0x3e70,0x3b76,0x9d4d,0x6435,
00710 0xbe91,0xec63,0x8f22,0x7f8d,
00711 0x3eb2,0xbf24,0x978c,0xf4ac,
00712 0xbed2,0x866f,0xcba5,0x6427,
00713 0x3ef1,0x3f58,0xbe9a,0x2859,
00714 0xbf0e,0x2b26,0x59c4,0x1d5a,
00715 0x3f28,0xb51b,0x7410,0x7cab,
00716 0xbf42,0xe2fd,0x1f15,0xeb52,
00717 0x3f5a,0xdc75,0x8a12,0x100e,
00718 0xbf71,0xb65e,0x201a,0xa849,
00719 0x3f85,0x9961,0xf3dd,0xe3dd,
00720 0xbf98,0x4e9e,0xf121,0xb6f0,
00721 0x3fa9,0x3e8a,0xcea8,0xa32d,
00722 0xbfb8,0x4b70,0x342d,0x06ea,
00723 0x3fc5,0xf7ac,0x77ac,0x88c0,
00724 0xbfd3,0x7feb,0xc057,0xcd8d,
00725 0x3fe5,0xa84e,0x9035,0xa22a
00726 };
00727 #endif
00728 
00729 
00730 /* Chebyshev coefficients for exp(-x) sqrt(x) I0(x)
00731  * in the inverted interval [8,infinity].
00732  *
00733  * lim(x->inf){ exp(-x) sqrt(x) I0(x) } = 1/sqrt(2pi).
00734  */
00735 
00736 #ifdef UNK
00737 static double B[] =
00738 {
00739 -7.23318048787475395456E-18,
00740 -4.83050448594418207126E-18,
00741  4.46562142029675999901E-17,
00742  3.46122286769746109310E-17,
00743 -2.82762398051658348494E-16,
00744 -3.42548561967721913462E-16,
00745  1.77256013305652638360E-15,
00746  3.81168066935262242075E-15,
00747 -9.55484669882830764870E-15,
00748 -4.15056934728722208663E-14,
00749  1.54008621752140982691E-14,
00750  3.85277838274214270114E-13,
00751  7.18012445138366623367E-13,
00752 -1.79417853150680611778E-12,
00753 -1.32158118404477131188E-11,
00754 -3.14991652796324136454E-11,
00755  1.18891471078464383424E-11,
00756  4.94060238822496958910E-10,
00757  3.39623202570838634515E-9,
00758  2.26666899049817806459E-8,
00759  2.04891858946906374183E-7,
00760  2.89137052083475648297E-6,
00761  6.88975834691682398426E-5,
00762  3.36911647825569408990E-3,
00763  8.04490411014108831608E-1
00764 };
00765 #endif
00766 
00767 #ifdef DEC
00768 static unsigned short B[] = {
00769 0122005,0066672,0123124,0054311,
00770 0121662,0033323,0030214,0104602,
00771 0022515,0170300,0113314,0020413,
00772 0022437,0117350,0035402,0007146,
00773 0123243,0000135,0057220,0177435,
00774 0123305,0073476,0144106,0170702,
00775 0023777,0071755,0017527,0154373,
00776 0024211,0052214,0102247,0033270,
00777 0124454,0017763,0171453,0012322,
00778 0125072,0166316,0075505,0154616,
00779 0024612,0133770,0065376,0025045,
00780 0025730,0162143,0056036,0001632,
00781 0026112,0015077,0150464,0063542,
00782 0126374,0101030,0014274,0065457,
00783 0127150,0077271,0125763,0157617,
00784 0127412,0104350,0040713,0120445,
00785 0027121,0023765,0057500,0001165,
00786 0030407,0147146,0003643,0075644,
00787 0031151,0061445,0044422,0156065,
00788 0031702,0132224,0003266,0125551,
00789 0032534,0000076,0147153,0005555,
00790 0033502,0004536,0004016,0026055,
00791 0034620,0076433,0142314,0171215,
00792 0036134,0146145,0013454,0101104,
00793 0040115,0171425,0062500,0047133
00794 };
00795 #endif
00796 
00797 #ifdef IBMPC
00798 static unsigned short B[] = {
00799 0x8b19,0x54ca,0xadb7,0xbc60,
00800 0x9130,0x6611,0x46da,0xbc56,
00801 0x8421,0x12d9,0xbe18,0x3c89,
00802 0x41cd,0x0760,0xf3dd,0x3c83,
00803 0x1fe4,0xabd2,0x600b,0xbcb4,
00804 0xde38,0xd908,0xaee7,0xbcb8,
00805 0xfb1f,0xa3ea,0xee7d,0x3cdf,
00806 0xe6d7,0x9094,0x2a91,0x3cf1,
00807 0x629a,0x7e65,0x83fe,0xbd05,
00808 0xbb32,0xcf68,0x5d99,0xbd27,
00809 0xc545,0x0d5f,0x56ff,0x3d11,
00810 0xc073,0x6b83,0x1c8c,0x3d5b,
00811 0x8cec,0xfa26,0x4347,0x3d69,
00812 0x8d66,0x0317,0x9043,0xbd7f,
00813 0x7bf2,0x357e,0x0fd7,0xbdad,
00814 0x7425,0x0839,0x511d,0xbdc1,
00815 0x004f,0xabe8,0x24fe,0x3daa,
00816 0x6f75,0xc0f4,0xf9cc,0x3e00,
00817 0x5b87,0xa922,0x2c64,0x3e2d,
00818 0xd56d,0x80d6,0x5692,0x3e58,
00819 0x616e,0xd9cd,0x8007,0x3e8b,
00820 0xc586,0xc101,0x412b,0x3ec8,
00821 0x9e52,0x7899,0x0fa3,0x3f12,
00822 0x9049,0xa2e5,0x998c,0x3f6b,
00823 0x09cb,0xaca8,0xbe62,0x3fe9
00824 };
00825 #endif
00826 
00827 #ifdef MIEEE
00828 static unsigned short B[] = {
00829 0xbc60,0xadb7,0x54ca,0x8b19,
00830 0xbc56,0x46da,0x6611,0x9130,
00831 0x3c89,0xbe18,0x12d9,0x8421,
00832 0x3c83,0xf3dd,0x0760,0x41cd,
00833 0xbcb4,0x600b,0xabd2,0x1fe4,
00834 0xbcb8,0xaee7,0xd908,0xde38,
00835 0x3cdf,0xee7d,0xa3ea,0xfb1f,
00836 0x3cf1,0x2a91,0x9094,0xe6d7,
00837 0xbd05,0x83fe,0x7e65,0x629a,
00838 0xbd27,0x5d99,0xcf68,0xbb32,
00839 0x3d11,0x56ff,0x0d5f,0xc545,
00840 0x3d5b,0x1c8c,0x6b83,0xc073,
00841 0x3d69,0x4347,0xfa26,0x8cec,
00842 0xbd7f,0x9043,0x0317,0x8d66,
00843 0xbdad,0x0fd7,0x357e,0x7bf2,
00844 0xbdc1,0x511d,0x0839,0x7425,
00845 0x3daa,0x24fe,0xabe8,0x004f,
00846 0x3e00,0xf9cc,0xc0f4,0x6f75,
00847 0x3e2d,0x2c64,0xa922,0x5b87,
00848 0x3e58,0x5692,0x80d6,0xd56d,
00849 0x3e8b,0x8007,0xd9cd,0x616e,
00850 0x3ec8,0x412b,0xc101,0xc586,
00851 0x3f12,0x0fa3,0x7899,0x9e52,
00852 0x3f6b,0x998c,0xa2e5,0x9049,
00853 0x3fe9,0xbe62,0xaca8,0x09cb
00854 };
00855 #endif
00856 
00861 double nfft_i0(double x)
00862 {
00863   double y;
00864   
00865   if( x < 0 )
00866     x = -x;
00867   if( x <= 8.0 )
00868     {
00869       y = (x/2.0) - 2.0;
00870       return( exp(x) * chbevl( y, A, 30 ) );
00871     }
00872   
00873   return(  exp(x) * chbevl( 32.0/x - 2.0, B, 25 ) / sqrt(x) ); 
00874 }
00875 
00878 double nfft_dot_complex(double complex *x, int n)
00879 {
00880   int k;
00881   double dot;
00882 
00883   for(k=0,dot=0; k<n; k++)
00884     dot+=conj(x[k])*x[k];
00885 
00886   return dot;
00887 }
00888 
00891 double nfft_dot_double(double *x, int n)
00892 {
00893   int k;
00894   double dot;
00895 
00896   for(k=0,dot=0; k<n; k++)
00897     dot+=x[k]*x[k];
00898 
00899   return dot;
00900 }
00901 
00902 
00905 double nfft_dot_w_complex(double complex *x, double *w, int n)
00906 {
00907   int k;
00908   double dot;
00909 
00910   for(k=0,dot=0.0; k<n; k++)
00911     dot+=w[k]*conj(x[k])*x[k];
00912 
00913   return dot;
00914 }
00915 
00918 double nfft_dot_w_double(double *x, double *w, int n)
00919 {
00920   int k;
00921   double dot;
00922 
00923   for(k=0,dot=0.0; k<n; k++)
00924     dot+=w[k]*x[k]*x[k];
00925 
00926   return dot;
00927 }
00928 
00929 
00933 double nfft_dot_w_w2_complex(double complex *x, double *w, double *w2, int n)
00934 {
00935   int k;
00936   double dot;
00937 
00938   for(k=0,dot=0.0; k<n; k++)
00939     dot+=w[k]*w2[k]*w2[k]*conj(x[k])*x[k];
00940 
00941   return dot;
00942 }
00943 
00947 double nfft_dot_w2_complex(double complex *x, double *w2, int n)
00948 {
00949   int k;
00950   double dot;
00951 
00952   for(k=0,dot=0.0; k<n; k++)
00953     dot+=w2[k]*w2[k]*conj(x[k])*x[k];
00954 
00955   return dot;
00956 }
00957 
00960 void nfft_cp_complex(double complex *x, double complex *y, int n)
00961 {
00962   int k;
00963 
00964   for(k=0;k<n;k++)
00965     x[k]=y[k];
00966 }
00967 
00970 void nfft_cp_double(double *x, double *y, int n)
00971 {
00972   int k;
00973 
00974   for(k=0;k<n;k++)
00975     x[k]=y[k];
00976 }
00977 
00980 void nfft_cp_a_complex(double complex *x, double a, double complex *y, int n)
00981 {
00982   int k;
00983 
00984   for(k=0;k<n;k++)
00985     x[k]=a*y[k];
00986 }
00987 
00990 void nfft_cp_a_double(double *x, double a, double *y, int n)
00991 {
00992   int k;
00993 
00994   for(k=0;k<n;k++)
00995     x[k]=a*y[k];
00996 }
00997 
00998 
01001 void nfft_cp_w_complex(double complex *x, double *w, double complex *y, int n)
01002 {
01003   int k;
01004 
01005   for(k=0;k<n;k++)
01006     x[k]=w[k]*y[k];
01007 }
01008 
01011 void nfft_cp_w_double(double *x, double *w, double *y, int n)
01012 {
01013   int k;
01014 
01015   for(k=0;k<n;k++)
01016     x[k]=w[k]*y[k];
01017 }
01018 
01019 
01020 
01023 void nfft_upd_axpy_complex(double complex *x, double a, double complex *y, int n)
01024 {
01025   int k;
01026 
01027   for(k=0;k<n;k++)
01028     x[k]=a*x[k]+y[k];
01029 }
01030 
01033 void nfft_upd_axpy_double(double *x, double a, double *y, int n)
01034 {
01035   int k;
01036 
01037   for(k=0;k<n;k++)
01038     x[k]=a*x[k]+y[k];
01039 }
01040 
01041 
01044 void nfft_upd_xpay_complex(double complex *x, double a, double complex *y, int n)
01045 {
01046   int k;
01047 
01048   for(k=0;k<n;k++)
01049     x[k]+=a*y[k];
01050 }
01051 
01054 void nfft_upd_xpay_double(double *x, double a, double *y, int n)
01055 {
01056   int k;
01057 
01058   for(k=0;k<n;k++)
01059     x[k]+=a*y[k];
01060 }
01061 
01062 
01063 
01066 void nfft_upd_axpby_complex(double complex *x, double a, double complex *y, double b, int n)
01067 {
01068   int k;
01069 
01070   for(k=0;k<n;k++)
01071     x[k]=a*x[k]+b*y[k];
01072 }
01073 
01076 void nfft_upd_axpby_double(double *x, double a, double *y, double b, int n)
01077 {
01078   int k;
01079 
01080   for(k=0;k<n;k++)
01081     x[k]=a*x[k]+b*y[k];
01082 }
01083 
01084 
01087 void nfft_upd_xpawy_complex(double complex *x, double a, double *w, double complex *y, int n)
01088 {
01089   int k;
01090 
01091   for(k=0;k<n;k++)
01092     x[k]+=a*w[k]*y[k];
01093 }
01094 
01097 void nfft_upd_xpawy_double(double *x, double a, double *w, double *y, int n)
01098 {
01099   int k;
01100 
01101   for(k=0;k<n;k++)
01102     x[k]+=a*w[k]*y[k];
01103 }
01104 
01105 
01106 
01109 void nfft_upd_axpwy_complex(double complex *x, double a, double *w, double complex *y, int n)
01110 {
01111   int k;
01112 
01113   for(k=0;k<n;k++)
01114     x[k]=a*x[k]+w[k]*y[k];
01115 }
01116 
01119 void nfft_upd_axpwy_double(double *x, double a, double *w, double *y, int n)
01120 {
01121   int k;
01122 
01123   for(k=0;k<n;k++)
01124     x[k]=a*x[k]+w[k]*y[k];
01125 }
01126 
01127 
01128 void nfft_fftshift_complex(double complex *x, int d, int* N)
01129 {
01130   int d_pre, d_act, d_post;
01131   int N_pre, N_act, N_post;
01132   int k_pre, k_act, k_post;
01133   int k,k_swap;
01134 
01135   double complex x_swap;
01136 
01137   for(d_act=0;d_act<d;d_act++)
01138     {
01139       for(d_pre=0, N_pre=1;d_pre<d_act;d_pre++)
01140   N_pre*=N[d_pre];
01141       
01142       N_act=N[d_act];
01143 
01144       for(d_post=d_act+1, N_post=1;d_post<d;d_post++)
01145   N_post*=N[d_post];
01146 
01147       for(k_pre=0;k_pre<N_pre;k_pre++)
01148   for(k_act=0;k_act<N_act/2;k_act++)
01149     for(k_post=0;k_post<N_post;k_post++)
01150       {
01151         k=(k_pre*N_act+k_act)*N_post+k_post;
01152         k_swap=(k_pre*N_act+k_act+N_act/2)*N_post+k_post;
01153 
01154         x_swap=x[k];
01155         x[k]=x[k_swap];
01156         x[k_swap]=x_swap;
01157       }
01158     }
01159 }
01160 
01161 double l_1_complex(double complex *x, double complex *y, int n)
01162 {
01163   int k;
01164   double l1;
01165   
01166   if(y==NULL)
01167     for(k=0,l1=0; k<n; k++)
01168       l1+=cabs(x[k]);
01169   else
01170     for(k=0,l1=0; k<n; k++)
01171       l1+=cabs(x[k]-y[k]);
01172 
01173   return l1;
01174 }
01175 
01176 double l_1_double(double *x, double *y, int n)
01177 {
01178   int k;
01179   double l1;
01180 
01181   if(y==NULL)
01182     for(k=0,l1=0; k<n; k++)
01183       l1+=fabs(x[k]);
01184   else
01185     for(k=0,l1=0; k<n; k++)
01186       l1+=fabs(x[k]-y[k]);
01187 
01188   return l1;
01189 }
01190 
01191 
01192 
01193 
01194 double l_2_complex(double complex *x, double complex *y, int n)
01195 {
01196   int k;
01197   double l22;  
01198 
01199   if(y==NULL)
01200     for(k=0,l22=0; k<n; k++)
01201       l22+=conj(x[k])*x[k];
01202   else
01203     for(k=0,l22=0; k<n; k++)
01204       l22+=conj(x[k]-y[k])*(x[k]-y[k]);
01205   
01206   return sqrt(l22);
01207 }
01208 
01209 double l_2_double(double *x, double *y, int n)
01210 {
01211   int k;
01212   double l22;
01213 
01214   if(y==NULL)
01215     for(k=0,l22=0; k<n; k++)
01216       l22+=x[k]*x[k];
01217   else
01218     for(k=0,l22=0; k<n; k++)
01219       l22+=(x[k]-y[k])*(x[k]-y[k]);
01220 
01221   return sqrt(l22);
01222 }
01223 
01224 
01225 
01226 
01227 double l_infty_complex(double complex *x, double complex *y, int n)
01228 {
01229   int k;
01230   double linfty;
01231   
01232   if(y==NULL)
01233     for(k=0,linfty=0; k<n; k++)
01234       linfty=((linfty<cabs(x[k]))?cabs(x[k]):linfty);
01235   else
01236     for(k=0,linfty=0; k<n; k++)
01237       linfty=((linfty<cabs(x[k]-y[k]))?cabs(x[k]-y[k]):linfty);
01238 
01239   return linfty;
01240 }
01241 
01242 
01243 double l_infty_double(double *x, double *y, int n)
01244 {
01245   int k;
01246   double linfty;
01247 
01248   if(y==NULL)
01249     for(k=0,linfty=0; k<n; k++)
01250       linfty=((linfty<fabs(x[k]))?fabs(x[k]):linfty);
01251   else
01252     for(k=0,linfty=0; k<n; k++)
01253       linfty=((linfty<fabs(x[k]-y[k]))?fabs(x[k]-y[k]):linfty);
01254 
01255   return linfty;
01256 }
01257 
01258 
01259 
01260 
01261 
01264 double nfft_error_l_infty_complex(double complex *x, double complex *y, int n)
01265 {
01266   return (l_infty_complex(x, y, n)/l_infty_complex(x, NULL, n));
01267 }
01268 
01271 double nfft_error_l_infty_double(double *x, double *y, int n)
01272 {
01273   return (l_infty_double(x, y, n)/l_infty_double(x, NULL, n));
01274 }
01275 
01276 
01277 
01280 double nfft_error_l_infty_1_complex(double complex *x, double complex *y, int n,
01281              double complex *z, int m)
01282 {
01283   return (l_infty_complex(x, y, n)/l_1_complex(z, NULL, m));
01284 }
01285 
01288 double nfft_error_l_infty_1_double(double *x, double *y, int n,
01289                               double *z, int m)
01290 {
01291   return (l_infty_double(x, y, n)/l_1_double(z, NULL, m));
01292 }
01293 
01294 
01295 
01298 double nfft_error_l_2_complex(double complex *x, double complex *y, int n)
01299 {
01300   return (l_2_complex(x, y, n)/l_2_complex(x, NULL, n));
01301 }
01302 
01305 double  nfft_error_l_2_double(double *x, double *y, int n)
01306 {
01307   return (l_2_double(x, y, n)/l_2_double(x, NULL, n));
01308 }
01309 
01310 
01311 
01314 void nfft_vpr_int(int *x, int n, char *text)
01315 {
01316   int k;
01317 
01318   if(text!=NULL)
01319   {
01320       printf ("\n %s, adr=%p\n", text, (void*)x);
01321       for (k=0; k<n; k++)
01322       {
01323     if (k%8==0) 
01324         printf("%6d.\t", k);
01325     printf("%d,", x[k]);
01326     if (k%8==7) 
01327         printf("\n");
01328       }
01329       if (n%8!=0)
01330         printf("\n");
01331   }
01332   else
01333       for (k=0; k<n; k++)
01334     printf("%d,\n", x[k]);
01335   fflush(stdout);
01336 }
01337 
01340 void nfft_vpr_double(double *x, int n, char *text)
01341 {
01342   int k;
01343 
01344   if(x==NULL)
01345     {
01346       printf("null pointer\n");
01347       fflush(stdout);
01348       exit(-1);
01349     }
01350 
01351   if(text!=NULL)
01352   {
01353       printf ("\n %s, adr=%p\n", text, (void*)x);
01354       for (k=0; k<n; k++)
01355       {
01356     if (k%8==0) 
01357         printf("%6d.\t", k);
01358     printf("%+.1E,", x[k]);
01359     if (k%8==7) 
01360         printf("\n");
01361       }
01362       if (n%8!=0)
01363         printf("\n");
01364   }
01365   else
01366       for (k=0; k<n; k++)
01367     printf("%+E,\n", x[k]);
01368   fflush(stdout);
01369 }
01370 
01373 void nfft_vpr_complex(double complex *x, int n, char *text)
01374 {
01375   int k;
01376 
01377   if(text!=NULL)
01378   {
01379       printf ("\n %s, adr=%p\n", text, (void*)x);
01380       for (k=0; k<n; k++)
01381       {
01382     if (k%4==0) 
01383         printf("%6d.\t", k);
01384     printf("%+.1E%+.1Ei,", creal(x[k]), cimag(x[k]));
01385     if (k%4==3) 
01386         printf("\n");
01387       }
01388       if (n%4!=0)
01389         printf("\n");
01390   }
01391   else
01392       for (k=0; k<n; k++)
01393     printf("%+E%+Ei,\n", creal(x[k]), cimag(x[k]));
01394   fflush(stdout);
01395 }
01396 
01397 void nfft_vrand_unit_complex(double complex *x, int n)
01398 {
01399   int k;
01400 
01401   for (k=0; k<n; k++)
01402     x[k] = ((double)rand())/RAND_MAX + I*((double)rand())/RAND_MAX;
01403 }
01404 
01405 void nfft_vrand_shifted_unit_double(double *x, int n)
01406 {
01407   int k;
01408 
01409   for (k=0; k<n; k++)
01410     x[k] = ((double)rand())/RAND_MAX - 0.5;
01411 }
01412 
01415 void nfft_voronoi_weights_1d(double *w, double *x, int M)
01416 {
01417   int j;
01418   
01419   w[0]=(x[1]-x[0])/2;
01420   for(j=1;j<M-1;j++)
01421     w[j]=(x[j+1]-x[j-1])/2;
01422   w[M-1]=(x[M-1]-x[M-2])/2;
01423 }
01424 
01428 double nfft_modified_fejer(int N,int kk)
01429 {
01430   double result;
01431 
01432   result=2.0/((double)N*N)*(1-fabs(2.0*kk+1)/((double)N));
01433 
01434   return result;
01435 }
01436 
01439 double nfft_modified_jackson2(int N,int kk)
01440 {
01441   int kj;
01442   double result;
01443   double n=(N/2+1)/2;
01444   double k;
01445   
01446   for(result=0,kj=kk;kj<=kk+1;kj++)
01447     {
01448       k=fabs(kj);
01449       if(k/n<1)
01450   result+= 1 - (3.0*k + 6.0*n*pow(k,2) - 3.0*pow(k,3)) 
01451     / (2.0*n*(2.0*pow(n,2)+1.0));
01452       else
01453   result+= (2*n-k)*(pow(2*n-k,2)-1) / (2.0*n*(2.0*pow(n,2)+1.0));
01454     }
01455       
01456   return result;
01457 }
01458 
01461 double nfft_modified_jackson4(int N,int kk)
01462 {
01463   int kj;
01464   double result;
01465   double n=(N/2+3)/4;
01466   double k;
01467   double normalisation=(2416*pow(n,7)+1120*pow(n,5)+784*pow(n,3)+720*n);
01468   
01469   for(result=0,kj=kk;kj<=kk+1;kj++)
01470     {
01471       k=fabs(kj);
01472 
01473       if(k/n<1)
01474   result+= 1 - (1260*k + (1680*pow(n,5)+2240*pow(n,3)+2940*n)*pow(k,2) -
01475           1715*pow(k,3) - (560*pow(n,3)+1400*n)*pow(k,4) + 490*
01476           pow(k,5) + 140*n*pow(k,6) - 35*pow(k,7)) / normalisation;
01477       
01478       if((1<=k/n)&&(k/n<2))
01479     result+= ((2472*pow(n,7)+336*pow(n,5)+3528*pow(n,3)-1296*n) - 
01480       (392*pow(n,6)-3920*pow(n,4)+8232*pow(n,2)-756)*k -
01481       (504*pow(n,5)+10080*pow(n,3)-5292*n)*pow(k,2) - 
01482       (1960*pow(n,4)-7840*pow(n,2)+1029)*pow(k,3) +
01483       (2520*pow(n,3)-2520*n)*pow(k,4) - (1176*pow(n,2)-294)*pow(k,5)
01484       + 252*n*pow(k,6) - 21*pow(k,7)) / normalisation;
01485       
01486       if((2<=k/n)&&(k/n<3))
01487   result+= (-(1112*pow(n,7)-12880*pow(n,5)+7448*pow(n,3)-720*n) +
01488       (12152*pow(n,6)-27440*pow(n,4)+8232*pow(n,2)-252)*k -
01489       (19320*pow(n,5)-21280*pow(n,3)+2940*n)*pow(k,2) +
01490       (13720*pow(n,4)-7840*pow(n,2)+343)*pow(k,3) -
01491       (5320*pow(n,3)-1400*n)*pow(k,4) + (1176*pow(n,2)-98)*pow(k,5)
01492       - 140*n*pow(k,6) + 7*pow(k,7)) / normalisation;
01493       
01494       if((3<=k/n)&&(k/n<4))
01495   result+= ((4*n-k)*(pow(4*n-k,2)-1)*(pow(4*n-k,2)-4)*(pow(4*n-k,2)-9)) /
01496     normalisation;
01497     }
01498 
01499   return result;
01500 }
01501 
01504 double nfft_modified_sobolev(double mu,int kk)
01505 {
01506   double result;
01507   int kj,k;
01508   
01509   for(result=0,kj=kk;kj<=kk+1;kj++)
01510     {
01511       k=fabs(kj);
01512       if(k==0)
01513   result+=1;
01514       else
01515   result+=pow(k,-2*mu);
01516     }
01517 
01518   return result;
01519 }
01520 
01523 double nfft_modified_multiquadric(double mu,double c,int kk)
01524 {
01525   double result;
01526   int kj,k;
01527   
01528   for(result=0,kj=kk;kj<=kk+1;kj++)
01529     {
01530       k=fabs(kj);
01531       result+=pow(k*k+c*c,-mu);
01532     }
01533 
01534   return result;
01535 }

Generated on 1 Nov 2006 by Doxygen 1.4.4