file:/local_home/local_home/hugo/neurospaces_project/heccer/source/c/snapshots/0/tests/code/main.c (Mon Jun 30 21:17:28 2008
) HOME
1: //
2: // Heccer : a compartmental solver that implements efficient Crank-Nicolson
3: // integration for neuronal models.
4: //
5:
6: //////////////////////////////////////////////////////////////////////////////
7: //'
8: //' Heccer : testbed C implementation
9: //'
10: //' Copyright (C) 2006-2008 Hugo Cornelis
11: //'
12: //' functional ideas .. Hugo Cornelis, hugo.cornelis@gmail.com
13: //'
14: //' coding ............ Hugo Cornelis, hugo.cornelis@gmail.com
15: //'
16: //////////////////////////////////////////////////////////////////////////////
17:
18:
19: #include <stdio.h>
20: #include <stdlib.h>
21:
22:
23: #include "main.h"
24:
25:
26: //v accessible from the outside if needed
27:
28: struct Heccer *pheccer = NULL;
29:
30: struct VClamp *pvc = NULL;
31:
32: struct PerfectClamp *ppc = NULL;
33:
34:
35: //o To use this file :
36: //o
37: //o set the variable 'inter' to an intermediary representation,
38: //o #define HECCER_TEST_STEPS 1
39: //o #define HECCER_TEST_TESTED_THINGS to a dump selection,
40: //o and so on for the defines below, when not set they get a
41: //o sensible default value.
42: //o #include this file, compile, run and parse the output.
43: //o
44: //o Heccer construction can also be done using the
45: //o HECCER_TEST_CONSTRUCT macro, in which case the global variable
46: //o pheccer must be preallocated.
47: //o
48: //o Tests with multiple heccers must not use this file.
49: //o
50:
51: #ifndef HECCER_TEST_NAME
52: #define HECCER_TEST_NAME ("unnamed test")
53: #endif
54:
55: #ifndef HECCER_TEST_CONSTRUCT
56: #define HECCER_TEST_CONSTRUCT \
57: memcpy(&pheccer->inter, &inter, sizeof(inter)); \
58: pheccer->iStatus = HECCER_STATUS_PHASE_2
59: #endif
60:
61: #ifndef HECCER_TEST_INITIATE
62: #define HECCER_TEST_INITIATE ((void)1)
63: #endif
64:
65: #ifndef HECCER_TEST_INTERVAL_DEFAULT_START
66: #define HECCER_TEST_INTERVAL_DEFAULT_START (-0.1)
67: #endif
68:
69: #ifndef HECCER_TEST_INTERVAL_DEFAULT_END
70: #define HECCER_TEST_INTERVAL_DEFAULT_END (0.05)
71: #endif
72:
73: #ifndef HECCER_TEST_INTERVAL_DEFAULT_ENTRIES
74: #define HECCER_TEST_INTERVAL_DEFAULT_ENTRIES 3000
75: #endif
76:
77: #ifndef HECCER_TEST_INTERPOL_INTERVAL_DEFAULT_ENTRIES
78: #define HECCER_TEST_INTERPOL_INTERVAL_DEFAULT_ENTRIES 149
79: #endif
80:
81: #ifndef HECCER_TEST_OPTIONS
82: #define HECCER_TEST_OPTIONS 0
83: #endif
84:
85: #ifndef HECCER_TEST_OUTPUT
86: #define HECCER_TEST_OUTPUT ((void)1)
87: #endif
88:
89: #ifndef HECCER_TEST_REPORTING_GRANULARITY
90: #define HECCER_TEST_REPORTING_GRANULARITY 1
91: #endif
92:
93: #ifndef HECCER_TEST_SCHEDULE
94: #define HECCER_TEST_SCHEDULE ((void)1)
95: #endif
96:
97: #ifndef HECCER_TEST_STEPS
98: #define HECCER_TEST_STEPS 10
99: #endif
100:
101: #ifndef HECCER_TEST_TESTED_THINGS
102: #define HECCER_TEST_TESTED_THINGS HECCER_DUMP_ALL
103: #endif
104:
105:
106: //! no heccer instance allowed to run with a clock smaller than this
107:
108: #ifndef HECCER_TEST_TIME_GRANULARITY
109: #define HECCER_TEST_TIME_GRANULARITY (1e-9)
110: #endif
111:
112:
113: //! default heccer time step, must be bigger than the HECCER_TEST_TIME_GRANULARITY
114:
115: #ifndef HECCER_TEST_TIME_STEP
116: #define HECCER_TEST_TIME_STEP (2e-5)
117: #endif
118:
119:
120: int WriteOutput(char *pcFilename)
121: {
122: //- set default result : ok
123:
124: int iResult = 1;
125:
126: //- copy the file content to stdout
127:
128: FILE *pfile = fopen(pcFilename, "r");
129:
130: char pc[10000];
131:
132: size_t st = fread(pc, sizeof(char), sizeof(pc), pfile);
133:
134: while (st == 10000)
135: {
136: fwrite(pc, sizeof(char), st, stdout);
137:
138: st = fread(pc, sizeof(char), sizeof(pc), pfile);
139: }
140:
141: fwrite(pc, sizeof(char), st, stdout);
142:
143: //- return result
144:
145: return(iResult);
146: }
147:
148:
149: int main(int argc, char *argv[])
150: {
151: //t use argv for heccer options
152:
153: //- set default result : ok
154:
155: int iResult = EXIT_SUCCESS;
156:
157: //- instantiate a heccer with an initialized intermediary
158:
159: //! note: test definition is allowed to allocate the heccer, with services.
160:
161: if (!pheccer)
162: {
163: pheccer = HeccerNewP2(HECCER_TEST_NAME, &inter);
164: }
165: else
166: {
167: HECCER_TEST_CONSTRUCT;
168: }
169:
170: //t need sensible API to set options I guess.
171:
172: pheccer->dStep = HECCER_TEST_TIME_STEP;
173:
174: pheccer->ho.dIntervalStart = HECCER_TEST_INTERVAL_DEFAULT_START;
175:
176: pheccer->ho.dIntervalEnd = HECCER_TEST_INTERVAL_DEFAULT_END;
177:
178: //t should set test defaults for basal activator tables.
179:
180: /* pheccer->ho.dBasalActivatorStart = HECCER_TEST_INTERVAL_DEFAULT_START; */
181:
182: /* pheccer->ho.dBasalActivatorEnd = HECCER_TEST_INTERVAL_DEFAULT_END; */
183:
184: pheccer->ho.iIntervalEntries = HECCER_TEST_INTERVAL_DEFAULT_ENTRIES;
185:
186: pheccer->ho.iSmallTableSize = HECCER_TEST_INTERPOL_INTERVAL_DEFAULT_ENTRIES;
187:
188: pheccer->ho.iOptions = HECCER_TEST_OPTIONS;
189:
190: //- build indices for optimization
191:
192: HeccerCompileP2(pheccer);
193:
194: //- compile to byte code
195:
196: HeccerCompileP3(pheccer);
197:
198: //- initiate values
199:
200: HeccerInitiate(pheccer);
201:
202: //- initialize test specific things
203:
204: HECCER_TEST_INITIATE;
205:
206: //- initial dump
207:
208: //! funny : the first '---' in the output are taken as an option
209: //! by Expect.pm, which complicates testing a bit. So just
210: //! removed.
211:
212: /* fprintf(stdout, "-------\n"); */
213:
214: HECCER_TEST_TESTED_THINGS && fprintf(stdout, "Initiated\n");
215:
216: HECCER_TEST_TESTED_THINGS && HeccerDump(pheccer, stdout, HECCER_TEST_TESTED_THINGS);
217:
218: //v final report needed ?
219:
220: int iFinalReport = 0;
221:
222: //- a couple of times
223:
224: int i;
225:
226: for (i = 0; i < HECCER_TEST_STEPS ; i++)
227: {
228: //- update the current simulation time.
229:
230: double dSimulationTime = i * HECCER_TEST_TIME_STEP + HECCER_TEST_TIME_GRANULARITY;
231:
232: //- step
233:
234: HeccerHeccs(pheccer, dSimulationTime);
235:
236: //- schedule other objects
237:
238: HECCER_TEST_SCHEDULE;
239:
240: //- generate user specified output
241:
242: HECCER_TEST_OUTPUT;
243:
244: //- dump
245:
246: if (i % HECCER_TEST_REPORTING_GRANULARITY == 0)
247: {
248: HECCER_TEST_TESTED_THINGS && fprintf(stdout, "-------\n");
249:
250: HECCER_TEST_TESTED_THINGS && fprintf(stdout, "Iteration %i\n", i);
251:
252: HECCER_TEST_TESTED_THINGS && HeccerDump(pheccer, stdout, HECCER_TEST_TESTED_THINGS);
253: }
254: else
255: {
256: iFinalReport = 1;
257: }
258: }
259:
260: //- add a final report if necessary
261:
262: if (iFinalReport)
263: {
264: HECCER_TEST_TESTED_THINGS && fprintf(stdout, "-------\n");
265:
266: HECCER_TEST_TESTED_THINGS && fprintf(stdout, "Final Iteration\n", i);
267:
268: HECCER_TEST_TESTED_THINGS && HeccerDump(pheccer, stdout, HECCER_TEST_TESTED_THINGS);
269: }
270:
271: //- return result
272:
273: return(iResult);
274: }
275:
276:
277:
Generated by Xrefactory version 2.0.14 on Thu Jul 24 22:41:20 2008