Fortran 90中的阅读格式

时间:2012-09-10 15:08:47

标签: format fortran

我有一个巨大的文件要读取其结构:

 [...]
 (0,0,0,0,0): 5.00634e-33, 5.59393e-33, 6.24691e-33, 7.29338e-33,
 (0,0,0,0,4): 7.77607e-33, 8.95879e-33, 9.65316e-33, 1.07434e-32,
 (0,0,0,0,8): 1.20824e-32, 1.34983e-32, 1.49877e-32, 1.73061e-32,
 (0,0,0,0,12): 1.919e-32, 2.15391e-32, 2.3996e-32, 2.67899e-32,
 [...]

我有兴趣阅读“:”之后的值,如果我使用Fortran90,我应该在read语句中使用format吗?

我试过

 read(1,'("(",I6,",",I6,",",I6,",",I6,",",I6,"):",F10.4,F10.4,F10.4,F10.4)')idx1,idx2,idx3,idx4,idx5,dummy1,dummy2,dummy3,dummy4

但我得到了forrtl: severe (64): input conversion error

1 个答案:

答案 0 :(得分:10)

由于项目似乎没有按列排列,因此格式很棘手。我会这样接近它:

read (55, '(A)')  string
colon_pos = index (string, ":")
read (string (colon_pos+1:len_string), * ) real1, real2, real3, real4

将每一行读入一个字符串,找到冒号,然后使用list-directed IO处理冒号后字符串中的数值。