Fortran Coder
标题: 新人求助,混编中参数输入出现系列问题 [打印本页]
作者: ptxyzs2 时间: 2021-11-29 16:54
标题: 新人求助,混编中参数输入出现系列问题
本帖最后由 ptxyzs2 于 2021-11-29 17:05 编辑
VS2019,x86+win32的fortran与c的混编下,出于某些原因没有使用iso_c_binding来混编,而是通过在fortran代码dailymoist.f中编写interface来调用c语言编写的trace_gas_model函数。
代码是对上一个版本代码的更新,interface的编写是根据上一个版本编写的,调用的c语言代码只是增加了一个float *efscltef参数,因此对原interface的修改也仅仅是增加了一个对efscltef参数的声明。上一个版本的代码运行是没有问题的,但是新代码不知道为什么在参数这里出现了多个相关的不同错误:
(a) error #6633: The type of the actual argument differs from the type of the dummy argument.;
(b) error #6784: The number of actual arguments cannot be greater than the number of dummy arguments.;
(c) error #8284: If the actual argument is scalar, the dummy argument shall be scalar unless the actual argument is of type character or is an element of an array that is not assumed shape, pointer, or polymorphic. [DN2LYR, DN2OLYR]。
个人认为问题首先出在error #6784实参、虚参的数目不一致上,但是我多次对过,数目是一样的43个,十分不理解为什么会出现这个问题。而其他的类型不一样、数组与标量的问题,我一一对过,也是一致的,所以实在不知道问题出在哪里,不知道接下来从何入手,还请大家指教。提供的代码比较长,实在是不好意思了
出问题的dailymoist.f文件中,trace_gas_model函数的interface编写如下,共有43个参数, dN2lyr, dN2Olyr为数组:
[Fortran] 纯文本查看 复制代码
c ... fortran代码,trace_gas_model的interface编写
INTERFACE
SUBROUTINE trace_gas_model(newminrl, ammonium, nitrate, texture,
& sand, silt, clay, afiel, bulkd, maxt,
& ppt, snow, avgwfps,stormf, basef,
& frlechd, stream, inorglch, critflow,
& wfluxout, newCO2, co2_conc, efscltef, time,
& NOflux, Nn2oflux, Dn2oflux, Dn2flux, CH4,
& isdecid, isagri, aglivc, rleavc, btolai,
& crpstore, forstore, nit_amt, nreduce, curday,
& pHscale, dN2lyr, dN2Olyr, month)
!MS$ATTRIBUTES ALIAS:'_trace_gas_model' :: trace_gas_model
DOUBLE PRECISION newminrl
DOUBLE PRECISION ammonium
DOUBLE PRECISION nitrate(*)
INTEGER texture
REAL sand
REAL silt
REAL clay
REAL afiel
REAL bulkd
REAL maxt
REAL ppt
REAL snow
REAL avgwfps
REAL stormf
REAL basef
REAL frlechd(*)
REAL stream(*)
DOUBLE PRECISION inorglch
REAL critflow
REAL wfluxout(*)
REAL newCO2
REAL co2_conc(*)
REAL efscltef
REAL time
DOUBLE PRECISION NOflux
DOUBLE PRECISION Nn2oflux
DOUBLE PRECISION Dn2oflux
DOUBLE PRECISION Dn2flux
DOUBLE PRECISION CH4
INTEGER isdecid
INTEGER isagri
REAL aglivc
REAL rleavc
REAL btolai
REAL crpstore
REAL forstore
DOUBLE PRECISION nit_amt
REAL nreduce
INTEGER curday
REAL pHscale
DOUBLE PRECISION dN2lyr(*)
DOUBLE PRECISION dN2Olyr(*)
INTEGER month
END SUBROUTINE trace_gas_model
dailymoist.f中调用该trace_gas_model的代码如下,共有43个参数:
[Fortran] 纯文本查看 复制代码
c ... trace_gas_model调用
call trace_gas_model(newminrl, ammonium, nitrate, texture,
& sand, silt, clay, afiel(1), bulkd, maxt,
& ppt(curday), snow, avgwfps, stormf, basef,
& frlechd, stream, inorglch, critflow,
& wfluxout, newCO2, co2_conc, efscltef, time,
& NOflux, Nn2oflux, Dn2oflux, Dn2flux, CH4,
& isdecid, isagri, aglivc, rleavc, btolai,
& crpstg(N),forstg(N),nit_amt,nreduce,curday,
& pHscalar(month), dN2lyr, dN2Olyr, month)
dailymoist.f中与trace_gas_model相关的local variables声明如下,dN2lyr, dN2Olyr为数组:
[Fortran] 纯文本查看 复制代码
c ... 相关的local variable声明
c ... LOCAL VARIABLES
c ... SWMAXLYR为parameter :: 43
double precision newminrl, inorglch
real avgwfps
real frlechd(MAXIEL)
real critflow
real wfluxout(SWMAXLYR)
real newCO2
real co2_conc(SWMAXLYR)
real dstr, efscltef
double precision Nn2oflux, Dn2oflux, Dn2flux, NOflux
double precision CH4, nit_amt
integer isdecid, isagri
double precision dN2lyr(SWMAXLYR), dN2Olyr(SWMAXLYR)
被调用c代码声明如下:
[C] 纯文本查看 复制代码
/* c source code, tgmodel.c */
void trace_gas_model(double *newminrl, double *ammonium, double nitrate[], int *texture,
float *sand, float *silt, float *clay, float *afiel, float *bulkd, float *maxt,
float *ppt, float *snow, float *avgwfps, float *stormf, float *basef,
float frlechd[], float stream[], double *inorglch, float *critflow,
float wfluxout[], float *newCO2, float co2PPM[], float *efscltef, float *time,
double *NOflux, double *Nn2oflux, double *Dn2oflux, double *Dn2flux, double *CH4,
int *isdecid, int *isagri, float *aglivc, float *rleavc, float *btolai,
float *crpstore, float *forstore, double *nit_amt, float *nreduce, int *jday,
float *pHscale, double dN2lyr[], double dN2Olyr[], int *month)
如果需要的话,这是上一个版本interface的写法,可以见到我仅仅是多加了一个efscltef的说明:
[Fortran] 纯文本查看 复制代码
SUBROUTINE trace_gas_model(newminrl, ammonium, nitrate,
& texture, sand, silt, clay, afiel,
& bulkd, maxt, ppt, snow, avgwfps,
& stormf, basef, frlechd, stream,
& inorglch, critflow, wfluxout,
& newCO2, co2_conc, time, NOflux,
& Nn2oflux, Dn2oflux, Dn2flux, CH4,
& isdecid, isagri, aglivc, rleavc,
& btolai, crpstore, forstore, nit_amt,
& nreduce, curday, pHscale, dN2lyr,
& dN2Olyr, month)
!MS$ATTRIBUTES ALIAS:'_trace_gas_model' :: trace_gas_model
DOUBLE PRECISION newminrl
DOUBLE PRECISION ammonium
DOUBLE PRECISION nitrate(*)
INTEGER texture
REAL sand
REAL silt
REAL clay
REAL afiel
REAL bulkd
REAL maxt
REAL ppt
REAL snow
REAL avgwfps
REAL stormf
REAL basef
REAL frlechd(*)
REAL stream(*)
DOUBLE PRECISION inorglch
REAL critflow
REAL wfluxout(*)
REAL newCO2
REAL co2_conc(*)
REAL time
DOUBLE PRECISION NOflux
DOUBLE PRECISION Nn2oflux
DOUBLE PRECISION Dn2oflux
DOUBLE PRECISION Dn2flux
DOUBLE PRECISION CH4
INTEGER isdecid
INTEGER isagri
REAL aglivc
REAL rleavc
REAL btolai
REAL crpstore
REAL forstore
DOUBLE PRECISION nit_amt
REAL nreduce
INTEGER curday
REAL pHscale
DOUBLE PRECISION dN2lyr(*)
DOUBLE PRECISION dN2Olyr(*)
INTEGER month
END SUBROUTINE trace_gas_model
作者: ptxyzs2 时间: 2021-11-30 09:53
因为不知道要如何删帖或者加上已解决的标签,在回复里记录一下这个问题的解决。
因为上古代码是F77固定格式的,所以行上有字符限制,这些定义和调用函数的行超出了限制,导致参数读取错误。
作者: fcode 时间: 2021-11-30 13:01
试试 /extend_source:132
(已解决标签,需要版主或管理员才能加)
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) |
Powered by Discuz! X3.2 |