forked from mattpitkin/tempo2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoFit.C
More file actions
103 lines (87 loc) · 3.3 KB
/
Copy pathdoFit.C
File metadata and controls
103 lines (87 loc) · 3.3 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
// Copyright (C) 2006,2007,2008,2009, George Hobbs, Russell Edwards
/*
* This file is part of TEMPO2.
*
* TEMPO2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* TEMPO2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with TEMPO2. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* If you use TEMPO2 then please acknowledge it by citing
* Hobbs, Edwards & Manchester (2006) MNRAS, Vol 369, Issue 2,
* pp. 655-672 (bibtex: 2006MNRAS.369..655H)
* or Edwards, Hobbs & Manchester (2006) MNRAS, VOl 372, Issue 4,
* pp. 1549-1574 (bibtex: 2006MNRAS.372.1549E) when discussing the
* timing model.
*/
#include "tempo2.h"
#include "t2fit.h"
#include <string.h>
#include <dlfcn.h>
#include <stdlib.h>
/**
* Master fitting routine with or without cholesky, global or not.
*/
void doFitAll(pulsar *psr,int npsr, const char *covarFuncFile) {
t2Fit(psr,npsr,covarFuncFile);
}
double getParamDeriv(pulsar *psr,int ipos,double x,int i,int k){
return t2Fit_getParamDeriv(psr,ipos,x,i,k);
}
void callFitFuncPlugin(pulsar *psr,int npsr, const char *covarFuncFile){
if (strcmp(psr[0].fitFunc,"default")!=0)
{
char *(*entry)(pulsar *,int,const char*);
void * module;
char str[256];
logmsg("Calling fitting plugin: %s",psr[0].fitFunc);
logmsg("%d",tempo2_plug_path_len);
for (int iplug=0; iplug < tempo2_plug_path_len; iplug++) {
snprintf(str,256,"%s/%s_fitFunc_%s_plug.t2",tempo2_plug_path[iplug],
psr[0].fitFunc,tempo2MachineType);
logmsg("Looking for '%s'",str);
module = dlopen(str, RTLD_NOW);
if (module==NULL) {
logerr("dlerror() = %s",dlerror());
} else break;
}
module = dlopen(str, RTLD_NOW);
if(!module) {
logerr("dlopen() unable to open plugin: %s.",str);
exit(1);
}
/*
* Check that the plugin is compiled against the same version of tempo2.h
*/
char ** pv = (char**)dlsym(module, "plugVersionCheck");
if(pv!=NULL){
// there is a version check for this plugin
if(strcmp(TEMPO2_h_VER,*pv)){
logerr("Plugin version mismatch");
logerr(" '%s' != '%s'",TEMPO2_h_VER,*pv);
logerr(" Please recompile plugin against same tempo2 version!");
dlclose(module);
exit(1);
}
}
entry = (char*(*)(pulsar *,int,const char*))dlsym(module, "pluginFitFunc");
if( entry == NULL ) {
dlclose(module);
logerr("dlerror() failed while retrieving address.");
exit(1);
}
entry(psr,npsr,covarFuncFile);
logmsg("FitFunc plugin Returning\n");
return;
}
}