Quantcast
Channel: Intel® Software - Intel® Visual Fortran Compiler for Windows*
Viewing all articles
Browse latest Browse all 5691

About calling and using Fortran dll in c

$
0
0

Hi! After I posted my problem about calling Fortran dll in c in this forum, But it is hard way. I struggled to try it these days. I want to use nonlinear regression analysis by odrpack. All information and program is put here:TOMS 869. I create a dll containing  lpkbls.f,  odr.f,  real_precision.f 3 files. For odr.f, I added  !DEC$ ATTRIBUTES DLLEXPORT :: ODR below SUBROUTINE ODR. Next I took a prog simple_example.f90 translated into C  for testing  dll. This is my unfinished code:

#include "stdafx.h"
#include< iostream>
using namespace std;
extern"C"{void ODR( void* a, int *N, int *M, int *NP, int *NQ, double *BETA, double *Y, double *X); }

void FCN(int *N, int *M, int *NP, int *NQ, int *LDN, int *LDM,\
	int *LDNP, double *BETA, double *XPLUSD ,int *IFIXB, int *IFIXX, int *LDIFX,\
	int *IDEVAL, double *F, double *FJACB,double *FJACD, int *ISTOP);

int _tmain(int argc, _TCHAR* argv[])
{
	int NP = 2, N = 4, M = 1, NQ = 1,;

	double X[] = { 0.982, 1.998, 4.978, 6.01 }, Y[] = { 2.7, 7.4, 148.0, 403.0 };
	double BETA[] = { 2.0, 0.5 }, L[] = { 0.0, 0.0 }, U[] = {10,0.9};

	cout << ODR( FCN, &N, &M, &NP, &NQ,BETA,Y,X) << endl;

	system("pause");
	return 0;
}

void FCN(int *N, int *M, int *NP, int *NQ, int *LDN, int *LDM, int *LDNP,\
	double *BETA, double *XPLUSD, int *IFIXB, int *IFIXX, int *LDIFX, \
	int *IDEVAL, double *F, double *FJACB, double *FJACD, int *ISTOP){
	ISTOP = 0;

	if (fmod(IDEVAL,10)!=0){
		for (int i = 0, i < N; i++){
			F[i][0] = BETA[0] * exp(BETA[1] * XPLUSD[i]);
		}
	}

	if (fmod(IDEVAL/10, 10) != 0){
		for (int i = 0, i <  N; i++){
			FJACB[i][0][0] = BETA[0] * exp(BETA[1] * XPLUSD[i][0]);
			FJACB[i][1][0] = BETA[0] * XPLUSD[i] *exp(BETA[1] * XPLUSD[i][0]);
		}
	}

	if (fmod(IDEVAL / 100, 10) != 0){
		for (int i = 0, i < N; i++){

			FJACD[i][0][0] = BETA[1] * BETA[0]* XPLUSD[1]* exp(BETA[1] * XPLUSD[i][0]);
		}
	}

}

My operating environment is Visual Studio 2013, and my program languages are Visual Fortran,and Visual C++.

About user defined function FCN, you can check in guide.ps page 21-24.

Currently, I found some problems. 

1. subroutine ODR needs user-defined FCN function as argument, how to program it in C so that I can pass it to dll? 

2. In void FCN, it declares int *IDEVAL and use it, however I cannot find where it is set value. 

Last, I am glad  you give other advice or information about my problem, thanks for you helping.


Viewing all articles
Browse latest Browse all 5691

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>