Search code examples
fortranintel-fortranabaqus

Trouble with WRITE statement and line continuations in Fortran


I am currently trying to figure out the problem with a line continuation in Fortran, and I'm new to the language. I am writing this for use with the software package ABAQUS, where all of the compilation is done using ifort. I believe the compilation is set to be compatible with Fortran 90. I have tried all of the below configurations for a line continuation in the middle of a WRITE statement:


        FILENAME = TRIM(KMC_DATADIR) // '/elementInfo.txt'
        OPEN(1001, FILE=FILENAME, STATUS="REPLACE", ACTION="WRITE")     

        FS = '(I5,I5,I5,F12.10)'

        DO K1=1,KMC_NUMELEM
            WRITE(1001,FS) KMC_ELEMENTS(K1)%IDNUM, KMC_ELEMENTS(K1)%MATID,
     &      KMC_ELEMENTS(K1)%TRANSFORMED, KMC_ELEMENTS(K1)%ORIENT%RMAT(1,1)
        END DO

        CLOSE(1001)

        FILENAME = TRIM(KMC_DATADIR) // '/elementInfo.txt'
        OPEN(1001, FILE=FILENAME, STATUS="REPLACE", ACTION="WRITE")     

        FS = '(I5,I5,I5,F12.10)'

        DO K1=1,KMC_NUMELEM
            WRITE(1001,FS) KMC_ELEMENTS(K1)%IDNUM, KMC_ELEMENTS(K1)%MATID, &
            KMC_ELEMENTS(K1)%TRANSFORMED, KMC_ELEMENTS(K1)%ORIENT%RMAT(1,1)
        END DO

        CLOSE(1001)

        FILENAME = TRIM(KMC_DATADIR) // '/elementInfo.txt'
        OPEN(1001, FILE=FILENAME, STATUS="REPLACE", ACTION="WRITE")     

        FS = '(I5,I5,I5,F12.10)'

        DO K1=1,KMC_NUMELEM
            WRITE(1001,FS) KMC_ELEMENTS(K1)%IDNUM, KMC_ELEMENTS(K1)%MATID, &
     &      KMC_ELEMENTS(K1)%TRANSFORMED, KMC_ELEMENTS(K1)%ORIENT%RMAT(1,1)
        END DO

        CLOSE(1001)

The compiler error I keep getting is this:

TRIPTrans.f(55): error #5082: Syntax error, found '&' when expecting one of: ( ...

       WRITE(1001,FS) KMC_ELEMENTS(K1)%IDNUM,KMC_ELEMENTS(K1)%MATID, &

----------------------------------------------------------------------------------------------------^

Am I allowed to split a write statement onto multiple lines?


Solution

  • Your code is not compatible with the -extend_source Intel Fortran compiler option.

    What the option does is that it extends the length of the line from 72 to 132 characters for fixed form sources. That might be convenient, however, many codes use the space after column 72 to store comments.

    Indeed, your & in

    WRITE(1001,FS) KMC_ELEMENTS(K1)%IDNUM,KMC_ELEMENTS(K1)%MATID, &
    

    is supposed to be a comment, invisible to the compiler. It is usually done to create files which are compatible with fixed and free form at the same time. But it is not invisible, due to -extend source.

    If you need the -extend source option, you can only use the & in the 6th column on the new line. You cannot use the additional one on the previous line.


    If, on the other hand, the code is supposed to be free-form, (you haven't told us!), then you must instruct the compiler by using the -free option.