带有格式换行符的单个Fortran WRITE语句?

问题描述

我希望在Fortran中编写一段文本,其中包含一些故障排除信息,这将需要多行,如下所示:

/!\  Troubleshooting! /!\

Seems your input is not formatted properly!
Accepted keywords are:
value1
value2
value3
value4

一个简单的方法是:

write(*,*)'/!\  Troubleshooting! /!\'
write(*,*)''    
write(*,*)'Seems your input is not formatted properly!'
write(*,*)'Accepted keywords are:'
write(*,*)'value1'
write(*,*)'value2'
write(*,*)'value3'
write(*,*)'value4'

我可以在单个write语句中转储所有文本,这是对的,但这会导致读取时有些混乱!

write(*,'(A)')'/!\  Troubleshooting! /!\    &
Seems your input is not formatted properly! &  
Accepted keywords are:                      &
value1                                      &
value2                                      &
value3                                      &
value4                                      &

像这样!

strelok@Yggdrasil:~$ ./write.exe
/!\  Troubleshooting! /!\     Seems your input is not formatted properly! Accepted keywords are:                       value1                                      value2                                      value3                                      value4

但是我希望更多……有趣!确实,我希望文本中的单个WRITE语句具有一些换行符(而无需编写新的WRITE语句!),因此可以通过多种方式以“格式化”方式生成它!

有什么建议吗?

解决方法

您可以插入new_line('A')字符,请参见https://gcc.gnu.org/onlinedocs/gfortran/NEW_005fLINE.html

write(*,'(A)')'/!\  Troubleshooting! /!\//new_line('A')//&
Seems your input is not formatted properly!//new_line('A')//&  
...