で入力配列ファイル(.dat)の最小値と最大値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()です。 –