用F描述符读取浮点数据 [英] Read a floating point data with F descriptor

查看:62
本文介绍了用F描述符读取浮点数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下格式的数据文件:

I have a data file in the following format:

   76     1               28.19345173               20.57121917               21.66248682
   77     1               30.48106325               37.84001977               19.95790222
   78     1               30.49966847                        38               20.68928893
   79     1               1.246861056              0.6998957711               34.74201206

我需要对此数据文件进行一些操作.因此,我开始编写代码以读取数据文件的最后4列.这是我用来读取所需信息并将其写入新文件的格式:

I need to do some manipulation on this data file. Thus, I started writing a code to read the 4 last columns of the data file. Here is the format I used to read the wanted information and write it in a new file:

阅读格式:

  format(21x,f16.11,10x,f16.11,10x,f16.11)

写作格式:

format(A1,1x,f16.11,5x,f16.11,5x,f16.11)

A1自动设置为1的情况. 我的代码的输出是:

Where A1 is automatically set to 1. The output of my code is :

1   28.19345173000       20.57121917000       21.66248682000
1   30.48106325000       37.84001977000       19.95790222000
1   30.49966847000        0.00000000038       20.68928893000
1    1.24686105600        0.69989577110       34.74201206000

您可以很容易地看到我的问题是第三行中的那个38被读取并写入为0.00000000038.谁能帮助我确定解决问题的最佳方法?

As you can easily see my problem is with that 38 in the third row which is read and written as 0.00000000038. Can anyone kindly help me to figure what the best way is to solve the problem?

推荐答案

在我看来,在F编辑描述符中没有地方可以使用非零输入.对于输出而言,控制小数位数很有用,但对输入有害.

In my opinion there is no place for using nonzero in the F edit descriptor for input. For output it is useful to control the number of decimal places, but it is harmful for input.

正如francescalus在其答案中所示,(c3>)中的d值导致没有小数点的文字被解释为按10 ^ d缩放.

As francescalus shows in his answer, the d in (Fw.d) value causes literals without a decimal symbols to be interpretted as scaled by 10^d.

解决方案是仅使用F16.0而不是F16.11.非零d部分是完全不必要和有害的.只是有一些奇怪的用例,但是您在这里没有它们.

The solution is to just use F16.0 and not F16.11. Nonzero d part is completely unnecessary and harmful. There are just some strange use cases for it, but you don't have them here.

这篇关于用F描述符读取浮点数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆