-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.c
45 lines (34 loc) · 1.12 KB
/
debug.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "astrotest.h"
FILE* dbg;
// Debug function, replaces the standard function get_score( )
double get_score_debug( struct _hordat *hordat) {
static int count = 0;
if (!debug_level) {
return get_score(hordat);
}
if (++count > 200) {
fprintf(dbg,"Limit of 200 score evaluations reached.\n Debug-output stopped.\n");
debug_level = 0;
return get_score(hordat);
}
if (!dbg) {
dbg = fopen("prot.txt","w");
if (dbg == NULL) {
fprintf(stderr,"Couldn't open debug prot file prot.txt for writing");
exit(EXIT.FILE_ACCESS_ERROR);
}
}
double score = 0;
reset_planet_buffer( );
fprintf( dbg, "(%f %f %f)\n ", hordat->jd, hordat->lon, hordat->lat );
for (int i=0; i<scoreFunction.size;i++) {
double s = scoreFunction.terms[i].f( hordat, & scoreFunction.terms[i].args );
fprintf(dbg, "%10.2lf + %.2lf => %10.2lf\n", score, s, score + s );
score += s;
}
fprintf( dbg, " sum = %f\n\n", score );
return (double) score;
}