Fortran Coder

查看: 4150|回复: 2
打印 上一主题 下一主题

[混编] 新人求助,混编中参数输入出现系列问题

[复制链接]

8

帖子

2

主题

0

精华

入门

F 币
62 元
贡献
23 点
跳转到指定楼层
楼主
发表于 2021-11-29 16:54:36 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 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] 纯文本查看 复制代码
01c ... fortran代码,trace_gas_model的interface编写
02      INTERFACE
03        SUBROUTINE trace_gas_model(newminrl, ammonium, nitrate, texture,
04     &                             sand, silt, clay, afiel, bulkd, maxt,
05     &                             ppt, snow, avgwfps,stormf, basef,
06     &                             frlechd, stream, inorglch, critflow,
07     &                             wfluxout, newCO2, co2_conc, efscltef, time,
08     &                             NOflux, Nn2oflux, Dn2oflux, Dn2flux, CH4,
09     &                             isdecid, isagri, aglivc, rleavc, btolai,
10     &                             crpstore, forstore, nit_amt, nreduce, curday,
11     &                             pHscale, dN2lyr, dN2Olyr, month)
12          !MS$ATTRIBUTES ALIAS:'_trace_gas_model' :: trace_gas_model
13          DOUBLE PRECISION newminrl
14          DOUBLE PRECISION ammonium
15          DOUBLE PRECISION nitrate(*)
16          INTEGER          texture
17          REAL             sand
18          REAL             silt
19          REAL             clay
20          REAL             afiel
21          REAL             bulkd
22          REAL             maxt
23          REAL             ppt
24          REAL             snow
25          REAL             avgwfps
26          REAL             stormf
27          REAL             basef
28          REAL             frlechd(*)
29          REAL             stream(*)
30          DOUBLE PRECISION inorglch
31          REAL             critflow
32          REAL             wfluxout(*)
33          REAL             newCO2
34          REAL             co2_conc(*)
35          REAL             efscltef
36          REAL             time
37          DOUBLE PRECISION NOflux
38          DOUBLE PRECISION Nn2oflux
39          DOUBLE PRECISION Dn2oflux
40          DOUBLE PRECISION Dn2flux
41          DOUBLE PRECISION CH4
42          INTEGER          isdecid
43          INTEGER          isagri
44          REAL             aglivc
45          REAL             rleavc
46          REAL             btolai
47          REAL             crpstore
48          REAL             forstore
49          DOUBLE PRECISION nit_amt
50          REAL             nreduce
51          INTEGER          curday
52          REAL             pHscale
53          DOUBLE PRECISION dN2lyr(*)
54          DOUBLE PRECISION dN2Olyr(*)
55          INTEGER          month
56        END SUBROUTINE trace_gas_model


dailymoist.f中调用该trace_gas_model的代码如下,共有43个参数:
[Fortran] 纯文本查看 复制代码
01c ... trace_gas_model调用
02      call trace_gas_model(newminrl, ammonium, nitrate, texture,
03     &                     sand, silt, clay, afiel(1), bulkd, maxt,
04     &                     ppt(curday), snow, avgwfps, stormf, basef,
05     &                     frlechd, stream, inorglch, critflow,
06     &                     wfluxout, newCO2, co2_conc, efscltef, time,
07     &                     NOflux, Nn2oflux, Dn2oflux, Dn2flux, CH4,
08     &                     isdecid, isagri, aglivc, rleavc, btolai,
09     &                     crpstg(N),forstg(N),nit_amt,nreduce,curday,
10     &                     pHscalar(month), dN2lyr, dN2Olyr, month)


dailymoist.f中与trace_gas_model相关的local variables声明如下,dN2lyr, dN2Olyr为数组:
[Fortran] 纯文本查看 复制代码
01c ... 相关的local variable声明
02c ... LOCAL VARIABLES
03c ... SWMAXLYR为parameter :: 43
04      double precision newminrl, inorglch
05      real             avgwfps
06      real             frlechd(MAXIEL)
07      real             critflow
08      real             wfluxout(SWMAXLYR)
09      real             newCO2
10      real             co2_conc(SWMAXLYR)
11      real             dstr, efscltef
12      double precision Nn2oflux, Dn2oflux, Dn2flux, NOflux
13      double precision CH4, nit_amt
14      integer          isdecid, isagri
15      double precision dN2lyr(SWMAXLYR), dN2Olyr(SWMAXLYR)


被调用c代码声明如下:
[C] 纯文本查看 复制代码
01/* c source code, tgmodel.c */
02    void trace_gas_model(double *newminrl, double *ammonium, double nitrate[], int *texture,
03                         float *sand, float *silt, float *clay, float *afiel, float *bulkd, float *maxt,
04                         float *ppt, float *snow, float *avgwfps, float *stormf, float *basef, 
05                         float frlechd[], float stream[], double *inorglch, float *critflow,
06                         float wfluxout[], float *newCO2, float co2PPM[], float *efscltef, float *time,
07                         double *NOflux, double *Nn2oflux, double *Dn2oflux, double *Dn2flux, double *CH4,
08                         int *isdecid, int *isagri, float *aglivc, float *rleavc, float *btolai, 
09                         float *crpstore, float *forstore, double *nit_amt, float *nreduce, int *jday,
10                         float *pHscale, double dN2lyr[], double dN2Olyr[], int *month)                


如果需要的话,这是上一个版本interface的写法,可以见到我仅仅是多加了一个efscltef的说明:
[Fortran] 纯文本查看 复制代码
01   SUBROUTINE trace_gas_model(newminrl, ammonium, nitrate,
02&                             texture, sand, silt, clay, afiel,
03&                             bulkd, maxt, ppt, snow, avgwfps,
04&                             stormf, basef, frlechd, stream,
05&                             inorglch, critflow, wfluxout,
06&                             newCO2, co2_conc, time, NOflux,
07&                             Nn2oflux, Dn2oflux, Dn2flux, CH4,
08&                             isdecid, isagri, aglivc, rleavc,
09&                             btolai, crpstore, forstore, nit_amt,
10&                             nreduce, curday, pHscale, dN2lyr,
11&                             dN2Olyr, month)
12     !MS$ATTRIBUTES ALIAS:'_trace_gas_model' :: trace_gas_model
13     DOUBLE PRECISION newminrl
14     DOUBLE PRECISION ammonium
15     DOUBLE PRECISION nitrate(*)
16     INTEGER          texture
17     REAL             sand
18     REAL             silt
19     REAL             clay
20     REAL             afiel
21     REAL             bulkd
22     REAL             maxt
23     REAL             ppt
24     REAL             snow
25     REAL             avgwfps
26     REAL             stormf
27     REAL             basef
28     REAL             frlechd(*)
29     REAL             stream(*)
30     DOUBLE PRECISION inorglch
31     REAL             critflow
32     REAL             wfluxout(*)
33     REAL             newCO2
34     REAL             co2_conc(*)
35     REAL             time
36     DOUBLE PRECISION NOflux
37     DOUBLE PRECISION Nn2oflux
38     DOUBLE PRECISION Dn2oflux
39     DOUBLE PRECISION Dn2flux
40     DOUBLE PRECISION CH4
41     INTEGER          isdecid
42     INTEGER          isagri
43     REAL             aglivc
44     REAL             rleavc
45     REAL             btolai
46     REAL             crpstore
47     REAL             forstore
48     DOUBLE PRECISION nit_amt
49     REAL             nreduce
50     INTEGER          curday
51     REAL             pHscale
52     DOUBLE PRECISION dN2lyr(*)
53     DOUBLE PRECISION dN2Olyr(*)
54     INTEGER          month
55   END SUBROUTINE trace_gas_model




分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

8

帖子

2

主题

0

精华

入门

F 币
62 元
贡献
23 点
沙发
 楼主| 发表于 2021-11-30 09:53:58 | 只看该作者
因为不知道要如何删帖或者加上已解决的标签,在回复里记录一下这个问题的解决。
因为上古代码是F77固定格式的,所以行上有字符限制,这些定义和调用函数的行超出了限制,导致参数读取错误。

2038

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1676 元
贡献
715 点

美女勋章热心勋章星光勋章新人勋章贡献勋章管理勋章帅哥勋章爱心勋章规矩勋章元老勋章水王勋章

板凳
发表于 2021-11-30 13:01:58 | 只看该作者
试试 /extend_source:132
(已解决标签,需要版主或管理员才能加)

您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2025-5-3 13:11

Powered by Discuz! X3.4

© 2013-2025 Comsenz Inc.

快速回复 返回顶部 返回列表