-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
78 lines (65 loc) · 1.96 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* mybls: maximum likelihood transit search for corot LCs
* (designed to be called from python, this file is a dummy
* wrapper for testing purposes)
*/
/*
* h-files
*/
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <string.h>
#include "mybls.h"
#define NDMAX 10000
#define NPMAX 10000
/* -- Main program -- */
int main(int argc, char *argv[])
{
char *pt1, *pt2, line[80], *filename = "example.dat";
FILE *inf = (FILE *) NULL;
long nmeas, np = NPMAX;
double time[NDMAX], flux[NDMAX], weight[NDMAX];
double period[NPMAX], statistic[NPMAX], dc[NPMAX], duration[NPMAX],
epoch[NPMAX], depth[NPMAX];
double stat = 0., per = 0., dep = 0., dcv = 0., ep = 0., dur = 0.;
long ip = 0;
/* read in example CoRoT LC */
inf = fopen(filename, "r");
nmeas = 0;
while (fgets(line, 80, inf)) {
if (nmeas >= NDMAX) {
printf("mybls/main.c: Error: too many data points.\n");
}
time[nmeas] = strtod(line, &pt1);
flux[nmeas] = (double) strtod(pt1, &pt2);
weight[nmeas] = (double) strtod(pt2, NULL);
weight[nmeas] = 1.0 / weight[nmeas] / weight[nmeas];
nmeas++;
}
fclose(inf);
/* Do search */
mybls(time, flux, weight, nmeas, 1.0, 20.0, 0.5, 1.5, 1.0,
period, statistic, dc, duration, epoch, depth, &np);
/* Find best values */
for (ip = 0; ip < np; ip++) {
if (statistic[ip] > stat) {
stat = statistic[ip];
per = period[ip];
dcv = dc[ip];
dur = duration[ip];
ep = epoch[ip];
dep = depth[ip];
}
}
printf("Best fit:\nStat Per Epoch DC Depth Dur\n");
printf("%.2f %.5f %.5f %.5f %.5f %.3f\n", stat, per, ep, dcv, dep, dur);
//print test output
//long i;
//for(i=0;i<np;i++){
// printf("%5li %8lf %10lf %9lf %9lf %9lf %8lf\n", i, *(period+i), *(statistic+i), *(dc+i), *(duration+i), *(epoch+i), *(depth+i));
// }
/* End */
return(0);
}