Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

fortran - gfortran error: unexpected element '' in format string at (1)

I have a project written in VS2010 with Intel Visual Fortran. I have a dump subroutine to write a 2D matrix into file:

subroutine Dump2D(Name,Nx,Ny,Res)
    implicit none
    integer i,j,Nx,Ny
    real(8) :: Res(Nx,Ny)
    character(len=30) name,Filename
    logical alive
    write(filename,*) trim(Name),".dat"
    Write(*,*) "Saving ",trim(Name)," Please wait..."
    open (10,file=filename)
    do i=1,Ny
           Write(10,FMt="(D21.13)")   (Res(j,i),j=1,Nx)
           Write(10,*)  
    end do
    close(10)
    Write(*,*) "Save ",trim(Name),"Complete!"  
    return
end subroutine Dump2D

It is ok to compile and run. But when I compile in emacs using gfortran it gives me the error:

I think it's because the gfortran doesn't recognize in a format for a write command. How do I fix this problem?

                Write(10,FMt="(D21.13)") (Res(j,i),j=1,Nx)
                                   1
Error: Unexpected element '' in format string at (1)
See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

The edit descriptor relates to backslash editing. This is a non-standard extension provided by the Intel compiler (and perhaps others). It is not supported by gfortran.

Such backslash editing is intended to affect carriage control. Much as in this answer such an effect can be handled with the (standard) non-advancing output.1

As you simply want to output each column of a matrix to a record/line you needn't bother with this effort.2 Instead (as you'll see in many other questions):

do i=1,Ny
   write(10,fmt="(*(D21.13))") Res(:,i)
end do

There are also other approaches which a more general search will find.


1 The Intel compiler treats and $ in the same way.

2 There are subtle aspects of , but I'll assume you don't care about those.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...