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

forrt1: severe (24): end-of-file during read

Chin_Wei_L_
Beginner
9,381 Views

Hello

I am getting the following message after running the code:

forrt1: severe (24): end-of-file during read...

What does this mean?

Basically, I'd like to sort the following column of numbers into an order based on their indices:

Example:

12

3

8

The index order is:

3

2

1

So, the expected output is:

8

3

12

What I am getting in the output file is:

12

Please could anyone help? 

Thank you.

0 Kudos
1 Solution
Les_Neilson
Valued Contributor II
9,381 Views

Something like this:

1 Read index file

2 Read data file

3 Output the data e.g.

do I = 1,3

    do j = 1,3

       if (I .eq. index(j)) then

            write(33, *) data(j)

       endif

    enddo

enddo

 

View solution in original post

0 Kudos
9 Replies
Arjen_Markus
Honored Contributor II
9,381 Views

It is not quite clear from your description, but I guess that you are reading the data from a file. Apparently this is not going the way you expect it - the program reaches the end of the file before it has been able to read all the data it expects to find there, hence the error message.

To help you, we will need to know more about what your program is doing. Could you post the parts that are reading the file? Include the declarations of the variables, that may be important.

0 Kudos
Chin_Wei_L_
Beginner
9,381 Views

Hi

Thank you for your reply.

Both data and index order are read in from text files, respectively.

The data.txt file contains a column of numbers:

12

3

8

The index.txt file contains a column of indices:

3

2

1

I would like to sort the numbers based on their indices in that particular order as in the index.txt and then write out to sorted.txt.

The Fortran code is:

program sort

implicit none

integer i, j, data(3), index(3)

open(11, file='data.txt', status='old')

open(22, file='index.txt', status='old')

open(33, file='sorted.txt', status='new')

do 101 i=1, 3

  do 201 j=1, 3

    read(22, *) index(j)

      if (index(j) == i) then

        read(11, *) data(i)

        write(33, *) data(i)

        go to 101

     else

        go to 201

     end if

 201  continue

101 continue

   close(11)

   close(22)

   close(33)

   stop

   end

 

Something wrong with this code?

Any comments welcome. 

 

0 Kudos
Arjen_Markus
Honored Contributor II
9,381 Views

Well, if there is anything wrong with the code perse, is a rather philosophical question ;). But it definitely is not doing what you want. Your code searches for the line that contains the value of i, but it does not rewind the file, so on the next value of i (loop 101), it reaches the end of the file and then you get the error message. Instead you could do:

  • Read the indices
  • Read the data
  • Write out the data in the order given by the indices

You are already storing the data and the indices in arrays, so use that feature.

 

0 Kudos
Chin_Wei_L_
Beginner
9,381 Views

Hi

Thank you for the tips.

However, I think I am complicated myself with the following:

  • Write out the data in the order given by the indices

Please could you provide more insight? 

 

Thanks.

0 Kudos
Arjen_Markus
Honored Contributor II
9,381 Views

Since the index for the data is in the array index, you can use data(index(i)) to get the value that should appear in the i-th position

0 Kudos
Chin_Wei_L_
Beginner
9,381 Views

Hi

Many apologies as I am still struggling with this.

Please could further help with demonstrating an example of the code?

(Beginner)

 

0 Kudos
Les_Neilson
Valued Contributor II
9,382 Views

Something like this:

1 Read index file

2 Read data file

3 Output the data e.g.

do I = 1,3

    do j = 1,3

       if (I .eq. index(j)) then

            write(33, *) data(j)

       endif

    enddo

enddo

 

0 Kudos
Arjen_Markus
Honored Contributor II
9,381 Views

Well, most of it is already there - you just need to read the index file in one loop and the data file in another loop. Then in a third loop you can write the data as I showed.

Instead of:

do 101 i = 1,3
    ...
101 continue

you can also do (and this is preferred, because you do not need to be careful with the label numbers then):

do i = 1,3
     ...
enddo

Or, to make it more generic: instead of 3 as a fixed upper bound, use size() to get the right upper bound automatically:

do i = 1,size(index)
    read( 101, * ) index(i)
enddo

 

0 Kudos
Chin_Wei_L_
Beginner
9,381 Views

Thanks guys. The code works with some small modifications and does the job. Very much appreciated!

0 Kudos
Reply