我一直在尝试调试这个调用 Fortran 子例程 DLSODE 的代码。这个子例程的两个参数是函数,FEX 和 JEX,我将它们作为函数指针传递。据我了解,fortran 子例程使用的任何函数都必须具有按引用调用的参数,因为 fortran 不接受按值调用。
我的问题是我得到的错误似乎表明我在指针的函数声明中声明的数据类型与下面的函数定义之间存在差异,并且我没有成功调试它。
#include <iostream>
#include <cmath>
using namespace std;
extern"C" {void DLSODE_(void (*fex)(int, double, double[], double[]), int *NEQ,
double *Y[], double *T, double *TOUT, int *ITOL,
double *RTOL, double *ATOL[], int *ITASK, int *ISTATE,
int *IOPT, double *RWORK[], int *LRW, int *IWORK[],
int *LIW, void (*jex)(int, double, double[], int,
int, double [3][3], int),
int *MF);
}
void FEX (int &NEQ, double &T, double Y[], int YDOT[]);
void JEX (int &NEQ, double &T, double Y[], int &ML, int &MU, double PD[3][3],
int &NRPD);
int main(){
int IOPT, IOUT, ISTATE, ITASK, ITOL, IWORK[23], LIW, LRW, MF, NEQ, ICOUNT=1;
double ATOL[3], RTOL, RWORK[58], T, TOUT, Y[3];
NEQ = 3;
Y[0] = 1;
Y[1] = 0;
Y[2] = 0;
T = 0;
TOUT = 0.4;
ITOL = 2;
RTOL = pow(10,-4);
ATOL[0] = pow(10,-6);
ATOL[1] = pow(10,-10);
ATOL[2] = pow(10,-6);
ITASK = 1;
ISTATE = 1;
IOPT = 0;
LRW = 58;
LIW = 23;
MF = 21;
for (ICOUNT; ICOUNT <13; ICOUNT++)
{
DLSODE_(&FEX, &NEQ, &Y, &T, &TOUT, &ITOL, &RTOL, &ATOL, &ITASK, &ISTATE,
&IOPT, &RWORK, &LRW, &IWORK, &LIW, &JEX, &MF);
cout<<"At t= "<<T<<" y= "<<Y[1]<<" "<<Y[2]<<" "<<Y[3]<<"\n";
}
}
void FEX (int &NEQ, double &T, double Y[], double YDOT[]){
YDOT[0] = -.04*Y[0] + pow(10,4)*Y[1]*Y[2];
YDOT[2] = 3*pow(10,7)*Y[1]*Y[1];
YDOT[1] = -YDOT[0] - YDOT[2];
}
void JEX (int &NEQ, double &T, double Y[], int &ML, int &MU, double &PD[3][3],
int &NRPD){
PD[0][0] = -.04;
PD[0][1] = 1*pow(10,4)*Y[2];
PD[0][2] = 1*pow(10,4)*Y[1];
PD[1][0] = .04;
PD[1][2] = -PD[0][2];
PD[2][1] = 6*pow(10,7)*Y[1];
PD[1][1] = -PD[0][1] - PD[2][1];
}
错误消息是
cversion1.cpp: In function ‘int main()’:
cversion1.cpp:44:52: error: invalid conversion from ‘void (*)(int&, double&, double*, int*)’ to ‘void (*)(int, double, double*, double*)’
cversion1.cpp:44:52: error: cannot convert ‘double (*)[3]’ to ‘double**’ for argument ‘3’ to ‘void DLSODE_(void (*)(int, double, double*, double*), int*, double**, double*, double*, int*, double*, double**, int*, int*, int*, double**, int*, int**, int*, void (*)(int, double, double*, int, int, double (*)[3], int), int*)’
cversion1.cpp: At global scope:
cversion1.cpp:55:77: error: declaration of ‘PD’ as array of references
cversion1.cpp:55:78: error: expected ‘)’ before ‘,’ token
cversion1.cpp:56:4: error: expected unqualified-id before ‘int’
谢谢,