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

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

问题描述

我写了一个简单的测试程序来尝试子程序和Fortran中的调用语句。我在GNU / Linux中使用gfortran编译器。我已经声明了14个参数,这些参数在我的代码中相应编号。虽然我的代码在PERFECTLY WELL中工作时尝试通过调用语句传递其中的11个参数,但当我试图包含第12个参数并尝试通过调用语句传递12个参数时,遇到了一个相当奇怪的SYNTAX ERROR。问题可能是什么,我该如何解决?这里是我正在讨论的程序
$ b $ p
$ b $ pre $ 程序测试

IMPLICIT REAL * 4(AB,DH,OZ)
隐式复合(C)
复数* 16 CQC,CQV

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

呼叫箱(k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12)

结束程序


子程序单元(k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12)

整数k1,k2 ,k3,k4,k5

结束子程序`

以下是错误当我包括时我会得到然后编译它:

`

  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
错误:参数列表中的语法错误(1)
test6.for:29.72:

子程序仓(k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k1
1
错误:正式参数列表中的意外垃圾(1)
test6.for:2.72:

程序测试
1
test6.for:31.72:

整数k1,k2 ,k3,k4,k5
2
错误:(1)和(2)两个主程序

`

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

解决方案

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



固定格式源对空格也不敏感。在调用语句之前的所有参数kxxx 赋值语句都不符合您的想法。



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


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   `

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)

`

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.

解决方案

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.

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.

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天全站免登陆