The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum
 Origin Forum
 External DLL using gsl library

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
aekalavya Posted - 01/26/2012 : 02:54:24 AM
Origin Ver. and Service Release (Select Help-->About Origin): 8.6
Operating System: Win7

I am trying to create a external dll file using gsl library with the help of the example given in the sample file for Voigt function/GslVoigtExIntegQag.
Here is the sample code for Voigt function.
-----------------------------
#include <gsl/gsl_integration.h>
static double f_callback(double t, void* params)
{
double* p = (double*)params;
#define Wl p[0]
#define Wg p[1]
#define xv p[2]
#define xc p[3]
return exp(-t * t) / (log(2) * (Wl/Wg) * (Wl/Wg) + pow((sqrt(4 * log(2)) * (xv - xc)/Wg - t), 2));

#undef Wl
#undef Wg
#undef xv
#undef xc
}

#define PI (3.14159265359)
#define WORKSPACE_SIZE 1000
int FAR PASCAL GslVoigtExIntegQag(FIT_PARA_LIST)
{
//params
#define y0 p[1]
#define A p[2]
#define Wl p[3]
#define Wg p[4]
#define a p[5]
#define b p[6]
#define xc p[7]
#define xVal x[1]
#define yVal y[1]


if ( HAS_FUNC_DERIV )
{
return NONE;
}
if ( GET_FUNC_VALUE )
{
double result = 0, err = 0;
gsl_integration_workspace* pWorkspace = gsl_integration_workspace_alloc(WORKSPACE_SIZE);
gsl_function Function;

double params[4];
Function.function = f_callback;
params[0] = Wl; params[1] = Wg; params[2] = xVal; params[3] = xc;
Function.params = params; //params needed in f_callback
gsl_integration_qag(&Function, a, b, 0, 1e-1, WORKSPACE_SIZE, 0, pWorkspace, &result, &err);
gsl_integration_workspace_free(pWorkspace);


yVal = y0 + A * (2 * log(2) / pow(PI, 3.0/2.0)) * (Wl/Wg) * result;

if ( MATH_ERR )
{
RETURN_ERR;
}
return 0;
}
if ( GET_FUNC_DERIV )
{
RETURN_ERR;
}

return 0;


#undef y0
#undef A
#undef Wl
#undef Wg
#undef a
#undef b
#undef xc
#undef xVal
#undef yVal
}
----------------------------------------------


With the help of the above code, I wrote my own function as follows,


----------------------------------------------
static double f_callback21(double x, void* params)
{
double* p = (double*)params;

#define A p[0] //Decay rate
#define B p[1] //Recovery rate
#define T p[2] //Sample temperature
#define F p[3] //Energy factor in boltzman distribution
#define time p[4] //time is the variable in the fitting function.
#define I p[5] //Pump beam Intensity



double dd = x-A*I/B*exp(-(x*B-A*I)*time);

return x * (x*B-A*I) * exp(-F*pow(x,0.66)/(8.617E-5*T)) / dd;

#undef A
#undef B
#undef T
#undef F
#undef time
#undef I

}

int FAR PASCAL IntTheoryIntegral(FIT_PARA_LIST)
{
//params
#define A p[1] //Decay rate
#define B p[2] //Recovery rate
#define T p[3] //Sample temperature
#define F p[4] //Energy factor in boltzman distribution
#define I p[5] //Pump beam Intensity
#define Nm p[6]
#define M p[7]
#define xVal x[1]
#define yVal y[1]


if ( HAS_FUNC_DERIV )
{
return NONE;
}
if ( GET_FUNC_VALUE )
{
double result = 0, err = 0 ;
gsl_integration_workspace* ww = gsl_integration_workspace_alloc(WORKSPACE_SIZE);
gsl_function F21;

double params[5];
F21.function = f_callback21;

params[0] = A; params[1] = B; params[2] = T; params[3] = F; params[4]=xVal; params[5]=I;
F21.params = params; //params needed in f_callback
gsl_integration_qag(&F21, 1, Nm, 0, 1e-7, WORKSPACE_SIZE, 0, ww, &result, &err);
gsl_integration_workspace_free(ww);

yVal = M*result;

if ( MATH_ERR )
{
RETURN_ERR;
}
return 0;
}
if ( GET_FUNC_DERIV )
{
RETURN_ERR;
}

return 0;


#undef A
#undef B
#undef T
#undef F
#undef I
#undef Nm
#undef M
#undef xVal
#undef yVal
}
----------------------------------------
I created the dll file including my function and built a fitting function using DLL option FitFuncs.IntTheoryIntegral

When I tried the 'Quick check' option in the fitting function builder, a window pops up and below error appears.

run-time check failure #2 stack around the variable 'F12' was corrupted. with three options : debug, abort and Ignore.
When I choose ignore twice, it gives a value in the quick check box which looks reasonably correct.

But when I tries to simulate the curve using the above fitting function, the origin hangs up and needs to close it.

Can anybody please help me out how to go about this.

thank you very much.

SHIVA







-Shiva
2   L A T E S T    R E P L I E S    (Newest First)
aekalavya Posted - 01/27/2012 : 04:00:42 AM
Problem found.

double params[5]; should read double params[6];


-Shiva
aekalavya Posted - 01/26/2012 : 03:00:19 AM
Small correction:

The error reads
run-time check failure #2 stack around the variable 'F21' was corrupted

F21 being the gsl_function.

Thanks.

-Shiva

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000