|
各位大神,我现在用fortran调用C的函数,目前的情况是这样,我将两个工程在同一个解决方案中分别建立,通过lib文件进行连接,编译通过应该可以证明没有编译错误,通过单步调试DEBUG发现二者已经链接上,但是二者之间数据似乎没有传递,感觉很奇怪,以下是代码:
fortran的部分:
[Fortran] 纯文本查看 复制代码
SUBROUTINE ISAT
1 (ELWRK, LRW, IELWRK, LIW, ANDTOL, EPSTOL, RNDTOL, STRIDE, YALL)
C
INCLUDE 'CHEM.TXT'
EXTERNAL BISRCH [C], BALNCE [C], INSRTD [C], ENLRGE [C],
& FRMEM[C], STATIS[C], FUN, JAC
DIMENSION YALL(KMAX), YTMP(KMAX), YQ(KMAX)
DIMENSION ELWRK(LRW),IELWRK(LIW)
C
INTEGER(4) nstep, ifind, iinteg, ienlge, irecrd
INTEGER(4) IFLAG, NONEAR, BF, GS, JS, GSN, GSO, GROSS
DOUBLE PRECISION ABOVE, BELOW, Y, DDY
DIMENSION Y(KMAX),DDY(KMAX),RTOL(KMAX),ATOL(KMAX)
DIMENSION ABOVE(KMAX+1),BELOW(KMAX+1),RPAR(KMAX),IPAR(KMAX)
c
real*4 contm,difftm,chemtm,dintm,isatm,intgtm,srchtm,deltm,
& slargetm,baltm,tmchm,tmchm0
common /stime/ difftm, contm, chemtm, dintm, isatm, intgtm,
& srchtm, deltm, slargetm, baltm
common /sflag/ nstep, ifind, iinteg, ienlge, irecrd
common /ode/ neq, mf, itol, iopt, itask, istate,rtol, atol
c
COMMON /FIND/ Y, DDY, ABOVE, BELOW, BF, JS, GROSS
COMMON /FLAG/ IFLAG, NONEAR, GSN, GSO
*
DO I = 1, KK+1
YTMP(I) = YALL(I)
Y(I) = YTMP(I)
END DO
*
TMPTM0 = SECNDS(0.0)
CALL BISRCH
TMPTM = SECNDS(0.0)
SRCHTM = SRCHTM + (TMPTM - TMPTM0)
*
IF ((NONEAR.EQ.0).OR.(IFLAG.EQ.0)) THEN
DO I = 1, KK+1
YQ(I) = YTMP(I) + DDY(I)
END DO
END IF
*
IF (IFLAG .EQ. 0) THEN
DO I = 1, KK+1
YALL(I) = YQ(I)
END DO
IFIND = IFIND + 1
ELSE
*
ISTATE = 1
TMP = 0.0
360 CONTINUE
TMPTM0 = SECNDS(0.0)
CALL DVODE(FUN,NEQ,YTMP,TMP,STRIDE,ITOL,RTOL,ATOL,ITASK,ISTATE,
& IOPT,ELWRK,LRW,IELWRK,LIW,JAC,MF,RPAR,IPAR)
TMPTM = SECNDS(0.0)
INTGTM = INTGTM + (TMPTM - TMPTM0)
IINTEG = IINTEG + 1
C
900 CONTINUE
END IF
C
RETURN
END
C的部分:[C] 纯文本查看 复制代码
#include "stdafx.h"
#include "isatcdef.h"
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <malloc.h>
// specification of the structures and some variables.
struct incrmnt
{
double y[lenth];
double ddy[lenth];
double above[lenth];
double below[lenth];
int bf;
int js;
int gross;
struct incrmnt *lchild;
struct incrmnt *rchild;
struct incrmnt *father;
};
struct strctflag
{
int iflag;
int nonear;
int gsn;
int gso;
};
struct ssflag
{ int nstep;
int ifind;
int iinteg;
int ienlge;
int irecrd;
};
struct incrmnt FIND;
struct strctflag FLAG;
struct ssflag SFLAG;
struct incrmnt *phead=NULL,*pfind=NULL,*pfather=NULL,
*pnear=NULL,*q=NULL,*a=NULL,*f=NULL,*b=NULL,*pd=NULL;
double plus[lenth],minus[lenth];
double min=Maxmin;
// end of the specifications.
extern "C" void bisrch()
{
int compar(struct incrmnt *,struct incrmnt *);
struct incrmnt *p;
int flag,i;
// initialize pfind.
// pfind=(struct incrmnt *)malloc(sizeof(struct incrmnt));
pfind=new incrmnt;
for(i=0;i<=lenth-1;i++)
pfind->y[i]=FIND.y[i];
pfind->lchild=NULL;
pfind->rchild=NULL;
pfind->father=NULL;
pfind->bf=0;
pfind->js=0;
pfind->gross=0;
if (phead==NULL)
{
phead=pfind;
FLAG.iflag=1;
FLAG.nonear=1;
return;
}
else
/*to find the location for pfind, insert it and adjust the bitree*/
{
f=NULL;a=phead;p=phead;q=NULL;
/*to find the location to insert pfind*/
while(p!=NULL)
{
if(p->bf!=0)
{a=p;f=q;} /* adjustment will start from node a,*/
/* f is the parents node of a */
//p->father=q;
q=p;
flag=compar(pfind,p); /*comparing the keyword*/
if(flag==0)
{
for(i=0;i<=lenth-1;i++)
{
FIND.ddy[i]=p->ddy[i];
}
p->js=p->js+1;
FIND.js=p->js;
min=Maxmin;
pnear=NULL;
delete pfind;
FLAG.iflag=0;
return;
}
else
if(flag==1)
p=p->lchild;
else
p=p->rchild;
}
if (fabs(min-Maxmin)<=1.e-10)
FLAG.nonear=1;
else
{
FLAG.nonear=0;
for (i=0;i<=lenth-1;i++)
{
FIND.ddy[i]=pnear->ddy[i];
}
}
FLAG.iflag=1;
return;
}
}
还有一个比较奇怪的地方是报错竟然是stack trace terminated abnormally,这个程序之前是有人用过的,不过是在CVF编译器上面实现的,但至少在堆栈上应该是不会存在问题的,不知道是否跟换编译器有关系,或者是我之前所说的链接问题?
说的比较杂乱,希望大神们不要怪罪!
十分感谢各位!!! |
|