Fortran中的常量值

时间:2014-11-01 22:23:59

标签: input fortran

我有一个输入文件来读取值,其中一个值为1d10

如何理解这个价值?

输入文件位于下方,LU用于LU分解:

8000   8000    8000    1d10               120  120    8

以上变量是:

min_n   max_n    stepsize  total_flops_in_timing_block   blower  bupper  bstride

1 个答案:

答案 0 :(得分:3)

假设所有这些值都是除flops变量之外的整数,则此示例代码将起作用。另请注意,这取决于输入文件的固定宽度以及由单个空格分隔的值。如果您有更多一般需求,则需要进行调整才能发挥作用。

program test
implicit none
  integer :: n_min, n_max, n_step, b_low, b_high, b_stride
  integer :: ufile
  real(kind=kind(1d0)) :: flops
  open(newunit=ufile, file="input2.txt", access="sequential")
  read(ufile,*) n_min, n_max, n_step, flops, b_low, b_high, b_stride
  close(ufile)
  print *, "min_n = ", n_min
  print *, "max_n = ", n_max
  print *, "stepsize = ", n_step  
  print *, "flops = ", flops
  print *, "blower = ",b_low
  print *, "bupper = ", b_high
  print *, "bstride = ", b_stride
end program test

给定输入文件:

8000 8000 8000 1d10 120 120 8

生成此输出:

% ./read_input 
 min_n =         8000
 max_n =         8000
 stepsize =         8000
 flops =    10000000000.000000     
 blower =          120
 bupper =          120
 bstride =            8