What is this error in fortran and how to stop the program when it occurs? -


i have program reads information input file. since code has nothing wrong, can compiled. question if there reading error, program still running not thing when program gets larger , hard me find out error occurs.

the program is:

program main  implicit none  integer ioerr, switch_1(3), switch_2,     open(100, file='./input_error.gr', action='read', iostat=ioerr)    if (ioerr == 0)      read(100,*) (switch_1(i), i=1,3)      write(*,*) 'switch_1 is: ', switch_1      read(100,*) switch_2      write(*,*) 'switch_2 is: ', switch_2    else      write(*,*) 'file not read'    end if  end program main 

and input file is:

1,2,3 3 

and works fine. if input file is:

1,2 

i reading error don't know , want program stop every time error occurs, , if possible gives me error message did file opening:

forrtl: severe (24): end-of-file during read, unit 100, file /users/ranranking/develop/test/switch_test/./input_error.gr image              pc                routine            line        source a.out              0000000107d1114e  unknown               unknown  unknown a.out              0000000107d2d686  unknown               unknown  unknown a.out              0000000107d2b7d4  unknown               unknown  unknown a.out              0000000107cfaa30  unknown               unknown  unknown a.out              0000000107cfa91e  unknown               unknown  unknown 

your program reached end of file. can use return code identify end-of-file condition , respond within program. code fragment show approach:

   use, intrinsic :: iso_fortran_env     .....     readfile:        read (data_lun, '(a)', iostat=readcode)  line        if ( readcode /= 0 )          if ( readcode == iostat_end )             write (*, *) "end of file"             exit readfile    ! end of file -- exit read loop          else             write ( *, '( / "error reading data file: ", i0 )' )  readcode             stop          end if       end if        read (line, *) .....        ......     end readfile 

Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -