### Aptech Systems, Inc. Worldwide Headquarters

Address:

Aptech Systems, Inc.

2350 East Germann Road, Suite #21

Chandler, AZ 85286Phone: 360.886.7100

FAX: 360.886.8922**Ready to Get Started?**### Request Quote & Product Information

### Industry Solutions

### Products

### Resources

### Support

### Training & Events

Want more guidance while learning about the full functionality of GAUSS and its capabilities? Get in touch for in-person training or browse additional references below.

### Tutorials

Step-by-step, informative lessons for those who want to dive into GAUSS and achieve their goals, fast.

### Have a Specific Question?

### Q&A: Register and Login

### Support Plans

Premier Support and Platinum Premier Support are annually renewable membership programs that provide you with important benefits including technical support, product maintenance, and substantial cost-saving features for your GAUSS System or the GAUSS Engine.

### User Forums

Join our community to see why our users are considered some of the most active and helpful in the industry!

### Where to Buy

Available across the globe, you can have access to GAUSS no matter where you are.

### Recent Tags

applications character vectors CML CMLMT Constrained Optimization datasets dates dlibrary dllcall econometrics Editor error error codes errors Excel file i/o floating network GAUSS Engine GAUSS Light graphics GUI hotkeys installation license licensing linux loading data loop loops matrix manipulation Maximum Likelihood Maxlik MaxLikMT Memory multidimensional array optimization Optmum output panel data PQG graphics procs random numbers strings structures threading### Recent Questions

- Can i get MaxLik Packge for Mac OS
- How to run Narayan and Popp (2010) unit root test with two structural break
- ThreadFor again
- cml.lcg zip file
- nelder-mead optimization algorithm
- Kernel regression - kreg
- exponential matrix
- Panel unit root test with structural breaks - calculating break dates
- Panel unit root test with structural breaks. A problem with the code
- creating subplot

### Features

### Time Series 2.0 MT

### Industry Solutions

### Find out more now

### Time Series MT 2.1

### Find out more now

### Find out more now

# Resources

# dllcall with function as input

Dear All

I wonder if it is possible to use functions rather than arrays as an input when call compiled dlls in GAUSS?

## 5 Answers

Many optimization codes have a reverse communication interface where the compiled code (FORTRAN/C/C++) will return a specific return value when it would like the objective function to be evaluated along with the values at which it would like them evaluated at.

Below is a simple example of the concept. For this example, we will assume that we have a FORTRAN function that will assign `ret` to be equal to 1, assign the values at which it would like the function evaluated to `parmout` and then return whenever it would like a function evaluation. You could then set up your GAUSS code something like this:

ret = 1; parmin = zeros(4, 1); parmout = zeros(4, 1); ans = zeros(4,1); do while (ret); dllcall fortranOptRoutine(parmin, parmout, ans, ret); if (ret == 1); parmin = myFunc(parmout); endif; endo; proc (1) = myFunc(x); retp(x*x); endp;

Functions that are called with `dllcall` can only accept GAUSS variables as inputs.

Are you wanting to save the step of assigning the output of a GAUSS procedure to a variable before passing it to the function you are calling with `dllcall`? Or are you wanting to try to pass a GAUSS function in to a compiled (C/C++/Fortran) function that takes a function pointer as an argument?

If you provide a little more information, I may be able to help you accomplish your end goal.

Thanks.

I want to know how to pass a GAUSS function into a compiled Fortran function that takes a function pointer as an argument.

You cannot directly pass a GAUSS procedure into a Fortran function that takes a function pointer as an argument. There may be a work around. Could you provide some information about the Fortan code? Do you have the source code?

I do have the FORTRAN source code which does optimization, in this optimization subroutine, there is a call to another FORTRAN subroutine, say FCN(N, X, F):

subroutine FCN(N,X,F) double precision X, F F = x*x return end

which defines the objective function.

I want to compile the optimization subroutine and call it within GAUSS, while the definition of the objective function FCN is written in GAUSS rather than Fortran.

## Your Answer

## 5 Answers

Many optimization codes have a reverse communication interface where the compiled code (FORTRAN/C/C++) will return a specific return value when it would like the objective function to be evaluated along with the values at which it would like them evaluated at.

Below is a simple example of the concept. For this example, we will assume that we have a FORTRAN function that will assign `ret` to be equal to 1, assign the values at which it would like the function evaluated to `parmout` and then return whenever it would like a function evaluation. You could then set up your GAUSS code something like this:

ret = 1; parmin = zeros(4, 1); parmout = zeros(4, 1); ans = zeros(4,1); do while (ret); dllcall fortranOptRoutine(parmin, parmout, ans, ret); if (ret == 1); parmin = myFunc(parmout); endif; endo; proc (1) = myFunc(x); retp(x*x); endp;

Functions that are called with `dllcall` can only accept GAUSS variables as inputs.

Are you wanting to save the step of assigning the output of a GAUSS procedure to a variable before passing it to the function you are calling with `dllcall`? Or are you wanting to try to pass a GAUSS function in to a compiled (C/C++/Fortran) function that takes a function pointer as an argument?

If you provide a little more information, I may be able to help you accomplish your end goal.

Thanks.

I want to know how to pass a GAUSS function into a compiled Fortran function that takes a function pointer as an argument.

You cannot directly pass a GAUSS procedure into a Fortran function that takes a function pointer as an argument. There may be a work around. Could you provide some information about the Fortan code? Do you have the source code?

I do have the FORTRAN source code which does optimization, in this optimization subroutine, there is a call to another FORTRAN subroutine, say FCN(N, X, F):

subroutine FCN(N,X,F) double precision X, F F = x*x return end

which defines the objective function.

I want to compile the optimization subroutine and call it within GAUSS, while the definition of the objective function FCN is written in GAUSS rather than Fortran.