C   26

nrerror

Guest on 27th April 2022 01:41:55 AM

  1.  
  2. #include <stdio.h>
  3. #include <stddef.h>
  4. #include <stdlib.h>
  5. #define NR_END 1
  6. #define FREE_ARG char*
  7.  
  8. void nrerror(char error_text[])
  9. /* Numerical Recipes standard error handler */
  10. {
  11.         fprintf(stderr,"Numerical Recipes run-time error...\n");
  12.         fprintf(stderr,"%s\n",error_text);
  13.         fprintf(stderr,"...now exiting to system...\n");
  14.         exit(1);
  15. }
  16.  
  17.  
  18. int *ivector(long nl, long nh)
  19. /* allocate an int vector with subscript range v[nl..nh] */
  20. {
  21.         int *v;
  22.  
  23.         v=(int *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(int)));
  24.         if (!v) nrerror("allocation failure in ivector()");
  25.         return v-nl+NR_END;
  26. }
  27.  
  28.  
  29. double *dvector(long nl, long nh)
  30. /* allocate a double vector with subscript range v[nl..nh] */
  31. {
  32.         double *v;
  33.  
  34.         v=(double *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(double)));
  35.         if (!v) nrerror("allocation failure in dvector()");
  36.         return v-nl+NR_END;
  37. }
  38.  
  39.  
  40. void free_dvector(double *v, long nl, long nh)
  41. /* free a double vector allocated with dvector() */
  42. {
  43.         free((FREE_ARG) (v+nl-NR_END));
  44. }
  45.  
  46.  
  47. void free_ivector(int *v, long nl, long nh)
  48. /* free an int vector allocated with ivector() */
  49. {
  50.         free((FREE_ARG) (v+nl-NR_END));
  51. }

Raw Paste


Login or Register to edit or fork this paste. It's free.