From 0cbd8fdc8be9f8374c868a419fed95267e809f00 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 2 Sep 2008 07:39:24 -0400 Subject: [PATCH] Fixed linker error running wlc check in check_sawsim. Obviously, the wlc check should be in check_tension_model, but that doesn't exist yet. When it does, it will still need the wlc() declaration, since wlc() is not exported directly by tension_model.h. I also added protective #ifndef-#def-#endif protection to the headers. TODO: Determine which modules depend on which other modules and make the appropriate includes in the headers themselves. Then the .c files need only include the headers they use directly. --- src/sawsim.nw | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/sawsim.nw b/src/sawsim.nw index 78ce2e7..660adc0 100644 --- a/src/sawsim.nw +++ b/src/sawsim.nw @@ -227,11 +227,16 @@ typedef struct environment_struct { @ <>= +#ifndef GLOBAL_H +#define GLOBAL_H <> <> <> <> +#endif /* GLOBAL_H */ @ +Where the [[GLOBAL_H]] defines are protecting [[global.h]] from being +included multiple times. \section{Simulation functions} @@ -1402,9 +1407,12 @@ need to take care of parsing those parameters themselves. We implement this parsing in [[parse.c]], define the interface in [[parse.h]], and the the unit testing in [[check_parse.c]]. <>= +#ifndef PARSE +#define PARSE <> <> <> +#endif /* PARSE */ @ <>= @@ -1634,6 +1642,7 @@ Here we check to make sure the various functions work as expected, using \citeta <> <> <> +<> <> <> <
> @@ -1705,10 +1714,13 @@ int main(void) @ <>= +extern double wlc(double x, double T, double p, double L); START_TEST(test_wlc_at_zero) { - double T=1.0, L=1.0, p=0.1, x=0.0; - fail_unless(wlc(x, T, p, L)==0, NULL); + double T=1.0, L=1.0, p=0.1, x=0.0, lim=1e-30; + fail_unless(abs(wlc(x, T, p, L)) < lim, \ + "abs(wlc(x=%g,T=%g,p=%g,L=%g)) = %g >= %g", + x, T, p, L, abs(wlc(x, T, p, L)), lim); } END_TEST @@ -1813,8 +1825,11 @@ the implementation in [[tension_balance.c]], and the unit testing in [[check_tension_balance.c]] <>= +#ifndef TENSION_BALANCE_H +#define TENSION_BALANCE_H <> <> +#endif /* TENSION_BALANCE_H */ @ <>= @@ -2155,7 +2170,7 @@ The analytic solution for a general number of springs is given in Appendix \ref{ <>= START_TEST(test_double_hooke) { - double k1=5, k2=4, x=3, last_x=2.0, F, Fe, x1e, x2e; + double k1=5, k2=4, x=3, last_x=-1.0, F, Fe, x1e, x2e; one_dim_fn_t *handlers[] = {&hooke, &hooke}; void *data[] = {&k1, &k2}; F = tension_balance(2, handlers, data, last_x, x); @@ -2169,6 +2184,7 @@ START_TEST(test_double_hooke) } END_TEST @ +TODO: test [[tension_balance()]] with another balance after the [[x_of_xo_data]] initializing balance we ran above. <>= TCase *tc_tbfunc = tcase_create("tension balance function"); @@ -2187,9 +2203,12 @@ Since the list handling is so general, and separable from the bulk of the simula The interface is defined in [[list.h]], the implementation in [[list.c]], and the unit testing in [[check_list.c]] <>= +#ifndef LIST_H +#define LIST_H <> <> <> +#endif /* LIST_H */ @ <>= @@ -2640,10 +2659,13 @@ Because this functionality is independent of the rest of the simulation, we'll s The interface is defined in [[string_eval.h]], the implementation in [[string_eval.c]], and the unit testing in [[check_string_eval.c]]. <>= +#ifndef STRING_EVAL_H +#define STRING_EVAL_H <> <> <> <> +#endif /* STRING_EVAL_H */ @ <>= @@ -2960,8 +2982,11 @@ That's only 15 calls per solution, so the search algorithm seems reasonable. The number of evaluation calls could be drastically reduced, however, by implementing an $x(x_0)$ lookup table. <>= +#ifndef ACCEL_K_H +#define ACCEL_K_H double accel_k(k_func_t *k, double F, environment_t *env, void *params); void free_accels(); +#endif /* ACCEL_K_H */ @ <>= @@ -3056,6 +3081,8 @@ Because these models are independent of the rest of the simulation, we'll split The interface is defined in [[tension_model.h]], the implementation in [[tension_model.c]], the unit testing in [[check_k_model.c]], and some other tidbits in [[tension_model_utils.c]]. <>= +#ifndef TENSION_MODEL_H +#define TENSION_MODEL_H <> <> <> @@ -3064,6 +3091,7 @@ The interface is defined in [[tension_model.h]], the implementation in [[tension <> <> <> +#endif /* TENSION_MODEL_H */ @ <>= @@ -3794,6 +3822,8 @@ but then your [[notangle]]s would look like [[notangle -R'k model.h']], which I don't like as much. <>= +#ifndef K_MODEL_H +#define K_MODEL_H <> <> <> @@ -3801,6 +3831,7 @@ which I don't like as much. <> <> <> +#endif /* K_MODEL_H */ @ <>= -- 2.26.2