1 | /* ode-initval/odeiv.c |
2 | * |
3 | * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman |
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 | |
20 | /* Author: G. Jungman |
21 | */ |
22 | #include <config.h> |
23 | #include <stdlib.h> |
24 | #include <gsl/gsl_errno.h> |
25 | #include <gsl/gsl_odeiv2.h> |
26 | |
27 | gsl_odeiv2_step * |
28 | gsl_odeiv2_step_alloc (const gsl_odeiv2_step_type * T, size_t dim) |
| 7Enter function.    gsl_odeiv2_step_alloc(T, dim) |
29 | { |
30 | gsl_odeiv2_step *s = (gsl_odeiv2_step *) malloc (sizeof (gsl_odeiv2_step)); |
| 8Call a function.    malloc(sizeof(gsl_odeiv2_step)) |
31 | |
32 | if (s == 0) |
| 9Take the false branch.    s == 0 |
33 | { |
34 | GSL_ERROR_NULL ("failed to allocate space for ode struct", GSL_ENOMEM); |
35 | }; |
36 | |
37 | s->type = T; |
38 | s->dimension = dim; |
39 | |
40 | s->state = s->type->alloc (dim); |
41 | |
42 | if (s->state == 0) |
| 10Take the false branch.    s->state == 0 |
43 | { |
44 | free (s); /* exception in constructor, avoid memory leak */ |
45 | |
46 | GSL_ERROR_NULL ("failed to allocate space for ode state", GSL_ENOMEM); |
47 | }; |
48 | |
49 | return s; |
50 | } |
| 11Exit function.    gsl_odeiv2_step_alloc(T, dim) |
51 | |
52 | const char * |
53 | gsl_odeiv2_step_name (const gsl_odeiv2_step * s) |
54 | { |
55 | return s->type->name; |
56 | } |
57 | |
58 | unsigned int |
59 | gsl_odeiv2_step_order (const gsl_odeiv2_step * s) |
60 | { |
61 | return s->type->order (s->state); |
62 | } |
63 | |
64 | int |
65 | gsl_odeiv2_step_apply (gsl_odeiv2_step * s, |
66 | double t, |
67 | double h, |
68 | double y[], |
69 | double yerr[], |
70 | const double dydt_in[], |
71 | double dydt_out[], const gsl_odeiv2_system * dydt) |
72 | { |
73 | return s->type->apply (s->state, s->dimension, t, h, y, yerr, dydt_in, |
74 | dydt_out, dydt); |
75 | } |
76 | |
77 | int |
78 | gsl_odeiv2_step_reset (gsl_odeiv2_step * s) |
79 | { |
80 | return s->type->reset (s->state, s->dimension); |
81 | } |
82 | |
83 | void |
84 | gsl_odeiv2_step_free (gsl_odeiv2_step * s) |
85 | { |
86 | RETURN_IF_NULL (s); |
87 | s->type->free (s->state); |
88 | free (s); |
89 | } |
90 | |
91 | int |
92 | gsl_odeiv2_step_set_driver (gsl_odeiv2_step * s, const gsl_odeiv2_driver * d) |
93 | { |
94 | if (d != NULL) |
95 | { |
96 | s->type->set_driver (s->state, d); |
97 | } |
98 | else |
99 | { |
100 | GSL_ERROR_NULL ("driver pointer is null", GSL_EFAULT); |
101 | } |
102 | |
103 | return GSL_SUCCESS; |
104 | } |
105 | |