专业的Fortran代码开发:创建日志文件 [英] Professional Fortran code development: Log file creation

查看:155
本文介绍了专业的Fortran代码开发:创建日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个具有以下特征的Fortran代码:


  1. 全局变量

  2. 具有多个子例程的模块

  3. 独立的子例程

  4. 使用用于LAPACK库(线性代数)的英特尔MKL库

  5. 阅读和编写文本文件

代码变得相当大。尽管在这个阶段我正在尝试得到正确的答案,但代码的执行速度仍然是需要的。

我正在写一个文本日志文件,其中包含 ERROR:message INFO :message 到目前为止。但是编写太多的信息会减慢代码的速度。我知道在Java开发中,我们使用log4j库来有效地编写日志文件,以便我们可以打开或关闭各种日志记录级别。因此,一旦代码清理完毕,我们可以关闭低级日志并保持高级日志。



我想从其他程序员那里了解最好的方法在Fortran 90 +中处理这个问题。

解决方案

我正在使用以下预处理器宏完成此任务(在<$ c
$ b

  #ifdef DEBUG 
#define DWRITE write (*,*)__FILE __,__ LINE__,
#define dwrite write(*,*)__FILE __,__ LINE__,
#else
#define DWRITE!
#define dwrite!
#endif

在我的代码中,我有以下头文件:

  #define DEBUG 
#includeMACROS.h

...

dwrite'发生了一个错误!'

这给出了我的文件和错误发生的地方,并通过评论第一行,我可以轻松地打开/关闭消息。



您可以轻松地将其扩展到不同的调试级别并写入文件...

I have developed a Fortran code which has the following characteristics:

  1. Global variables
  2. 13 Modules with multiple subroutines
  3. Independent subroutines
  4. Using Intel MKL library for LAPACK libraries (Linear Algebra)
  5. Reading and writing text files

The code has become quite big. Even though at this stage I am trying to get the correct answer, speed of execution of the code is desired.

I was writing a text log file with tags such as ERROR: message or INFO: message so far. But writing too much information slows down the code. I know in Java development we use log4j library to efficiently write log files where we can switch on or off various levels of logging. So once the code is clean, we can switch off low level logs and just keep the high level logs.

I would like to know from other programmers what is the best way to handle this in Fortran 90+.

解决方案

I'm using the following preprocessor macros for exactly this task (inside MACROS.h):

#ifdef DEBUG
#define DWRITE write(*,*) __FILE__,__LINE__,
#define dwrite write(*,*) __FILE__,__LINE__,
#else
#define DWRITE ! 
#define dwrite ! 
#endif

In my code I then have the following header:

#define DEBUG
#include "MACROS.h"

...

dwrite 'An error occurred!'

This gives my the file and the line where the error occurred, and by commenting the first line I can easily switch the message on/off.

You could easily extend this to different debug levels and writing to files...

这篇关于专业的Fortran代码开发:创建日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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