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

Revision 7872, 5.4 KB checked in by aivar, 8 years ago (diff)

Added 'noise' and 'chi_square_delta' parameters to EcfWrapper and JNI interface.

RevLine 
[7781]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
[7691]20#include "loci_curvefitter_SLIMCurveFitter.h"
21#include "EcfWrapper.h"
22
23/*
24 * Class:     loci_curvefitter_SLIMCurveFitter
25 * Method:    RLD_fit
[7872]26 * Signature: (D[DII[DII[D[D[D[D[D[DD)I
[7691]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,
[7872]31        jint noise, jdoubleArray sig,
32        jdoubleArray z, jdoubleArray a, jdoubleArray tau,
[7691]33        jdoubleArray fitted, jdoubleArray chi_square, jdouble chi_square_target) {
34
[7693]35    jdouble *y_array;
36    jdouble *instr_array;
37    jdouble *sig_array;
38    jdouble *fitted_array;
39    jdouble *z_ref;
40    jdouble *a_ref;
41    jdouble *tau_ref;
42    jdouble *chi_square_ref;
43    int return_value;
44
[7691]45    // convert the arrays
[7693]46    y_array = (*env)->GetDoubleArrayElements(env, y, 0);
47    instr_array = NULL;
[7691]48    if (NULL != instr) {
49        instr_array  = (*env)->GetDoubleArrayElements(env, instr, 0);
50    }
[7693]51    sig_array = NULL;
[7691]52    if (NULL != sig) {
53        sig_array    = (*env)->GetDoubleArrayElements(env, sig, 0);
54    }
[7693]55    fitted_array = (*env)->GetDoubleArrayElements(env, fitted, 0);
[7691]56
57    // also handle double by reference as arrays
[7693]58    z_ref = (*env)->GetDoubleArrayElements(env, z, 0);
[7695]59    a_ref = (*env)->GetDoubleArrayElements(env, a, 0);
[7693]60    tau_ref = (*env)->GetDoubleArrayElements(env, tau, 0);
61    chi_square_ref = (*env)->GetDoubleArrayElements(env, chi_square, 0);
[7691]62
[7693]63    return_value = RLD_fit(x_inc, y_array, fit_start, fit_end,
[7872]64            instr_array, n_instr, noise, sig_array, z_ref, a_ref, tau_ref,
[7691]65            fitted_array, chi_square_ref, chi_square_target);
66
67    // pass back the arrays
68    (*env)->ReleaseDoubleArrayElements(env, y, y_array, 0);
69    if (NULL != instr) {
70        (*env)->ReleaseDoubleArrayElements(env, instr, instr_array, 0);
71    }
72    if (NULL != sig) {
73        (*env)->ReleaseDoubleArrayElements(env, sig, sig_array, 0);
74    }
75    (*env)->ReleaseDoubleArrayElements(env, fitted, fitted_array, 0);
76
77    // pass back the double by reference values
78    (*env)->ReleaseDoubleArrayElements(env, z, z_ref, 0);
79    (*env)->ReleaseDoubleArrayElements(env, a, a_ref, 0);
80    (*env)->ReleaseDoubleArrayElements(env, tau, tau_ref, 0);
81    (*env)->ReleaseDoubleArrayElements(env, chi_square, chi_square_ref, 0);
82
83    return return_value;
84}
85
86/*
87 * Class:     loci_curvefitter_SLIMCurveFitter
88 * Method:    LMA_fit
[7872]89 * Signature: (D[DII[DII[D[D[II[D[DDD)I
[7691]90 */
91JNIEXPORT jint JNICALL Java_loci_curvefitter_SLIMCurveFitter_LMA_1fit
92  (JNIEnv *env, jobject obj, jdouble x_inc, jdoubleArray y,
93        jint fit_start, jint fit_end, jdoubleArray instr, jint n_instr,
[7872]94        jint noise, jdoubleArray sig,
95        jdoubleArray param, jintArray param_free, jint n_param,
96        jdoubleArray fitted, jdoubleArray chi_square,
97        jdouble chi_square_target, jdouble chi_square_delta) {
[7691]98
[7693]99    jdouble *y_array;
100    jdouble *instr_array;
101    jdouble *sig_array;
102    jdouble *param_array;
103    jint *param_free_array;
104    jdouble *fitted_array;
105    jdouble *chi_square_ref;
106    int return_value;
107
[7691]108    // convert the arrays
[7693]109    y_array = (*env)->GetDoubleArrayElements(env, y, 0);
110    instr_array = NULL;
[7691]111    if (NULL != instr) {
112        instr_array  = (*env)->GetDoubleArrayElements(env, instr, 0);
113    }
[7693]114    sig_array = NULL;
[7691]115    if (NULL != sig) {
116        sig_array    = (*env)->GetDoubleArrayElements(env, sig, 0);
117    }
[7693]118    param_array = (*env)->GetDoubleArrayElements(env, param, 0);
119    param_free_array = (*env)->GetIntArrayElements(env, param_free, 0);
120    fitted_array = (*env)->GetDoubleArrayElements(env, fitted, 0);
[7691]121
122    // also handle double by reference as array
[7693]123    chi_square_ref = (*env)->GetDoubleArrayElements(env, chi_square, 0);
[7691]124
[7693]125    return_value = LMA_fit(x_inc, y_array, fit_start, fit_end,
[7872]126            instr_array, n_instr, noise, sig_array,
127            param_array, param_free_array, n_param,
128            fitted_array, chi_square_ref, chi_square_target, chi_square_delta);
[7691]129
130    // pass back the arrays
131    (*env)->ReleaseDoubleArrayElements(env, y, y_array, 0);
132    if (NULL != instr) {
133        (*env)->ReleaseDoubleArrayElements(env, instr, instr_array, 0);
134    }
135    if (NULL != sig) {
136        (*env)->ReleaseDoubleArrayElements(env, sig, sig_array, 0);
137    }
138    (*env)->ReleaseDoubleArrayElements(env, param, param_array, 0);
139    (*env)->ReleaseIntArrayElements(env, param_free, param_free_array, 0);
140    (*env)->ReleaseDoubleArrayElements(env, fitted, fitted_array, 0);
141
142    // pass back the double by reference value
143    (*env)->ReleaseDoubleArrayElements(env, chi_square, chi_square_ref, 0);
144
145    return return_value;
146  }
Note: See TracBrowser for help on using the repository browser.