【发布时间】:2012-05-09 10:25:14
【问题描述】:
我尝试实现一个读取数字 n 的代码,创建一个向量来存储 n 个双精度数字,读取这个数字,调用一个子程序 printminmax() 来找到最小值和最大值。我的代码非常适合普通数字(整数、实数等),但是当我有科学记数法(0.3412E+01)堆栈时。为什么?我想用 * 阅读所有格式。谢谢
implicit none
integer, dimension(:), allocatable :: x
integer :: n
open (unit=77, file='input2.dat', action='read', status='old')
read(77,*), n
allocate(x(n))
call printminmax(n)
deallocate(x)
end
subroutine printminmax(y)
implicit none
integer, dimension(:), allocatable :: x
integer :: y,max,min,i
allocate(x(y))
read(77,*) x
!print *,'Maximun=', maxval(x)
!print *,'Minimun=', minval(x
!initialize the value max & min
max=x(1)
min=x(1)
do i=2,y
if (x(i)>max) max=x(i)
if (x(i)<min) min=x(i)
end do
write(*,*) 'Maximum=',max
write(*,*) 'Minimum=',min
end subroutine printminmax
堆栈输入的一个例子是
1000
5.39524398466520e-01
9.85099770130787e-01
7.38946122872518e-01
6.47771620257608e-01
8.80871051119695e-01
2.99375585725816e-02
我认为科学记数法的错误是
At line 13 of file io.f90 (unit = 77, file = 'input3.dat')
Fortran runtime error: Bad integer for item 1 in list input
【问题讨论】:
-
对不起!第一行有一个整数。这个数字是 1000
-
据我了解的问题在于 read()
标签: arrays io fortran fortran90