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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Taking derivatives of functions in Origin C
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

gpoon

USA
Posts

Posted - 07/21/2009 :  2:31:06 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. 8 and Service Release (Select Help-->About Origin): SR4
Operating System: XP

I am trying to take numerical derivatives of functions (not a dataset of points) in Origin C. I noticed that the NAG library doesn't have a function for differentiation for C (but does for Fortran). The GNU Scientific Library (GSL) does have such a function, but I cannot get it to work because, apparently, Origin C doesn't support calling external functions that return a struct type variable.

So this is what I was trying in my "ocgsl.h" file:

/* Definition of an arbitrary function with parameters */

struct gsl_function_struct
{
double (* function) (double x, void * params);
void * params;
};

typedef struct gsl_function_struct gsl_function ;

GSL_EXPORT int gsl_diff_central (const gsl_function *f,
double x,
double *result, double *abserr);

Does Origin C (or NAG) have a differentiation function (for functions) that I just don't know about? Is there any way to overcome this limitation of calling functions that return struct type variables? Many thanks!

Iris_Bai

China
Posts

Posted - 07/21/2009 :  11:39:55 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Could you give more details about not work, for example compiling error?
Origin C doesn't support external functions that return a struct type variable, but support struct type as output variable. In your code above, gsl_function is a struct and in gsl_diff_central function it is a output variable, not a return value. So should work in Origin C.

Any way, you can reference to:
http://wiki.originlab.com/~originla/internal/index.php?title=Tutorial:Fitting_with_Integral_Function_using_GSL_routine

http://ocwiki.originlab.com/index.php?title=OriginC:Calling_GNU_Scientific_Library



Iris
Go to Top of Page

gpoon

USA
Posts

Posted - 07/22/2009 :  6:04:23 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Iris!

Thanks for your reply. When I tried to compile "ocgsl.h" as follows (using the example on OriginWiki was a template):

#pragma dll(libgsl, header)
// this is OC special pragma,
// header keyword is to indicate libgsl.dll is in same location as this file

#define GSL_EXPORT // for OC, this is not needed, so make it empty

// you can directly search and copy gsl function prototypes here

struct gsl_function_struct
{
double (* function) (double x, void * params); <---
void * params;
};

typedef struct gsl_function_struct gsl_function ;

GSL_EXPORT int gsl_diff_central (const gsl_function *f,
double x,
double *result, double *abserr);

The compiler returns "Error, syntax error in function declaration" at the line marked with the arrow. What is my mistake?

Thanks,
Gregory
Go to Top of Page

Iris_Bai

China
Posts

Posted - 07/22/2009 :  11:36:09 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Gregory,

Please try the following way to define a function pointer outside strcut:

typedef double (* FUNC)(double x, void * params);

struct gsl_function_struct
{
	FUNC function;
	void * params;
};


Iris
Go to Top of Page

gpoon

USA
Posts

Posted - 07/27/2009 :  02:16:46 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It works! Thanks!
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000