/src/scopmath/ramp.c

https://bitbucket.org/yarikoptic/nrn · C · 77 lines · 29 code · 5 blank · 43 comment · 11 complexity · 248dd91be2f7f66246bdd6f996d7c73d MD5 · raw file

  1. #include <../../nrnconf.h>
  2. /******************************************************************************
  3. *
  4. * File: ramp.c
  5. *
  6. * Copyright (c) 1984-1991
  7. * Duke University
  8. *
  9. ******************************************************************************/
  10. #ifndef LINT
  11. static char RCSid[] =
  12. "ramp.c,v 1.1.1.1 1994/10/12 17:22:23 hines Exp" ;
  13. #endif
  14. /*-----------------------------------------------------------------------------
  15. *
  16. * RAMP()
  17. *
  18. * Computes the value of a ramp function of specified height
  19. * and duration
  20. *
  21. * Calling sequence:
  22. * ramp(t, lag, height, duration)
  23. *
  24. * Arguments:
  25. * Input: t, double the independent variable,
  26. * usually time
  27. *
  28. * lag, double value of t at which ramp begins
  29. *
  30. * height, double ramp height
  31. *
  32. * duration,double duration of the ramp incline
  33. *
  34. * Output: reset_integ, *int set to 1 if discontinuity is
  35. * generated
  36. * old_value, *double saved value from previous
  37. * call
  38. *
  39. * Returns:
  40. * Double precision value of the ramp function
  41. *
  42. * Functions called:
  43. * none
  44. *
  45. * Files accessed:
  46. * none
  47. *
  48. */
  49. double
  50. ramp(reset_integ, old_value, t, lag, height, duration)
  51. double *old_value, t, lag, height, duration;
  52. int *reset_integ;
  53. {
  54. if (t < lag)
  55. {
  56. if (*old_value != 0.) *reset_integ = 1;
  57. *old_value = 0.;
  58. return (0.0);
  59. }
  60. else if (t > lag + duration)
  61. {
  62. if (*old_value != height) *reset_integ = 1;
  63. *old_value = height;
  64. return (height);
  65. }
  66. else
  67. {
  68. if (*old_value == 0. || *old_value == height) *reset_integ = 1;
  69. *old_value = (t - lag) * height / duration;
  70. return (*old_value);
  71. }
  72. }