source: sasview/sansmodels/src/igor_wrapper/templates/weighted_template.c @ fd25fb0

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since fd25fb0 was ae3ce4e, checked in by Mathieu Doucet <doucetm@…>, 17 years ago

Moving sansmodels to trunk

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/**
2 * Evaluate [PYTHONCLASS] with angular distribution given
3 * by user.
4 *
5 * This code was written as part of the DANSE project
6 *  http://danse.us/trac/sans/
7 *
8 * WARNING: THIS FILE WAS GENERATED BY IGORGENERATOR.PY
9 *          DO NOT MODIFY THIS FILE, MODIFY [INCLUDE_FILE]
10 *          AND RE-RUN THE GENERATOR SCRIPT
11 *   
12 *  @copyright 2007: University of Tennessee, for the DANSE project
13 *
14 */
15
16#include "c_disperser.h"
17#include "danse.h"
18#include <math.h>
19
20/**
21 * Evaluate model for given angular distributions in theta and phi.
22 *
23 * Angles are in radian.
24 *
25 * See [C_FILE_NAME] for more information about the model parameters.
26 *
27 * @param dp: model parameters
28 * @param phi_values: vector of phi_values
29 * @param phi_weights: vector of weights for each entry in phi_values
30 * @param n_phi: length of phi_values and phi_weights vectors
31 * @param theta_values: vector of theta values
32 * @param theta_weights: vector of weights for each entry in theta_values
33 * @param n_theta: length of theta_Values and theta_weights vectors
34 * @param q: q-value to evaluate the model at
35 * @param phi_q: angle between the q-vector and the q_x axis
36 * @return: scattering intensity
37 *
38[PARS_LIST]
39 *
40 */
41double [MODEL_NAME]_Weights(double dp[], double *phi_values, double *phi_weights, int n_phi, 
42                                                                double *theta_values, double *theta_weights, int n_theta, 
43                                                                double q, double phi_q) {
44        // Copy of parameters
45        double pars[[NPARS]];
46        // Parameter index for theta
47        int theta_index = [THETA_INDEX];
48        // Parameter index for phi
49        int phi_index   = [PHI_INDEX];
50        int i, i_theta;
51        double sum, norm;
52       
53        // Copy parameters because they will be modified
54        for(i=0; i<[NPARS]; i++) {
55                pars[i] = dp[i];
56        }
57
58        if (n_theta == 0) {
59                return weight_dispersion( &disperse_[MODEL_NAME]_analytical_2D,
60                                phi_values, phi_weights, n_phi, phi_index, pars, q, phi_q );
61        } else {
62                sum = 0.0;
63                norm = 0.0;
64               
65                for(i_theta=0; i_theta<n_theta; i_theta++) {
66                        // Assign new theta value
67                        pars[theta_index] = theta_values[i_theta];
68                        // Evaluate the function, weight by sin(theta)
69                        sum += sin(theta_values[i_theta]) * theta_weights[i_theta] * 
70                                        weight_dispersion( &disperse_[MODEL_NAME]_analytical_2D,
71                                        phi_values, phi_weights, n_phi, phi_index, pars, q, phi_q );
72                        // Keep track of normalization
73                        norm += theta_weights[i_theta];
74                }
75               
76                // Protect against null weight vector
77                if(norm > 0) {
78                        return sum/norm;
79                }
80        }
81        return 0.0;
82}
83
84
Note: See TracBrowser for help on using the repository browser.