python驱动的fortran预处理器

fypp的Python项目详细描述


https://travis-ci.org/aradi/fypp.svg?branch=develop

fypp是一个python驱动的预处理器。它可以用于任何编程 但是它的主要目的是提供一个fortran预处理器,它有助于 用条件编译和模板元编程扩展fortran 能力。它没有引入自己的表达式语法,而是使用python 在其预处理器指令中的表达式,提供一致性和 python在制定元编程任务时的通用性。它使人坚强 强调健壮性和与开发工具链的完美集成。

项目是hosted on github

Detailed DOCUMENTATION在上可用 readthedocs.org

FYPP是根据bsd 2子句许可证发布的。

主要功能

  • 定义、评估和删除变量:

    #:if DEBUG > 0
      print *, "Some debug information"
    #:endif
    
    #:set LOGLEVEL = 2
    print *, "LOGLEVEL: ${LOGLEVEL}$"
    
    #:del LOGLEVEL
    
  • 宏定义和宏调用:

    #:def assertTrue(cond)
    #:if DEBUG > 0
    if (.not. ${cond}$) then
      print *, "Assert failed in file ${_FILE_}$, line ${_LINE_}$"
      error stop
    end if
    #:endif
    #:enddef assertTrue
    
    ! Invoked via direct call (argument needs no quotation)
    @:assertTrue(size(myArray) > 0)
    
    ! Invoked as Python expression (argument needs quotation)
    $:assertTrue('size(myArray) > 0')
    
  • 条件输出:

    program test
    #:if defined('WITH_MPI')
      use mpi
    #:elif defined('WITH_OPENMP')
      use openmp
    #:else
      use serial
    #:endif
    
  • 迭代输出(例如,用于生成Fortran模板):

    interface myfunc
    #:for dtype in ['real', 'dreal', 'complex', 'dcomplex']
      module procedure myfunc_${dtype}$
    #:endfor
    end interface myfunc
    
  • 内联指令:

    logical, parameter :: hasMpi = #{if defined('MPI')}# .true. #{else}# .false. #{endif}#
    
  • 插入任意python表达式:

    character(*), parameter :: comp_date = "${time.strftime('%Y-%m-%d')}$"
    
  • 预处理期间包含文件:

    #:include "macrodefs.fypp"
    
  • 在预处理器指令中使用Fortran样式的连续行:

    #:if var1 > var2 &
        & or var2 > var4
      print *, "Doing something here"
    #:endif
    
  • 将多行字符串参数传递给可调用项:

    #! Callable needs only string argument
    #:def debug_code(code)
      #:if DEBUG > 0
        $:code
      #:endif
    #:enddef debug_code
    
    #! Pass code block as first positional argument
    #:call debug_code
      if (size(array) > 100) then
        print *, "DEBUG: spuriously large array"
      end if
    #:endcall debug_code
    
    #! Callable needs also non-string argument types
    #:def repeat_code(code, repeat)
      #:for ind in range(repeat)
        $:code
      #:endfor
    #:enddef repeat_code
    
    #! Pass code block as positional argument and 3 as keyword argument "repeat"
    #:call repeat_code(repeat=3)
    this will be repeated 3 times
    #:endcall repeat_code
    
  • 预处理器注释:

    #! This will not show up in the output
    #! Also the newline characters at the end of the lines will be suppressed
    
  • 抑制选定区域中的预处理器输出:

    #! Definitions are read, but no output (e.g. newlines) will be produced
    #:mute
    #:include "macrodefs.fypp"
    #:endmute
    
  • 停止预处理器的显式请求:

    #:if DEBUGLEVEL < 0
      #:stop 'Negative debug level not allowed!'
    #:endif
    
  • 轻松检查宏参数的健全性:

    #:def mymacro(RANK)
      #! Macro only works for RANK 1 and above
      #:assert RANK > 0
      :
    #:enddef mymacro
    
  • 输出中的行号指令:

    program test
    #:if defined('MPI')
    use mpi
    #:endif
    :
    

    转换为

    # 1 "test.fypp" 1
    program test
    # 3 "test.fypp"
    use mpi
    # 5 "test.fypp"
    :
    

    当定义变量MPI并且指示FYPP生成行时 标记。

  • 生成的超过行长度限制的行的自动折叠

安装

fypp需要一个工作的python解释器。它与Python2(版本 2.6及以上版本)和Python3(所有版本)。

自动安装

使用pythons命令行安装程序pip下载stable 从Fypp page on PyPI和 在您的系统上安装:

pip install fypp

这将同时安装命令行工具fypp和python模块 fypp.py。如果要访问 直接从python脚本中获取fypp。

手动安装

对于手动安装,可以下载stable的源代码Fypp project website中释放。

如果希望获得最新的development版本,请克隆项目 存储库:

git clone https://github.com/aradi/fypp.git

并查看master分支。

命令行工具是一个单独的脚本。你可以直接运行它 从源文件夹

FYPP_SOURCE_FOLDER/bin/fypp

或者将它从bin文件夹复制到路径中列出的任何位置之后 环境变量,只需发出

fypp

python模块fypp.py可以在FYP_SOURCE_FOLDER/src中找到。

运行

fypp命令行工具读取文件,对其进行预处理并将其写入 另一个文件,因此通常会像这样调用它:

fypp source.fpp source.f90

它将处理source.fpp并将结果写入source.f90。如果 未指定输入和输出文件,信息从stdin和 写给标准输出。

fypp的行为可以受到各种命令行选项的影响。一个 所有命令行选项的摘要可通过以下方式获得:

fypp -h

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaPax考试:从非标准Maven存储库解析Karaf特性存储库(XML文件)   java Spring启动Bean创建异常   java中将ArrayList转换为数组的方法   Android Studio的java Unity插件。   java在CheckStyle中从方法计数中排除getter和setter   HibernateJava。sql。SQLSyntaxErrorException:表/视图“序列”不存在   与命令行程序Java vs C通信   java WebView膨胀异常   java在O(n)java8流中寻找两个列表的交集   java使用Gradle运行单元测试时,最大堆大小在哪里设置?   ssl加载java应用程序(CXF)内的jks文件   CI:Jenkins Git:Simple Java项目:希望在特定时间在脚本上发送消息   java根据位置更改数字   java按数值排序字符串数组   macos java版本“1.6.0_65”是否与java 6模棱两可?   Cassandra中的java时间戳