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 for Programming
 Forum for Origin C
 gsl and origin C

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
michaelbecker Posted - 05/21/2008 : 09:18:46 AM
Origin Version : 8
Operating System: Windows XP

Hello,

is there a way to use the gsl (Gnu Scientific Library) in Origin C? Can I use the gsl to implent user defined fit functions?

Thank you very much for your help
Michael Becker
7   L A T E S T    R E P L I E S    (Newest First)
Sophy Posted - 06/03/2009 : 06:02:44 AM
Hi, Oliver:

I am regretful to tell you that currently Origin C doesn't support calling external functions that return a struct type variable :(, but you can call functions that don't return a struct, say double gsl_acosh (const double x);

If you want to perform mathematical operations on complex data, why not use Origin complex class, like:

void test_complex()
{
complex cInput = 1 + 2i;
complex cInput2 = 2 - 4i;
complex cSin = sin(cInput);
out_complex("complex sin result : ", cSin);

complex ccos = cos(cInput);
out_complex("complex cos result : ", ccos);

complex cAdded = cInput + cInput2;
out_complex("complex + result : ", cAdded);
}

for more operations on complex data, please refer to http://ocwiki.originlab.com/index.php?title=Category:Complex_%28Math_Functions%29_%28global_function%29 and http://ocwiki.originlab.com/index.php?title=Category:complex_(class)
obauer Posted - 06/02/2009 : 11:06:45 AM
Hi Sophy!

Thank you so much for your remarks and suggestions! Unfortunately I am not so much of an expert in ORIGIN C ... Could you explain to me what the type definiton which you quoted exactly means and what it does? Could you give an example of how you think to put in the real and imaginary part of a complex number according to your suggestion? I really appreciate your efforts!

best regards,
Oliver
Sophy Posted - 06/02/2009 : 05:46:04 AM
Hi, Oliver:

I notice that there is code like
typedef struct
{
double dat[2];
}gsl_complex;
then you can use "gsl_complex mydata;" to declare variables of this type. However, there need some conversion between Origin complex type and gsl_complex, maybe you have to put the real part and imaginary part of and Origin complex type data into mydata.dat[0] and mydata.dat[1] correspondingly. After get the result of gsl_complex_add, perform a contrary procedure as to get a Origin complex result.


obauer Posted - 05/08/2009 : 08:33:00 AM
Origin Version: OriginPro 8 SR4
Operating System: Windows XP

Hello!

I am also wiling to use gsl in Origin C, in particular the content of the header files gsl_complex.h and gsl_complex_math.h . In order to do so, I followed the instructions from the example which is linked above (OriginC:Calling GNU Scientific Library (GSL)): I created a header file named ocgsl.h by copy/past from the example as well as from the above mentioned gsl_*.h files. Additionally I pasted the content of gsl_types.h into the ocgsl.h because gsl_complex_math.h initially wanted to include it,too. Now my ocgsl.h file looks like this:



#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

GSL_EXPORT double gsl_sf_zeta_int (const int n);

GSL_EXPORT int gsl_fit_linear (const double * x, const size_t xstride,
const double * y, const size_t ystride,
const size_t n,
double * c0, double * c1,
double * cov00, double * cov01, double * cov11,
double * sumsq);


//******************* taken from gsl_complex.h *****************************

#ifndef __GSL_COMPLEX_H__
#define __GSL_COMPLEX_H__

#undef __BEGIN_DECLS
#undef __END_DECLS
#ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
#else
# define __BEGIN_DECLS /* empty */
# define __END_DECLS /* empty */
#endif

__BEGIN_DECLS


/* two consecutive built-in types as a complex number */
typedef double * gsl_complex_packed ;
typedef float * gsl_complex_packed_float ;
//typedef long double * gsl_complex_packed_long_double ;

typedef const double * gsl_const_complex_packed ;
typedef const float * gsl_const_complex_packed_float ;
//typedef const long double * gsl_const_complex_packed_long_double ;


/* 2N consecutive built-in types as N complex numbers */
typedef double * gsl_complex_packed_array ;
typedef float * gsl_complex_packed_array_float ;
//typedef long double * gsl_complex_packed_array_long_double ;

typedef const double * gsl_const_complex_packed_array ;
typedef const float * gsl_const_complex_packed_array_float ;
//typedef const long double * gsl_const_complex_packed_array_long_double ;


/* Yes... this seems weird. Trust us. The point is just that
sometimes you want to make it obvious that something is
an output value. The fact that it lacks a 'const' may not
be enough of a clue for people in some contexts.
*/
typedef double * gsl_complex_packed_ptr ;
typedef float * gsl_complex_packed_float_ptr ;
//typedef long double * gsl_complex_packed_long_double_ptr ;

typedef const double * gsl_const_complex_packed_ptr ;
typedef const float * gsl_const_complex_packed_float_ptr ;
//typedef const long double * gsl_const_complex_packed_long_double_ptr ;


//typedef struct
//{
//long double dat[2];
//}
//gsl_complex_long_double;

typedef struct
{
double dat[2];
}
gsl_complex;

typedef struct
{
float dat[2];
}
gsl_complex_float;

#define GSL_REAL(z) ((z).dat[0])
#define GSL_IMAG(z) ((z).dat[1])
#define GSL_COMPLEX_P(zp) ((zp)->dat)
#define GSL_COMPLEX_P_REAL(zp) ((zp)->dat[0])
#define GSL_COMPLEX_P_IMAG(zp) ((zp)->dat[1])
#define GSL_COMPLEX_EQ(z1,z2) (((z1).dat[0] == (z2).dat[0]) && ((z1).dat[1] == (z2).dat[1]))

#define GSL_SET_COMPLEX(zp,x,y) do {(zp)->dat[0]=(x); (zp)->dat[1]=(y);} while(0)
#define GSL_SET_REAL(zp,x) do {(zp)->dat[0]=(x);} while(0)
#define GSL_SET_IMAG(zp,y) do {(zp)->dat[1]=(y);} while(0)

#define GSL_SET_COMPLEX_PACKED(zp,n,x,y) do {*((zp)+2*(n))=(x); *((zp)+(2*(n)+1))=(y);} while(0)

__END_DECLS

#endif /* __GSL_COMPLEX_H__ */



//******************* taken from gsl_complex_math.h *****************************

#ifndef __GSL_COMPLEX_MATH_H__
#define __GSL_COMPLEX_MATH_H__
//#include <gsl/gsl_complex.h>
//#include <gsl/gsl_types.h>

#undef __BEGIN_DECLS
#undef __END_DECLS
#ifdef __cplusplus
#define __BEGIN_DECLS extern "C" {
#define __END_DECLS }
#else
#define __BEGIN_DECLS /* empty */
#define __END_DECLS /* empty */
#endif

__BEGIN_DECLS

/* Complex numbers */

GSL_EXPORT gsl_complex gsl_complex_rect (double x, double y); /* r= real+i*imag */
GSL_EXPORT gsl_complex gsl_complex_polar (double r, double theta); /* r= r e^(i theta) */

#ifdef HAVE_INLINE
extern inline gsl_complex
gsl_complex_rect (double x, double y)
{ /* return z = x + i y */
gsl_complex z;
GSL_SET_COMPLEX (&z, x, y);
return z;
}
#endif

#define GSL_COMPLEX_ONE (gsl_complex_rect(1.0,0.0))
#define GSL_COMPLEX_ZERO (gsl_complex_rect(0.0,0.0))
#define GSL_COMPLEX_NEGONE (gsl_complex_rect(-1.0,0.0))

/* Properties of complex numbers */

GSL_EXPORT double gsl_complex_arg (gsl_complex z); /* return arg(z), -pi< arg(z) <=+pi */
GSL_EXPORT double gsl_complex_abs (gsl_complex z); /* return |z| */
GSL_EXPORT double gsl_complex_abs2 (gsl_complex z); /* return |z|^2 */
GSL_EXPORT double gsl_complex_logabs (gsl_complex z); /* return log|z| */

/* Complex arithmetic operators */

GSL_EXPORT gsl_complex gsl_complex_add (gsl_complex a, gsl_complex b); /* r=a+b */
GSL_EXPORT gsl_complex gsl_complex_sub (gsl_complex a, gsl_complex b); /* r=a-b */
GSL_EXPORT gsl_complex gsl_complex_mul (gsl_complex a, gsl_complex b); /* r=a*b */
GSL_EXPORT gsl_complex gsl_complex_div (gsl_complex a, gsl_complex b); /* r=a/b */

GSL_EXPORT gsl_complex gsl_complex_add_real (gsl_complex a, double x); /* r=a+x */
GSL_EXPORT gsl_complex gsl_complex_sub_real (gsl_complex a, double x); /* r=a-x */
GSL_EXPORT gsl_complex gsl_complex_mul_real (gsl_complex a, double x); /* r=a*x */
GSL_EXPORT gsl_complex gsl_complex_div_real (gsl_complex a, double x); /* r=a/x */

GSL_EXPORT gsl_complex gsl_complex_add_imag (gsl_complex a, double y); /* r=a+iy */
GSL_EXPORT gsl_complex gsl_complex_sub_imag (gsl_complex a, double y); /* r=a-iy */
GSL_EXPORT gsl_complex gsl_complex_mul_imag (gsl_complex a, double y); /* r=a*iy */
GSL_EXPORT gsl_complex gsl_complex_div_imag (gsl_complex a, double y); /* r=a/iy */

GSL_EXPORT gsl_complex gsl_complex_conjugate (gsl_complex z); /* r=conj(z) */
GSL_EXPORT gsl_complex gsl_complex_inverse (gsl_complex a); /* r=1/a */
GSL_EXPORT gsl_complex gsl_complex_negative (gsl_complex a); /* r=-a */

/* Elementary Complex Functions */

GSL_EXPORT gsl_complex gsl_complex_sqrt (gsl_complex z); /* r=sqrt(z) */
GSL_EXPORT gsl_complex gsl_complex_sqrt_real (double x); /* r=sqrt(x) (x<0 ok) */

GSL_EXPORT gsl_complex gsl_complex_pow (gsl_complex a, gsl_complex b); /* r=a^b */
GSL_EXPORT gsl_complex gsl_complex_pow_real (gsl_complex a, double b); /* r=a^b */

GSL_EXPORT gsl_complex gsl_complex_exp (gsl_complex a); /* r=exp(a) */
GSL_EXPORT gsl_complex gsl_complex_log (gsl_complex a); /* r=log(a) (base e) */
GSL_EXPORT gsl_complex gsl_complex_log10 (gsl_complex a); /* r=log10(a) (base 10) */
GSL_EXPORT gsl_complex gsl_complex_log_b (gsl_complex a, gsl_complex b); /* r=log_b(a) (base=b) */

/* Complex Trigonometric Functions */

GSL_EXPORT gsl_complex gsl_complex_sin (gsl_complex a); /* r=sin(a) */
GSL_EXPORT gsl_complex gsl_complex_cos (gsl_complex a); /* r=cos(a) */
GSL_EXPORT gsl_complex gsl_complex_sec (gsl_complex a); /* r=sec(a) */
GSL_EXPORT gsl_complex gsl_complex_csc (gsl_complex a); /* r=csc(a) */
GSL_EXPORT gsl_complex gsl_complex_tan (gsl_complex a); /* r=tan(a) */
GSL_EXPORT gsl_complex gsl_complex_cot (gsl_complex a); /* r=cot(a) */

/* Inverse Complex Trigonometric Functions */

GSL_EXPORT gsl_complex gsl_complex_arcsin (gsl_complex a); /* r=arcsin(a) */
GSL_EXPORT gsl_complex gsl_complex_arcsin_real (double a); /* r=arcsin(a) */
GSL_EXPORT gsl_complex gsl_complex_arccos (gsl_complex a); /* r=arccos(a) */
GSL_EXPORT gsl_complex gsl_complex_arccos_real (double a); /* r=arccos(a) */
GSL_EXPORT gsl_complex gsl_complex_arcsec (gsl_complex a); /* r=arcsec(a) */
GSL_EXPORT gsl_complex gsl_complex_arcsec_real (double a); /* r=arcsec(a) */
GSL_EXPORT gsl_complex gsl_complex_arccsc (gsl_complex a); /* r=arccsc(a) */
GSL_EXPORT gsl_complex gsl_complex_arccsc_real (double a); /* r=arccsc(a) */
GSL_EXPORT gsl_complex gsl_complex_arctan (gsl_complex a); /* r=arctan(a) */
GSL_EXPORT gsl_complex gsl_complex_arccot (gsl_complex a); /* r=arccot(a) */

/* Complex Hyperbolic Functions */

GSL_EXPORT gsl_complex gsl_complex_sinh (gsl_complex a); /* r=sinh(a) */
GSL_EXPORT gsl_complex gsl_complex_cosh (gsl_complex a); /* r=coshh(a) */
GSL_EXPORT gsl_complex gsl_complex_sech (gsl_complex a); /* r=sech(a) */
GSL_EXPORT gsl_complex gsl_complex_csch (gsl_complex a); /* r=csch(a) */
GSL_EXPORT gsl_complex gsl_complex_tanh (gsl_complex a); /* r=tanh(a) */
GSL_EXPORT gsl_complex gsl_complex_coth (gsl_complex a); /* r=coth(a) */

/* Inverse Complex Hyperbolic Functions */

GSL_EXPORT gsl_complex gsl_complex_arcsinh (gsl_complex a); /* r=arcsinh(a) */
GSL_EXPORT gsl_complex gsl_complex_arccosh (gsl_complex a); /* r=arccosh(a) */
GSL_EXPORT gsl_complex gsl_complex_arccosh_real (double a); /* r=arccosh(a) */
GSL_EXPORT gsl_complex gsl_complex_arcsech (gsl_complex a); /* r=arcsech(a) */
GSL_EXPORT gsl_complex gsl_complex_arccsch (gsl_complex a); /* r=arccsch(a) */
GSL_EXPORT gsl_complex gsl_complex_arctanh (gsl_complex a); /* r=arctanh(a) */
GSL_EXPORT gsl_complex gsl_complex_arctanh_real (double a); /* r=arctanh(a) */
GSL_EXPORT gsl_complex gsl_complex_arccoth (gsl_complex a); /* r=arccoth(a) */

__END_DECLS

#endif /* __GSL_COMPLEX_MATH_H__ */


//******************* taken from gsl_types.h *****************************

#ifndef __GSL_TYPES_H__
#define __GSL_TYPES_H__

#ifndef GSL_VAR

#ifdef WIN32
# ifdef GSL_DLL
# ifdef DLL_EXPORT
# define GSL_VAR extern __declspec(dllexport)
# define GSL_EXPORT __declspec(dllexport)
# else
# define GSL_VAR extern __declspec(dllimport)
# define GSL_EXPORT __declspec(dllimport)
# endif
# else
# define GSL_VAR extern
# define GSL_EXPORT
# endif
#else
# define GSL_VAR extern
# define GSL_EXPORT
#endif

#endif

#endif /* __GSL_TYPES_H__ */



Also I had to comment out all lines that contained the type definition "long double" as this definiton caused an errror message saying "Error, can not add user defined type" in the Origin Code Builder.

After that I wrote a little program to test the functions for complex number processing. It is as follows:

void test_gsl_complex()
{

complex z1 = 1+1i;
complex z2 = 2+2i;
complex z3;

z3 = gsl_complex_add (z1, z2);

out_complex("z3= ", z3);

return
}


When I try to compile this program, I get the following error message: "Error, cannot convert argument in function call" which refers to the line "z3 = gsl_complex_add (z1, z2);". My understanding is that this error is because gsl_complex_add requires an argument of the form (gsl_complex a, gsl_complex b). Yet I did not succeed in defining a complex number as gsl_complex. What is my mistake? I would be grateful for any help/comments. Thank you very much.

best regards, Oliver
cpyang Posted - 05/26/2008 : 3:18:08 PM
We created an example using Visual C++ Express, which is now a free compiler form Microsoft. Using VC Express 2005, you can try this out


http://wiki.originlab.com/~originla/wiki/index.php?title=OriginC:Calling_GNU_Scientific_Library_%28GSL%29

and


http://wiki.originlab.com/~originla/wiki/index.php?title=Originlab:Use_GSL_as_fit_function


CP




michaelbecker Posted - 05/25/2008 : 10:18:19 AM
Hi,
I'm interested in gsl_integration_qag. At the moment, I only have the compiler that comes with Origin.
Thanks
Michael Becker
cpyang Posted - 05/24/2008 : 08:03:36 AM
Origin C can call any DLL functions. We really should provide an example on this, which compiler are you using? Best if you can tell us which GSL function that you think can serve as a good example.

CP



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