gfortran错误:格式字符串中出现意外元素'\'(1) [英] gfortran error: unexpected element '\' in format string at (1)

查看:1188
本文介绍了gfortran错误:格式字符串中出现意外元素'\'(1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用英特尔Visual Fortran编写的VS2010项目。我有一个dump子例程来写入一个2D矩阵到文件中:

pre $子程序Dump2D(Name,Nx,Ny,Res)
隐式无
整数i,j,Nx,Ny
real(8):: Res(Nx,Ny)
字符(len = 30)名称,文件名
逻辑(*,*)保存,修剪(名称),请稍候...
写入(文件名,*)修剪(名称),。dat
写入open(10,file = filename)
do i = 1,Ny
写(10,FMt =(D21.13 \))(Res(j,i),j = 1, Nx)
Write(10,*)
end do
close(10)
写入(*,*)保存,修剪(名称),完成!
返回
结束子程序Dump2D

可以编译并运行。但是,当我使用gfortran编译emacs时,它给了我错误:



我认为这是因为gfortran不能识别 \ 以写入命令的格式存储。如何解决这个问题?

 写(10,FMt =(D21.13 \))(Res j,i),j = 1,Nx)
1
错误:格式字符串中出现意外元素'\'(1)

解决方案

编辑描述符 \ 反斜杠编辑。这是英特尔编译器提供的非标准扩展程序 (也可能是其他的)。它不被gfortran支持。



这种反斜杠编辑旨在影响托架控制。就像在这个答案中一样,这种效果可以用(标准)非提前输出来处理。 1



因为您只是想将矩阵的每一列输出到记录/行中,您不必费心去做这项工作。 2 (你会在其他许多问题中看到):

$ $ $ $ $ $ $ $ $ $ $ I $ 1, fmt =(*(D21.13)))Res(:,i)
end do

还有其他一些更常规的搜索会发现的方法。




1 Intel编译器以相同的方式处理 \ $



2 \ 有一些微妙的方面,但我会假设你不关心这些。


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)

解决方案

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.

这篇关于gfortran错误:格式字符串中出现意外元素'\'(1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆