Fortran 调用语句中的语法错误 [英] Syntax error in call statement in Fortran

查看:16
本文介绍了Fortran 调用语句中的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个简单的测试程序来尝试 Fortran 中的子例程和调用语句.我在 GNU/Linux 中使用 gfortran 编译器.我已经声明了 14 个参数,这些参数在我的代码中相应编号.当我尝试通过调用语句传递其中的 11 个参数时,我的代码工作得非常好,但当我尝试包含第 12 个参数并尝试通过调用语句传递 12 个参数时,我遇到了一个相当奇怪的语法错误".问题可能是什么,我该如何解决?这是我正在谈论的程序

I have written a simple test program to try subroutines and the call statement in Fortran. I am using gfortran compiler in GNU/Linux. I have declared 14 parameters which are numbered accordingly in my code. While my code works PERFECTLY WELL when I try to pass 11 of those arguments through the call statement, I encounter a rather strange 'SYNTAX ERROR' when I try to include a 12th argument and I try to pass 12 arguments through the call statement. What might the problem be and how might I fix it? Here is the program I am talking about

`

    program test

         IMPLICIT REAL*4(A-B,D-H,O-Z)
         IMPLICIT COMPLEX(C)
         COMPLEX*16 CQC,CQV

         parameter k1=2   
         parameter k2=2  
         parameter k3=2
         parameter k4=2
         parameter k5=2
         parameter k6=2
         parameter k7=2
         parameter k8=2
         parameter k9=2
         parameter k10=2
         parameter k11=2
         parameter k12=2
         parameter k13=2
         parameter k14=2

         call bins(k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12) 

    end program


    subroutine bins(k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12)

         integer k1, k2, k3, k4, k5

    end subroutine   `

以下是我在'call'语句中包含k12然后编译它时得到的错误:

Following is the error that I get when I include k12 in the 'call' statement and then compile it:

`

siddharth@siddharth-VBox:~/Desktop/Codes$ gfortran test6.for -o  test6.out
test6.for:23.72:

             call bins(k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12
                                                                    1
Error: Syntax error in argument list at (1)
test6.for:29.72:

        subroutine bins(k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k1
                                                                    1
Error: Unexpected junk in formal argument list at (1)
test6.for:2.72:

        program test                                                    
                                                                    1
test6.for:31.72:

            integer k1, k2, k3, k4, k5                                 
                                                                    2
Error: Two main PROGRAMs at (1) and (2)

`

我重申,当我在 call 语句中包含参数 k1 到 k11 时,我在编译时没有遇到任何问题,它只是引入了第 12 个参数,从而引入了问题.任何帮助将不胜感激.

I reiterate that I don't encounter any problems in compiling when I include the arguments k1 to k11 in the call statement, its just the introduction of a 12th argument that introduces the problem. Any help will be appreciated.

推荐答案

按照惯例,扩展名为 .for 或 .f 的文件被视为固定格式源.固定格式行上的语句必须位于第 7 列和第 72 列之间,包括第 7 列和第 72 列.请注意错误消息中的列位置 - 语句的结尾被截断.

Files with a .for or .f extension, by convention, are treated as fixed form source. Statements on fixed form lines must go in between columns 7 and 72, inclusive. Note the column position in the error message - the end of your statement is being chopped off.

固定形式的源代码也对空格不敏感.call 语句之前的所有parameter kxxx 赋值语句都不是你想的那样.

Fixed form source is also not sensitive to whitespace. All the parameter kxxx assignment statements before the call statement don't do what you think.

除非您正在修改现有的遗留代码,否则不要使用固定格式的源代码.

Do not use fixed form source unless you are modifying existing legacy code.

除非您正在修改现有的遗留代码(或者可能参与一些深奥的泛型编程应用程序),否则不要使用隐式类型.IMPLICIT NONE 是你最好的朋友.

Do not use implicit typing unless you are modifying existing legacy code (or perhaps engaging in some esoteric application of generic programming). IMPLICIT NONE is your best friend.

这篇关于Fortran 调用语句中的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆