2

統合プログラムを作成するために、FORTRAN での書き込みに関する書籍や PDF を参照してきました。コードを gfortran でコンパイルすると、次のエラーのコピーがいくつか表示されます。

1)Unexpected data declaration statement at (1)
2)Unterminated character constant beginning at (1)
3)Unclassifiable statement at (1)
4)Unexpected STATEMENT FUNCTION statement at (1)
5)Expecting END PROGRAM statement at (1)
6)Syntax error in data declaration at (1)
7)Statement function at (1) is recursive
8)Unexpected IMPLICIT NONE statement at (1)

私はそれらが本当に意味することやそれらを修正する方法を知りません.Google検索はnullであることが証明されており、このサイトの他のトピックは他のエラーについてです. エラー 5 の場合) C++ のように Program main と end program main を挿入しましたが、それでも同じ結果が得られました。エラー 7) は意味がありません。プログラムで再帰を試みています。エラー 8) i read implicit none は不要な減速を防ぐためのものでした。

コード自体を投稿しますが、配列データ処理を微調整する必要があるため、コンパイルエラーにもっと興味がありますが、動作するまでそれを行うことはできません。

         Program main
  implicit none      
  real, dimension(:,:), allocatable :: m, oldm
  real a
  integer io, nn
  character(30) :: filename
  real, dimension(:,:), allocatable :: alt, temp, nue, oxy
  integer locationa, locationt, locationn, locationo, i
  integer nend
  real dz, z, integral
  real alti, tempi, nuei, oxyi
  integer y, j

  allocate( m(0, 0) ) ! size zero to start with?

  nn = 0
  j = 0

   write(*,*) 'Enter input file name: '

   read(*,*) filename

   open( 1, file = filename )



  do !reading in data file

   read(1, *, iostat = io) a

   if (io < 0 ) exit

   nn = nn + 1

   allocate( oldm( size(m), size(m) ) )

   oldm = m 

   deallocate( m )

   allocate( m(nn, nn) )

   m = oldm

   m(nn, nn) = a ! The nnth value of m

   deallocate( oldm )

  enddo



  ! Decompose matrix array m into column arrays [1,n]

  write(*,*) 'Enter Column Number for Altitude'
  read(*,*) locationa
  write(*,*) 'Enter Column Number for Temperature'
  read(*,*) locationt
  write(*,*) 'Enter Column Number for Nuetral Density'
  read(*,*) locationn 
  write(*,*) 'Enter Column Number for Oxygen density'
  read(*,*) locationo

  nend = size(m, locationa) !length of column #locationa

  do i = 1, nend

   alt(i, 1) = m(i, locationa)

   temp(i, 1) = log(m(i, locationt))

   nue(i, 1) = log(m(i, locationn))

   oxy(i, 1) = log(m(i, locationo))

  enddo



  ! Interpolate Column arrays, Constant X value will be array ALT with the 3 other arrays

  !real dz = size(alt)/100, z, integral = 0
  !real alti, tempi, nuei, oxyi
  !integer y, j = 0
  dz = size(alt)/100


  do z = 1, 100, dz
  y = z !with chopped rounding alt(y) will always be lowest integer for smooth transition.
  alti = alt(y, 1) + j*dz ! the addition of j*dz's allow for all values not in the array between two points of the array. 

   tempi = exp(linear_interpolation(alt, temp, size(alt), alti))

   nuei = exp(linear_interpolation(alt, nue, size(alt), alti))

   oxyi = exp(linear_interpolation(alt, oxy, size(alt), alti))
   j = j + 1



   !Integration

   integral = integral + tempi*nuei*oxyi*dz 

  enddo


  end program main


  !Functions

  real function linear_interpolation(x, y, n, x0)

   implicit none

   integer :: n, i, k

   real :: x(n), y(n), x0, y0

   k = 0


  do i = 1, n-1

   if ((x0 >= x(i)) .and. (x0 <= x(i+1))) then  

    k = i ! k is the index where: x(k) <= x <= x(k+1)
    exit ! exit loop

   end if

  enddo


  if (k > 0) then  ! compute the interpolated value for a point not in the array

   y0 = y(k) + (y(k+1)-y(k))/(x(k+1)-x(k))*(x0-x(k))

  else

   write(*,*)'Error computing the interpolation !!!'

   write(*,*) 'x0 =',x0, ' is out of range <', x(1),',',x(n),'>'

  end if

  ! return value

     linear_interpolation = y0

  end function linear_interpolation

正確なエラーのより詳細な説明を提供できます。各タイプがいくつかあるため、エラー名で十分であることを願っていました。

4

1 に答える 1

0

コード サンプルにいくつかの重大なエラーを見つけることができると思います。構文エラーは、exp(...ステートメント内の括弧のバランスが取れていないことです。それらは次のようになります。

tempi = exp(linear_interpolation(alt, temp, size(alt), alti) ) ! <- extra ")"
nuei = exp(linear_interpolation(alt, nue, size(alt), alti) )
oxyi = exp(linear_interpolation(alt, oxy, size(alt), alti) )

あなたが得ているような紛らわしいエラーの長い文字列を生成できるのは、まさにこのようなものです。したがって、Dave と Jonathan が与えたアドバイスは何度も繰り返すことはできません。

別のエラー (「分類できないステートメント」) がループに適用されます。

do(i=1, nend)
! ...
do(z=1, 100, dz)
! ...

これらは括弧なしで記述する必要があります。

「データ宣言エラー」は、次のような複数の変数を宣言して初期化しようとしたことに起因します

real dz = size(alt)/100, z, integral = 0

(前述のように) コード内での位置が正しくないことに加えて、これは二重のコロン区切り記号でのみ行うことができます。

real :: dz = size(alt)/100, z, integral = 0

個人的には、常にこのような宣言を書くことをお勧めします。saveただし、このように変数を初期化すると、暗黙的に属性が与えられるという副作用があることに注意する必要があります。これはメインプログラムには影響しませんが、知っておくことは重要です。初期化を別の行に置くことで回避できます。

于 2012-11-14T15:56:25.690 に答える