简体   繁体   English

Fortran77中(1)处的无法分类的语句和(1)处的意外数据声明的语句?

[英]Unclassifiable statement at (1) and Unexpected data declaration statement at (1) in Fortran77?

I am trying to count the number of lines in a file in Fortran 77 (My file has two columns, both with numbers) 我正在尝试计算Fortran 77中文件的行数(我的文件有两列,均带有数字)

I am getting an unclassifiable statement and unexpected data declaration and I am not sure why. 我收到了无法分类的声明和意外的数据声明,我不确定为什么。 This is my code: (new to fortran 77): 这是我的代码:(fortran 77的新功能):

    PROGRAM Exercise

C
C John Smith
C

C
C PARAMETERS
C
      REAL PRECISION UNUM
      PARAMETER (UNUM=15)
C
C LOCAL VARIABLES
C

C
C FUNCTION DECLARATIONS
C

      INTEGER*8 PRECISION NUMLIN

C
C COMMON VARIABLES
C

C
C DATA STATEMENTS
C
      DATA FILEN /'linecounttester.txt'/
C
C MAIN PROGRAM MODULE
C

      OPEN(UNIT=UNUM, FILE = FILEN, STATUS='OLD')

C
C function counts the lines in the file

C

      FUNCTION NUMLIN
      INTEGER*8 PRECISION NUMLIN
      CHARACTER*256 LINE
      100 READ(UNUM,*,END=200) LINE
      NUMLIN=NUMLIN+1
      GOTO 100
      200 CONTINUE

      RETURN
      END

      REWIND(UNUM)

      CLOSE(UNUM)

This is my data file: (just a tester so I can count the lines to 8): 1 100 2 200 3 300 4 400 5 500 6 600 7 700 8 800 这是我的数据文件:(只是一个测试器,所以我可以将行数数为8):1100 2 200 3 300 4 400 5 500 6 600 7 700 8 800

These are my errors: 这些是我的错误:

Exercise.for:58.6: Exercise.for:58.6:

  FUNCTION NUMLIN                                                   
  1

Error: Unclassifiable statement at (1) Exercise.for:59.32: 错误:在(1)Exercise.for:59.32处无法分类的陈述:

  INTEGER*8 PRECISION NUMLIN                                        
                            1

Error: Symbol 'precisionnumlin' at (1) already has basic type of INTEGER Exercise.for:60.72: 错误:(1)处的符号'precisionnumlin'已经具有INTEGER Exercise.for:60.72的基本类型:

  CHARACTER*256 LINE                                                
                                                                    1

Error: Unexpected data declaration statement at (1) Exercise.for:61.7: 错误:在(1)Exercise.for:61.7处发生了意外的数据声明语句:

  100 READ(UNUM,*,END=200)                                          
   1

Error: Invalid character in name at (1) Exercise.for:62.6: 错误:(1)Exercise.for:62.6名称中的字符无效:

  LINE                                                              
  1

Error: Unclassifiable statement at (1) Exercise.for:65.7: 错误:无法执行(1)练习中的声明:65.7:

  200 CONTINUE                                                      
   1

Error: Invalid character in name at (1) Exercise.for:41.10: 错误:(1)Exercise.for:41.10中名称中的字符无效:

  DATA FILEN /'linecounttester.txt'/                                
      1

Error: Incompatible types in DATA statement at (1); 错误:(1)处的DATA语句中的类型不兼容; attempted conversion of CHARACTER(1) to REAL(4) Exercise.for:46.16: 尝试将CHARACTER(1)转换为REAL(4)Exercise.for:46.16:

  OPEN(UNIT=UNUM, FILE = FILEN, STATUS='OLD')                       
            1

Error: UNIT tag at (1) must be of type INTEGER Exercise.for:64.72: 错误:(1)处的UNIT标签必须为INTEGER Exercise.for:64.72类型:

  GOTO 100                                                          
                                                                    1

Error: Label 100 referenced at (1) is never defined Exercise.for:1.72: 错误:从未定义在(1)处引用的标签100 Exercise.for:1.72:

  PROGRAM EXERCISE                                    
                                                                    1

Exercise.for:70.72: Exercise.for:70.72:

  REWIND(UNUM)                                                      
                                                                    2

Error: Two main PROGRAMs at (1) and (2) 错误:(1)和(2)处有两个主要程序

Can anyone help me out? 谁能帮我吗?

You are mixing your namespaces. 您正在混合名称空间。

you have a 你有一个

PROGRAM

statement, which needs a corresponding 声明,需要相应的

END

statement before you start declaring your functions. 在开始声明功能之前的声明。

that should fix the compilation errors you see. 应该可以解决您看到的编译错误。 however, i do not see where you actually call the function you create. 但是,我看不到您实际在哪里调用创建的函数。 in other words, it appears that you are defining a function without actually using it. 换句话说,您似乎在定义函数而未实际使用它。 I would suggest that you first write the code without the function, just to make sure it works. 我建议您首先编写不带该功能的代码,以确保它能正常工作。 then separate it out, until you get the hang of this :) 然后将其分离出来,直到您掌握了这个窍门:)

EDIT: I also second the comments under your question, about the strange syntax you are using. 编辑:我也将您的问题下的评论放在第二位,关于您使用的奇怪语法。 though I will not dissuade you from using FORTRAN77 but i hope you have a very good reason to do so ;) 尽管我不会劝阻您使用FORTRAN77,但希望您有充分的理由这样做;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM