source: trunk/projects/slim-curve/src/main/c/loci_curvefitter_SLIMCurveFitter.c @ 7781

Revision 7781, 5.3 KB checked in by paulbarber, 8 years ago (diff)

Added GPL license to all source code.

Line 
1/*
2This file is part of the SLIM-curve package for exponential curve fitting of spectral lifetime data.
3
4Copyright (c) 2010, 2011, Gray Institute University of Oxford & UW-Madison LOCI.
5
6    This program is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation, either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "loci_curvefitter_SLIMCurveFitter.h"
21#include "EcfWrapper.h"
22
23/*
24 * Class:     loci_curvefitter_SLIMCurveFitter
25 * Method:    RLD_fit
26 * Signature: (D[DII[DI[D[D[D[D[D[DD)I
27 */
28JNIEXPORT jint JNICALL Java_loci_curvefitter_SLIMCurveFitter_RLD_1fit
29  (JNIEnv *env, jobject obj, jdouble x_inc, jdoubleArray y,
30        jint fit_start, jint fit_end, jdoubleArray instr, jint n_instr,
31        jdoubleArray sig, jdoubleArray z, jdoubleArray a, jdoubleArray tau,
32        jdoubleArray fitted, jdoubleArray chi_square, jdouble chi_square_target) {
33
34    jdouble *y_array;
35    jdouble *instr_array;
36    jdouble *sig_array;
37    jdouble *fitted_array;
38    jdouble *z_ref;
39    jdouble *a_ref;
40    jdouble *tau_ref;
41    jdouble *chi_square_ref;
42    int return_value;
43
44    // convert the arrays
45    y_array = (*env)->GetDoubleArrayElements(env, y, 0);
46    instr_array = NULL;
47    if (NULL != instr) {
48        instr_array  = (*env)->GetDoubleArrayElements(env, instr, 0);
49    }
50    sig_array = NULL;
51    if (NULL != sig) {
52        sig_array    = (*env)->GetDoubleArrayElements(env, sig, 0);
53    }
54    fitted_array = (*env)->GetDoubleArrayElements(env, fitted, 0);
55
56    // also handle double by reference as arrays
57    z_ref = (*env)->GetDoubleArrayElements(env, z, 0);
58    a_ref = (*env)->GetDoubleArrayElements(env, a, 0);
59    tau_ref = (*env)->GetDoubleArrayElements(env, tau, 0);
60    chi_square_ref = (*env)->GetDoubleArrayElements(env, chi_square, 0);
61
62    return_value = RLD_fit(x_inc, y_array, fit_start, fit_end,
63            instr_array, n_instr, sig_array, z_ref, a_ref, tau_ref,
64            fitted_array, chi_square_ref, chi_square_target);
65
66    // pass back the arrays
67    (*env)->ReleaseDoubleArrayElements(env, y, y_array, 0);
68    if (NULL != instr) {
69        (*env)->ReleaseDoubleArrayElements(env, instr, instr_array, 0);
70    }
71    if (NULL != sig) {
72        (*env)->ReleaseDoubleArrayElements(env, sig, sig_array, 0);
73    }
74    (*env)->ReleaseDoubleArrayElements(env, fitted, fitted_array, 0);
75
76    // pass back the double by reference values
77    (*env)->ReleaseDoubleArrayElements(env, z, z_ref, 0);
78    (*env)->ReleaseDoubleArrayElements(env, a, a_ref, 0);
79    (*env)->ReleaseDoubleArrayElements(env, tau, tau_ref, 0);
80    (*env)->ReleaseDoubleArrayElements(env, chi_square, chi_square_ref, 0);
81
82    return return_value;
83}
84
85/*
86 * Class:     loci_curvefitter_SLIMCurveFitter
87 * Method:    LMA_fit
88 * Signature: (D[DII[DI[D[D[II[D[DD)I
89 */
90JNIEXPORT jint JNICALL Java_loci_curvefitter_SLIMCurveFitter_LMA_1fit
91  (JNIEnv *env, jobject obj, jdouble x_inc, jdoubleArray y,
92        jint fit_start, jint fit_end, jdoubleArray instr, jint n_instr,
93        jdoubleArray sig, jdoubleArray param, jintArray param_free, jint n_param,
94        jdoubleArray fitted, jdoubleArray chi_square, jdouble chi_square_target) {
95
96    jdouble *y_array;
97    jdouble *instr_array;
98    jdouble *sig_array;
99    jdouble *param_array;
100    jint *param_free_array;
101    jdouble *fitted_array;
102    jdouble *chi_square_ref;
103    int return_value;
104
105    // convert the arrays
106    y_array = (*env)->GetDoubleArrayElements(env, y, 0);
107    instr_array = NULL;
108    if (NULL != instr) {
109        instr_array  = (*env)->GetDoubleArrayElements(env, instr, 0);
110    }
111    sig_array = NULL;
112    if (NULL != sig) {
113        sig_array    = (*env)->GetDoubleArrayElements(env, sig, 0);
114    }
115    param_array = (*env)->GetDoubleArrayElements(env, param, 0);
116    param_free_array = (*env)->GetIntArrayElements(env, param_free, 0);
117    fitted_array = (*env)->GetDoubleArrayElements(env, fitted, 0);
118
119    // also handle double by reference as array
120    chi_square_ref = (*env)->GetDoubleArrayElements(env, chi_square, 0);
121
122    return_value = LMA_fit(x_inc, y_array, fit_start, fit_end,
123            instr_array, n_instr, sig_array, param_array, param_free_array, n_param,
124            fitted_array, chi_square_ref, chi_square_target);
125
126    // pass back the arrays
127    (*env)->ReleaseDoubleArrayElements(env, y, y_array, 0);
128    if (NULL != instr) {
129        (*env)->ReleaseDoubleArrayElements(env, instr, instr_array, 0);
130    }
131    if (NULL != sig) {
132        (*env)->ReleaseDoubleArrayElements(env, sig, sig_array, 0);
133    }
134    (*env)->ReleaseDoubleArrayElements(env, param, param_array, 0);
135    (*env)->ReleaseIntArrayElements(env, param_free, param_free_array, 0);
136    (*env)->ReleaseDoubleArrayElements(env, fitted, fitted_array, 0);
137
138    // pass back the double by reference value
139    (*env)->ReleaseDoubleArrayElements(env, chi_square, chi_square_ref, 0);
140
141    return return_value;
142  }
Note: See TracBrowser for help on using the repository browser.