gsl_integration__workspace.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* integration/workspace.c
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. #include "gsl__config.h"
  20. #include <stdlib.h>
  21. #include "gsl_integration.h"
  22. #include "gsl_errno.h"
  23. gsl_integration_workspace *
  24. gsl_integration_workspace_alloc (const size_t n)
  25. {
  26. gsl_integration_workspace * w ;
  27. if (n == 0)
  28. {
  29. GSL_ERROR_VAL ("workspace length n must be positive integer",
  30. GSL_EDOM, 0);
  31. }
  32. w = (gsl_integration_workspace *)
  33. malloc (sizeof (gsl_integration_workspace));
  34. if (w == 0)
  35. {
  36. GSL_ERROR_VAL ("failed to allocate space for workspace struct",
  37. GSL_ENOMEM, 0);
  38. }
  39. w->alist = (double *) malloc (n * sizeof (double));
  40. if (w->alist == 0)
  41. {
  42. free (w); /* exception in constructor, avoid memory leak */
  43. GSL_ERROR_VAL ("failed to allocate space for alist ranges",
  44. GSL_ENOMEM, 0);
  45. }
  46. w->blist = (double *) malloc (n * sizeof (double));
  47. if (w->blist == 0)
  48. {
  49. free (w->alist);
  50. free (w); /* exception in constructor, avoid memory leak */
  51. GSL_ERROR_VAL ("failed to allocate space for blist ranges",
  52. GSL_ENOMEM, 0);
  53. }
  54. w->rlist = (double *) malloc (n * sizeof (double));
  55. if (w->rlist == 0)
  56. {
  57. free (w->blist);
  58. free (w->alist);
  59. free (w); /* exception in constructor, avoid memory leak */
  60. GSL_ERROR_VAL ("failed to allocate space for rlist ranges",
  61. GSL_ENOMEM, 0);
  62. }
  63. w->elist = (double *) malloc (n * sizeof (double));
  64. if (w->elist == 0)
  65. {
  66. free (w->rlist);
  67. free (w->blist);
  68. free (w->alist);
  69. free (w); /* exception in constructor, avoid memory leak */
  70. GSL_ERROR_VAL ("failed to allocate space for elist ranges",
  71. GSL_ENOMEM, 0);
  72. }
  73. w->order = (size_t *) malloc (n * sizeof (size_t));
  74. if (w->order == 0)
  75. {
  76. free (w->elist);
  77. free (w->rlist);
  78. free (w->blist);
  79. free (w->alist);
  80. free (w); /* exception in constructor, avoid memory leak */
  81. GSL_ERROR_VAL ("failed to allocate space for order ranges",
  82. GSL_ENOMEM, 0);
  83. }
  84. w->level = (size_t *) malloc (n * sizeof (size_t));
  85. if (w->level == 0)
  86. {
  87. free (w->order);
  88. free (w->elist);
  89. free (w->rlist);
  90. free (w->blist);
  91. free (w->alist);
  92. free (w); /* exception in constructor, avoid memory leak */
  93. GSL_ERROR_VAL ("failed to allocate space for order ranges",
  94. GSL_ENOMEM, 0);
  95. }
  96. w->size = 0 ;
  97. w->limit = n ;
  98. w->maximum_level = 0 ;
  99. return w ;
  100. }
  101. void
  102. gsl_integration_workspace_free (gsl_integration_workspace * w)
  103. {
  104. free (w->level) ;
  105. free (w->order) ;
  106. free (w->elist) ;
  107. free (w->rlist) ;
  108. free (w->blist) ;
  109. free (w->alist) ;
  110. free (w) ;
  111. }
  112. /*
  113. size_t
  114. gsl_integration_workspace_limit (gsl_integration_workspace * w)
  115. {
  116. return w->limit ;
  117. }
  118. size_t
  119. gsl_integration_workspace_size (gsl_integration_workspace * w)
  120. {
  121. return w->size ;
  122. }
  123. */