带有格式化换行符的单个 Fortran WRITE 语句? [复制]
Posted
技术标签:
【中文标题】带有格式化换行符的单个 Fortran WRITE 语句? [复制]【英文标题】:Single Fortran WRITE statement with formatted line breaks? [duplicate] 【发布时间】:2020-12-12 20:46:56 【问题描述】:我想用 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(*,'(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 语句!),因此它可以通过多种方式以“格式化”方式产生!
有什么建议吗?
【问题讨论】:
我不记得如何在 FORTRAN 中执行此操作,但在 C 中您可以将 \n 放入 printf 或 putchar 函数中。 en.wikipedia.org/wiki/… 【参考方案1】:您可以插入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')//&
...
【讨论】:
以上是关于带有格式化换行符的单个 Fortran WRITE 语句? [复制]的主要内容,如果未能解决你的问题,请参考以下文章
fortran 怎么避免输出自动换行? 命令是每一行都是四个real*8的数 但是输出时,最后一个数在第二行
fortran中怎样避免输出字符时自动换行。如 print*,"a" print*,''b" 输出时:a b 怎样设计使输出ab