在不进行预处理的情况下,通过子例程实现print语句的功能? [英] Achieving the power of the print statement with subroutines without preprocessing?

查看:64
本文介绍了在不进行预处理的情况下,通过子例程实现print语句的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Fortran子例程需要声明所有内容,因此,我们无法轻松编写具有与 print 语句相同的功能和灵活性的自定义打印子例程.

Since Fortran subroutines require everything to be declared, we can't easily write a custom print subroutine with the same power and flexibility as the print statement.

在整个代码中,我们有每个带有多个if语句的print语句,以处理并行处理和选定的调试输出模式.会打印出许多不同类型的具有不同格式的变量,包括带有各自do循环的矩阵.

Throughout the code we have print statements each with multiple if statements to handle the parallel processing and the chosen debug output mode. Many different types of variables with different formats are printed, including matrices with their respective do-loops.

我们只想正常写一个打印语句,除了一个表示其调试模式的整数外,然后找到一种方法来为每个这些语句包括所有适当的if语句.试图通过一个子例程来实现这一点,可以通过一个通用接口来实现,但是需要大量的接口盒来覆盖所有可能的输入方式.而使用预处理替换则要简单得多.我错过了一些有用的东西吗?

We simply want to write a print statement as normal in addition to one integer which represents its debug mode and then find a way to include all of the appropriate if statements for each of these. Trying to achieve this with a subroutine is achievable with a generic interface but requires huge amounts of interface cases covering all of the possible input arrangements. Whereas, this is much more straightforward with preprocessing replacement. Am I missing something majorly useful?

推荐答案

您可能会发现有用的一种设备,使用字符串内部的内部 write ,然后将字符串传递给调试处理子例程,例如:

one device you may find useful, use the intrinsic write internal to a string, then pass the string to your debug-handling subroutine, eg:

    character(len=100) :: string
    ...
    write(string,*)"var1:",var1,"var2:",var2
    call debugout(string,debugflags)

然后在子例程中,您可以进行开关来决定如何处理字符串.

then in the subroutine you can have your switches to decide what to do with the string.

这篇关于在不进行预处理的情况下,通过子例程实现print语句的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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