问题描述
没有格式化我的输出,这就是我所做的(在一个循环内部,所以这发生了几次):
$ $ p $ $ $ $ $ $ $ $ $ $ $ $ $ $ >
现在,我尝试添加一个格式语句: 和(与其他一切相同),而我得到只有星号在我的输出: 我试着读到这应该如何工作,我不明白为什么会发生这种情况。我已经尝试格式更多的空间数字( 我在这里错过了什么? 见 另外,我应该提及星号表示数字不能以所述格式显示。 / b> 编辑: 在下面的george中添加注释: I'm having a hard time wrapping my head around formatting statements in Fortran. Without formatting my output, this is what I do (inside a loop, so this happens a few times): Now, I try to add a format statement: and (with everything else the same) instead I get only asterisks in my output: I've tried to read up on how this should work, and I can't figure out why this is happening. I've tried formats with more space for digits ( What am I missing here? Fortran format statements are defined as: See http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap05/format.html Also, I should mention that the asterisks are indicative that the number cannot be displayed in the format stated. EDIT: Adding in the comment from george below: "For E format the fieldwidth has to be at least 7 more than the number of decimals, eg E15.8. Four for the exponent, two for the lead 0. one for a possible '-'. I usually add one more extra space so numbers don't run together, E16.8" 这篇关于Fortran将我的输出输出为星号 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! t
这里是 real * 8
。输出正是我所期望的 - 增量为0.1,有一些舍入误差:
$ $ $ $ $ $ $ $ $ $ 0.10000000000000001 $
0.20000000000000001
0.29999999999999999
0.40000000000000002
0.50000000000000000
0.59999999999999998
0.69999999999999996
0.79999999999999993
0.89999999999999991
0.99999999999999989
write(*,'(F1.2)')t * 1E9
**
**
(etc ...)
F15.15
只是给了我更多的星号每行),我试着将格式声明移动到自己的标签行...我只是不能得到我想要的输出。
写(*,'(F4.3)')t * 1E9
对于E格式,字段宽度必须至少比小数位数多7,例如E15.8,四位指数,两位数字,一位用于可能的 - 。一个额外的空间,所以数字不会一起运行,E16.8write(*,*) t*1E9
t
here is real*8
. The output is just what I'd expect - increments of 0.1, with some rounding errors:0.0000000000000000
0.10000000000000001
0.20000000000000001
0.29999999999999999
0.40000000000000002
0.50000000000000000
0.59999999999999998
0.69999999999999996
0.79999999999999993
0.89999999999999991
0.99999999999999989
write(*, '(F1.2)') t*1E9
**
**
(etc...)
F15.15
just gives me more asterisks per line), I've tried moving the format statement to its own, labelled line... I just can't seem to get the output I'd like.Fw.d
, where w is the number of characters to be used in total, and d is the number of characters after the decimal point. Here you are telling it that you need a float, that is 1 character wide in total, and 2 characters after the decimal point, something that is obviously not correct. So to get, for example, a float that is 4 characters in total, with 3 decimal places, you'd write:write(*, '(F4.3)') t*1E9