invalid character name at (1)

前端 未结 2 521
情深已故
情深已故 2021-01-26 12:40

I am trying to compile a fortran code. It will analyze an X file in an Y directory and then create a new file Z with the results. But there is something wrong occurring.

2条回答
  •  日久生厌
    2021-01-26 12:43

    This part of your compilation statement:

    gfortran Codigo.f 
    

    will treat the source file, with its .f suffix, as fixed form source. This means that a continuation line is indicated by any character (other than a blank or a 0) in column 6.

    However, the error message you get suggests that the + in the second line of your snippet is not in column 6 and that the compiler is treating it as the initial character in a new entity name for which it is not valid. The fact that the + is aligned, vertically, with n in the previous line strengthens my suspicion that this may the root of your problem.

    Adding the ampersand, as suggested in a now-deleted answer, doesn't actually help in this case if you continue to tell the compiler that it is dealing with a fixed form source file. & is only used for continuation in free form source files. Adding the string-concatenation operator, //, doesn't help either since it is not followed by another string but a line ending. //& would help but is probably unnecessary.

    I think you have 2 possible solutions, but choose only one:

    1. Stick with fixed form and get the alignment right.
    2. Change the file suffix to .f90 which will cause gfortran to treat the source file as free-form.

    If you go for option 2 (which I would recommend) you can then either use & at the end of the continued line or you could simply merge the lines. In free-form the maximum line length is 132 characters.

提交回复
热议问题