Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28445 Discussions

Attempting to read a record with a smaller array length

Alvaro_M_1
Beginner
305 Views

Hi everyone,

I have a very strange problem while reading a previously written file.  I write an unformatted file using the following code

 

!...... SOME PREVIOUS CODE

COMPLEX(KIND=8), ALLOCATABLE, DIMENSION(:,:) :: D

CALL getenv('DIPFILE',file_dip)
 file_dip = TRIM(file_dip)//".V" ! velocity gauge
OPEN(UNIT=iout, FILE=file_dip, STATUS='REPLACE', &
 &  ACCESS='SEQUENTIAL', FORM='UNFORMATTED')


 ALLOCATE ( D(dim_t,dim_t), STAT = istatus )
 IF (istatus /= 0) CALL alloc_error ( ilog, 0, istatus, 'D')

 D=CMPLX(0.0_rk, 0.0_rk)

 DO l = 0, l_max


!   SOME OPERATIONS....


   DO j_st = 1, dim_t

     WRITE(iout)  REAL(D(:,j_st))
     WRITE(iout) AIMAG(D(:,j_st))

   ENDDO


 ENDDO 

 CLOSE(iout)

 

Then, I read the file using another fortran program (using the same compiling options), but this time I don't read the whole record but just a part of it, I'm doing as follows.

 REAL(KIND=8), ALLOCATABLE, DIMENSION(:)     :: D_re, D_im

 ALLOCATE ( D_re(n_Dip), STAT = istatus )    !
 IF (istatus /= 0) CALL alloc_error ( ilog, 0, istatus, 'D_re')
 ALLOCATE ( D_im(n_Dip), STAT = istatus )    !
 IF (istatus /= 0) CALL alloc_error ( ilog, 0, istatus, 'D_im')



!  SOME CODE INTERMEDIATE CODE



   DO l = 0, l_max 
 
 
    n_col = NS_sym(l+1)
    n_row = NS_sym(l+1)
 
 
    i_D = D_sym(l+1, l+1)
 
    
    DO i_col = 1, n_col
 
      READ(idata) D_re(i_D: i_D + n_row - 1)
      READ(idata) D_im(i_D: i_D + n_row - 1)
 
      i_D = i_D + n_row
    
    ENDDO
    
    DO i_col = n_col + 1, dim_r
 
      READ(idata) 
      READ(idata) 
 
    ENDDO
 
 
   ENDDO 
 
   CLOSE(idata)

Now, when I run it I get the error

forrtl: severe (67): input statement requires too much data, unit 10, file "test"

The strange thing is that I'm reading less data that what is actually in the records of the "test" file. Even more strange is that it only happens sometimes, meaning that with other files the program runs perfectly ok. There seems to be no pattern, as when I write and read the matrices of five thousand or more elements it read perfectly, but with few elements works sometimes well, sometimes spits the error above.

Could you help me?

Im using ifort compiler version 15.0.1 using the compiler flags -O3 -xHost -ipo ( I've tried compiling without optimizations and the result is the same in any case)

 

Thanks in advanced,

Ronquentin

 

 

 

0 Kudos
3 Replies
Steven_L_Intel1
Employee
305 Views

I think you've encountered a known bug, which gets triggered when you read a small part of a very large record, causing the file position to be set incorrectly. This is fixed for a release later this year.

0 Kudos
Alvaro_M_1
Beginner
305 Views

Thank you for your quick reply Steve.

I am grateful that this will be fixed, but in any case, would you have any suggestion to temporally overcome the bug?

Thanks in advanced,

Roquentin

0 Kudos
Steven_L_Intel1
Employee
305 Views

I'm now told to expect this to be fixed in Update 3.

Sorry, I don't know of a workaround other than by reading the rest of the large record (perhaps into a variable you don't use.)

0 Kudos
Reply