Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
774 views
in Technique[技术] by (71.8m points)

fortran - Error: Non-numeric character in statement label at (1)?

I wrote the following two lines in fortran

C23456789
    REAL H3 = 0                                                       
    H3=H*H*H  

and I received the following errors from gdb :

ljmd.f:186.5:

    REAL H3 = 0                                                         
     1
Error: Non-numeric character in statement label at (1)
ljmd.f:187.5:

    H3=H*H*H                                                            
     1
Error: Non-numeric character in statement label at (1)
ljmd.f:187.6:

    H3=H*H*H                                                            
      1

What is the proper way to create and use new variables in the middle of someone else's fortran program? C23456789 is my label of the current column used in the program.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is in any random Fortran tutorial. I expect you have the fixed source form. Then any statement must start at column 7 or farther.

Also,

REAL H3 = 0

isn't legal in free form source Fortran and does a completely different thing in fixed form (see @francesalus' comment). And in your case there is no reason to initialize the variable at all. You can just do

  REAL H3
  H3 = H**3

If you happen to need the initialization somewhere else, you either must use

  real :: a = 0

(requires Fotran 90), or

  REAL A
  DATA A/0/

(in Fortran77). Beware, both version make the variable SAVE which you may know as static from other languages.

The last point, you cannot introduce variables anywhere "in the middle of program", the declaration of variables have their place at the beginning of each compilation unit (program, function, subroutine,...).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...