Fortran variadic宏中的CPP / GPP(加上Fortran //串联) [英] CPP/GPP in Fortran variadic macro (plus Fortran // concatenation)

查看:204
本文介绍了Fortran variadic宏中的CPP / GPP(加上Fortran //串联)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译一个巨大的,世界闻名的数值天气预报代码 - 大部分都是在Fortran 90编写的 - 广泛地使用了 cpp ,并成功地与PGI,Intel和gfortran一起使用。现在,我继承了一个专家已经添加了几百个可变宏的例子。他们使用英特尔和 fpp ,这大概是更多以Fortran为中心的,并且可以全部运行。我需要使用gfortran,并且无法使用它的新增功能来使用 cpp 处理此代码。



简化了问题如下 -



预处理代码:

  PRINT *,Hello//Don
#define adderv(...)(myadd(__ VA_ARGS__))
sumv = adderv(1,2,3,4,5)

不使用 - 传统 cpp >选项将处理可变宏,但不处理Fortran连接:

  $ cpp -P t.F90 
PRINT *,Hello
sumv =(myadd(1,2,3,4,5))


$ b $另一方面,使用 -traditional 标志处理连接,但不处理可变宏:



< pre $ code $ $ ppp -traditional t.F90
t.F90:2:0:错误:宏参数列表中的语法错误
#define adderv(.. 。)(myadd(__ VA_ARGS__))
^
PRINT *,Hello//Don
sumv = adderv(1,2,3,4,5)

我真的很努力地寻找



我已经开始使用 gpp 进行游戏,感觉自己越来越接近了,但是,现实情况是,我可能距离解决方案还有很长的路要走。它不接受 ... ,并且不会展开 __ VA_ARGS __ 。当然,以下几乎不是真正的可变宏...

  PRINT *,Hello// Don
#define adderv()(myadd(__ VA_ARGS__))
sumv = adderv(1,2,3,4,5)



$ gpp t.F90
PRINT *,Hello//Don
sumv =(myadd(__ VA_ARGS__))

我在网上搜索无济于事,迄今为止我看到的最可能的可能性,这可能会让我感到丑陋和痛苦,我将所有Fortran连接运算符分成几行。即

  PRINT *,Hello//Don

变为

  PRINT *,Hello/& 
& /Don

cpp和gpp的内脏对我有点吓人,但如果有人看到成功的可能性,并可能指向正确的方向,我会非常感激。重组这个庞大的代码真的不是一种选择,但是如果我足够迫切的话,一个自动化策略(比如将这些concat操作符分割成不同的行)可能就是这样。






其他信息 - roygvib建议我尝试添加 -C 标志。我们最近一直在压制它,因为它似乎在Fortran代码中引入了很多C注释。那么,我继续努力尝试这一点,我认为我更接近了:

  $ cat t.f90 
PRINT *,Hello//Don
#define adderv(...)(myadd(__ VA_ARGS__))
sumv = adderv(1,2,3,4,5)$ b $当我使用-P和-C标志调用时,它自然会通过C ++(Fortran concat操作符),但是当使用-P和-C标志调用时,它似乎也会生成一些C语言版权文本:

  $ / lib / cpp -P -C t.F90 
/ * Copyright(C)1991-2014 Free Software Foundation,Inc.
本文件是GNU C Library的一部分。



/ * wchar_t使用ISO / IEC 10646(第二版,2011-03-15出版)/ Unicode 6.0。 * /
/ *我们不支持C11< threads.h> ;. * /
PRINT *,Hello//Don
sumv =(myadd(1,2,3,4,5))
pre>

一点研究(删除由cpp生成的评论)表明,这种版权的添加可能是cpp的一个相对较新的功能。



我可以'没有看到任何简单的方法来抑制这一点,所以我想我可能需要构建一个如上所述调用cpp的包装脚本(例如 mycpp ),过滤掉任何C风格的注释,然后传递到下一个阶段。

这不是最佳的,我有点吝啬,因为整个软件包还包含C代码。但理论上讲,我认为最糟糕的情况是未能在预处理的C代码中生成注释。



如果有人知道如何简单地抑制这个版权信息的生成,我可能是在做生意。

至少在下面描述的简单示例的上下文中,我通过安装旧的cpp解决了这个问题。 其他研究已确认版本4.8插入了额外的C评论转换为预处理的Fortran代码,这显然不是一件好事。这个解决方案很简单,使用cpp-4.7。

安装(在Ubuntu 16.04上)比我预想的要简单得多。一个简单的
$ b $ pre $ $ $ c $ sudo apt-get install cpp-4.7
将必要的可执行文件放在/ usr / bin / cpp- 4.7

,并按照我的需要预处理以下示例。

  $ /usr/bin/cpp-4.7 -C -P t.F90 
PRINT *,Hello//Don
sum =(myadd(1,2,3,4,5))


I'm trying to compile a huge, world-renowned numerical weather prediction code - written mostly in Fortran 90 - that uses cpp extensively, and successfully, with PGI, Intel and gfortran. Now, I've inherited a version where experts have added several hundred cases of variadic macros. They use Intel and fpp, which is presumably a little more Fortran-centric, and can get it all to work. I need to use gfortran, and have not been able to get cpp to work on this code with its new additions.

A gross simplification of the problem is as follows -

Code to preprocess:

    PRINT *, "Hello" // "Don"
#define adderv(...) (myadd(__VA_ARGS__))
    sumv = adderv(1, 2, 3, 4, 5)

Using cpp without the -traditional option will handle the variadic macro, but not the Fortran concatenation:

$ cpp -P t.F90
    PRINT *, "Hello"
    sumv = (myadd(1, 2, 3, 4, 5))

On the other hand, using the -traditional flag handles the concatenation, but not the variadic macro:

$ cpp -P -traditional t.F90 
t.F90:2:0: error: syntax error in macro parameter list
 #define adderv(...) (myadd(__VA_ARGS__))
 ^
    PRINT *, "Hello" // "Don"
    sumv = adderv(1, 2, 3, 4, 5)

I'm really struggling to find a way to facilitate the processing of both.

I've started by playing with gpp, and feel like I'm getting close, but the reality is I might still be a long way from a solution. It doesn't accept the ... and, it doesn't expand __VA_ARGS__. Of course, the following isn't really a variadic macro any more...

    PRINT *, "Hello" // "Don"
#define adderv() (myadd(__VA_ARGS__))
    sumv = adderv(1, 2, 3, 4, 5)



$ gpp t.F90
    PRINT *, "Hello" // "Don"
    sumv = (myadd(__VA_ARGS__))

I've scoured the web to no avail, and the best possibility I've seen so far, which strikes me as possibly ugly and painful, is to split all my Fortran concatenation operators into separate lines. i.e.

PRINT *, "Hello" // "Don"

becomes

PRINT *, "Hello" /&
&              / "Don"

The innards of cpp and gpp are a bit intimidating to me, but if anybody sees the potential for success and might point me in the right direction, I'd be very appreciative. Restructuring this huge code really isn't an option, though an automated strategy (such as splitting those concat operators into separate lines) might be, if I'm desperate enough.


Additional information - roygvib suggested I try adding the -C flag. We had been suppressing it lately because it seemed to introduce many C comments into the Fortran code. Well, I went ahead and tried this, and I think I'm closer:

$ cat t.f90
        PRINT *, "Hello" // "Don"
    #define adderv(...) (myadd(__VA_ARGS__))
        sumv = adderv(1, 2, 3, 4, 5)

When I invoke with -P and -C flags, naturally it passes through the C++ (Fortran concat operator), but it also seems to generate some C-commented copyright text:

   $ /lib/cpp -P -C  t.F90
   /* Copyright (C) 1991-2014 Free Software Foundation, Inc.
      This file is part of the GNU C Library.
   .
   .
   .
   /* wchar_t uses ISO/IEC 10646 (2nd ed., published 2011-03-15) /       Unicode 6.0.  */
   /* We do not support C11 <threads.h>.  */
       PRINT *, "Hello" // "Don"
       sumv = (myadd(1, 2, 3, 4, 5))

A little bit of research ( Remove the comments generated by cpp ) is suggesting that this addition of the copyright may be a relatively new "feature" of cpp.

I can't see any simple way to suppress this, so I'm thinking I may need to build a wrapper script (e.g. mycpp) that calls cpp as above, filters out any C-style comments, then passes that to the next stage.

It's not optimal, and I'm a little leery because this whole package also has C code in it. Theoretically, though, I think that the worst thing that would happen would be failure to generate comments in preprocessed C code.

If anybody has knowledge as to how I might simply suppress the generation of that copyright message, I might be in business.

解决方案

At least in the context of the simple example described below, I resolved the problem by installing an older cpp. Other research had confirmed that version 4.8 was inserting additional C comments into preprocessed Fortran code, which obviously isn't a good thing. The solution was simple, use cpp-4.7.

Installation (on Ubuntu 16.04) was more straightforward than I had anticipated. A simple

sudo apt-get install cpp-4.7
put the necessary executable in /usr/bin/cpp-4.7

and that preprocesses the following examples the way I want.

$ /usr/bin/cpp-4.7 -C -P t.F90
    PRINT *, "Hello" // "Don"
    sum = (myadd(1, 2, 3, 4, 5))  

这篇关于Fortran variadic宏中的CPP / GPP(加上Fortran //串联)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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