我需要在fortran 2003/2008中为我的分子动力学代码实现链接列表数据结构我正在使用最新的fortran编译器(英特尔).
我如何以尽可能最好的方式实现链表,如果可能的话,我希望在Fortran中实现无锁无等待实现.
谢谢.
我正在尝试使用Fortan90验证目录是否存在.在我发现的各种网站上:
logical :: dir_e
inquire(file='./docs/.', exist=dir_e)
if ( dir_e ) then
write(*,*) "dir exists!"
else
! workaround: it calls an extern program...
call system('mkdir docs')
end if
Run Code Online (Sandbox Code Playgroud)
但是,inquire返回False目录是否存在,如果我执行此代码两次,我收到一条错误消息
无法制作dir,文件已经存在
如果我使用:
inquire(file='./docs/test', exist=dir_e)
Run Code Online (Sandbox Code Playgroud)
使用现有文件测试,inquire返回true.
如何检查目录的存在?我正在使用ubuntu 11.04和ifort编译器.
这个Fortran代码的含义是什么:
IF (J1-3) 20, 20, 21
21 J1 = J1 - 3
20 IF (J2-3) 22, 22, 23
23 J2 = J2 - 3
22 CONTINUE
Run Code Online (Sandbox Code Playgroud)
我在旧项目中看到过,我不知道带有数字(标签)的IF是什么意思.
我需要在Fortran 90中将一些数据写入文件.我应该如何使用列WRITE (*,*) input分组的值?总是在每次通话后放一个,这就是问题所在.WRITEnew line
代码示例:
open (unit = 4, file = 'generated_trajectories1.dat', form='formatted')
do time_nr=0, N
write (4,*) dble(time_nr)*dt, initial_traj(time_nr)
end do
Run Code Online (Sandbox Code Playgroud)
现在重点是将它写在不同的列中.
这很好用:
program main
integer,parameter,dimension(3) :: x = [1,2,3]
print*,x
end program main
Run Code Online (Sandbox Code Playgroud)
就像这样:
program main
integer,parameter,dimension(3) :: x = (/1,2,3/)
print*,x
end program main
Run Code Online (Sandbox Code Playgroud)
是否有理由认为一种形式应优先于另一种形式(例如向后兼容性)?
我在Fortran90程序中有以下数据结构:
TYPE derivedType
CHARACTER(100) :: name = ' '
INTEGER :: type = 0
REAL(KIND(1.0D0)) :: property = 0.0
END TYPE derivedType
TYPE (derivedType), ALLOCATABLE, DIMENSION(:) :: arrayOfDerivedTypes
Run Code Online (Sandbox Code Playgroud)
当我尝试在GDB中调试和打印值时:
(gdb) p arrayOfDerivedTypes(1)%name
Run Code Online (Sandbox Code Playgroud)
我得到非敏感值(通常为零,正斜杠和字母串)或完全错误的值(如arrayOfDerivedTypes(1)%name = 9,当我知道它是= 2时).如何让GDB打印正确的值?
我知道:
我不想经历编译GDB的单独分支以测试它是否解决了这个问题的麻烦,如果有人已经知道它不会或者是否有更好的解决方案可用.
我很难想象还没有解决方案.fortran社区没有更好的免费调试器解决方案吗?
我开发了一个Fortran代码,它具有以下特征:
代码变得非常大.尽管在这个阶段我试图得到正确的答案,但仍需要执行代码的速度.
我正在编写带有标签的文本日志文件,例如ERROR: message或者INFO: message到目前为止.但是写太多信息会减慢代码的速度.我知道在Java开发中我们使用log4j库来高效地编写日志文件,我们可以打开或关闭各种级别的日志记录.因此,一旦代码干净,我们就可以关闭低级日志并保留高级日志.
我想知道其他程序员在Fortran 90+中处理这个问题的最佳方法是什么.
我在我的Ubuntu 15.04系统上安装了gfortran.在编译Fortran代码时,DO循环仅要求获取整数参数,而不是实数值或变量.这包括循环变量和步骤表达式.为什么它也不能采取真正的价值观呢?
以下是从这里开始的程序,练习3.5的嵌套do循环部分.
program xytab
implicit none
!constructs a table of z=x/y for values of x from 1 to 2 and
!y from 1 to 4 in steps of .5
real :: x, y, z
print *, ' x y z'
do x = 1,2
do y = 1,4,0.5
z = x/y
print *, x,y,z
end do
end do
end program xytab
Run Code Online (Sandbox Code Playgroud)
编译后显示的错误是:
xytab.f95:8.4:
do y = 1,4,0.5
1
Warning: Deleted feature: Loop variable at (1) …Run Code Online (Sandbox Code Playgroud) 我不熟悉导致以下警告的原因:
warning #5117: Bad # preprocessor line
#include "rtt_alloc_rad.interface"
Run Code Online (Sandbox Code Playgroud)
我已经看过一些明显的问题,比如#include左边是红色的.我想知道在哪里寻找可能的原因的一些提示.
我正在使用英特尔编译器:ifort版本15.0.1
该代码具有与外部库相关联的大型气候模型.很难知道要发布什么,但警告来自以下代码段:
MODULE rtt_interface
use rtt_types, only : rtt_options, rtt_coefs, profile_Type, &
transmission_Type, radiance_Type,rtt_coef_scatt_ir,rtt_optpar_ir, &
rtt_chanprof, rtt_emissivity, rtt_reflectance
use rtt_const, only : errorstatus_success, errorstatus_fatal, &
platform_name,inst_name
use rtt_unix_env, only : rtt_exit
use cosp_kinds, only : wp,wi,wl
IMPLICIT NONE
real(wp), parameter :: tmin_baran = 193.1571_wp
#include "rtt_alloc_rad.interface"
#include "rtt_alloc_transmission.interface"
#include "rtt_alloc_prof.interface"
#include "rtt_dealloc_coefs.interface"
#include "rtt_direct.interface"
#include "rtt_print_opts.interface"
! snip...
END MODULE rtt_interface
Run Code Online (Sandbox Code Playgroud)
我用标志编译: f90flags=-g -fp-model precise -traceback -r8 -O0
如何将字符串格式化为具有恒定宽度并左对齐?有Aw格式化程序,其中w表示所需的字符输出宽度,但它会在 if 前面添加空格w > len(characters),而不是附加它们。
当我尝试时
44 format(A15)
print 44, 'Hi Stack Overflow'
Run Code Online (Sandbox Code Playgroud)
我明白了
> Hi Stack Overflow<
Run Code Online (Sandbox Code Playgroud)
代替
>Hi Stack Overflow <
Run Code Online (Sandbox Code Playgroud)
有没有简单的 Fortran 格式化解决方案可以解决这个问题?
fortran ×10
fortran90 ×10
gfortran ×2
file-io ×1
formatting ×1
fortran95 ×1
gdb ×1
linked-list ×1