func2d.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*-
  2. *
  3. * Original program and various modifications:
  4. * Lubos Mitas
  5. *
  6. * GRASS4.1 version of the program and GRASS4.2 modifications:
  7. * H. Mitasova,
  8. * I. Kosinovsky, D. Gerdes
  9. * D. McCauley
  10. *
  11. * Copyright 1993, 1995:
  12. * L. Mitas ,
  13. * H. Mitasova ,
  14. * I. Kosinovsky,
  15. * D.Gerdes
  16. * D. McCauley
  17. *
  18. * modified by McCauley in August 1995
  19. * modified by Mitasova in August 1995, Nov. 1996
  20. *
  21. */
  22. #include <stdio.h>
  23. #include <math.h>
  24. #include <grass/gis.h>
  25. #include <grass/interpf.h>
  26. double IL_crst(double r, double fi)
  27. /*
  28. * Radial basis function - completely regularized spline with
  29. * tension (d=2)
  30. */
  31. {
  32. double rfsta2 = fi * fi * r / 4.;
  33. static double c[4] = { 8.5733287401, 18.0590169730, 8.6347608925,
  34. 0.2677737343
  35. };
  36. static double b[4] = { 9.5733223454, 25.6329561486, 21.0996530827,
  37. 3.9584969228
  38. };
  39. double ce = 0.57721566;
  40. static double u[10] = { 1.e+00, -.25e+00,
  41. .055555555555556e+00, -.010416666666667e+00, /*fixed bug 415.. repl. by 416.. */
  42. .166666666666667e-02, -2.31481481481482e-04,
  43. 2.83446712018141e-05, -3.10019841269841e-06,
  44. 3.06192435822065e-07, -2.75573192239859e-08
  45. };
  46. double x = rfsta2;
  47. double res;
  48. double e1, ea, eb;
  49. if (x < 1.e+00) {
  50. res = x * (u[0] + x * (u[1] + x * (u[2] + x * (u[3] + x * (u[4] + x *
  51. (u[5] +
  52. x *
  53. (u[6] +
  54. x *
  55. (u[7] +
  56. x *
  57. (u[8] +
  58. x *
  59. u
  60. [9])))))))));
  61. return (res);
  62. }
  63. if (x > 25.e+00)
  64. e1 = 0.00;
  65. else {
  66. ea = c[3] + x * (c[2] + x * (c[1] + x * (c[0] + x)));
  67. eb = b[3] + x * (b[2] + x * (b[1] + x * (b[0] + x)));
  68. e1 = (ea / eb) / (x * exp(x));
  69. }
  70. res = e1 + ce + log(x);
  71. return (res);
  72. }
  73. int IL_crstg(double r, double fi, double *gd1, /* G1(r) */
  74. double *gd2 /* G2(r) */
  75. )
  76. /*
  77. * Function for calculating derivatives (d=2)
  78. */
  79. {
  80. double r2 = r;
  81. double rfsta2 = fi * fi * r / 4.;
  82. double x, exm, oneme, hold;
  83. double fsta2 = fi * fi / 2.;
  84. x = rfsta2;
  85. if (x < 0.001) {
  86. *gd1 = 1. - x / 2. + x * x / 6. - x * x * x / 24.;
  87. *gd2 = fsta2 * (-.5 + x / 3. - x * x / 8. + x * x * x / 30.);
  88. }
  89. else {
  90. if (x < 35.e+00) {
  91. exm = exp(-x);
  92. oneme = 1. - exm;
  93. *gd1 = oneme / x;
  94. hold = x * exm - oneme;
  95. *gd2 = (hold + hold) / (r2 * x);
  96. }
  97. else {
  98. *gd1 = 1. / x;
  99. *gd2 = -2. / (x * r2);
  100. }
  101. }
  102. return 1;
  103. }