fortran - 比较 Fortran 输出中的 $ 编辑描述符和 Advance="no"
问题描述
我知道 $ 编辑描述符不在标准中,advance="no"
建议使用,但是这个小例子表明它们有不同的行为(使用 ifort 但不使用 gfortran),我不明白为什么(它不会打扰我不止于此,但如果有人有我感兴趣的解释!)。
program p
use sleep_mod
implicit none
integer :: i
character(len=80) :: mymsg
mymsg = 'H e l l o w o r l d ! W e l c o m e - B i e n v e n u e - W i l l k o m m e n'
!
!- Write the characters of "mymsg" on the same line with a time delay between them:
!
write(*,*)
do i = 1, len_trim(mymsg)
call usleep (onesec/4)
write(*,'(a1,$)') mymsg(i:i) ! ok w/ gfortran, ok w/ ifort
! write(*,'(a1)',advance='no') mymsg(i:i) ! ok w/ gfortran, KO w/ ifort
end do
write(*,'(/)')
end program p
sleep_mod 模块如下:
module sleep_mod
use iso_c_binding
integer(c_int32_t), parameter :: onesec = 100000_c_int32_t
interface ! found in http://computer-programming-forum.com (by Tobias Burnu)
subroutine usleep (useconds) bind(C)
use iso_c_binding
implicit none
integer(c_int32_t), value :: useconds
end subroutine
end interface
end module sleep_mod
使用 $ 版本,无论编译器是什么(ifort 或 gfortran),结果都符合预期:每个字符打印之间的时间延迟。advance='no'
使用 gfortran 而不是使用 ifort 编译的版本获得了相同的结果。
解决方案
推荐阅读
- node.js - 如何在 ElectronJS/NodeJS 中检测可移动驱动器(USB、SD)
- angular - 打字稿中的条件过滤
- python - 为什么我的布尔条件会生成“ValueError:只能比较标记相同的系列对象”?
- php - 数据库列表延迟
- go - 有没有一种简单的方法可以在 Go 程序中编译 Go 代码而无需读取/写入磁盘?
- python - 已达到 Django Celery Max DB 连接数
- python - 使用 Python 将多种文件类型(*.jpg、*.pdf 和 *.tiff)移动到另一个目录
- java - 将字符串解析为公钥时出现问题;无效的密钥格式
- c++ - 如何为函数参数指定任意模板参数?
- javascript - 卡组件无法正常工作