-1

There is a set of data in a text file which is the hourly temperature and rainfall. I wanted to read this data in a particular way in Fortran.

Data in the text file:

Day 1 Hour 1  Temp rain
Day 1 Hour 2  Temp rain
Day 1 Hour 3  Temp rain
...
Day 1 Hour 24 Temp rain
Day 2 Hour 1  Temp rain
Day 2 Hour 2  Temp rain
Day 2 Hour 3  Temp rain
...
Day 2 Hour 24  Temp rain
Day 3 Hour 1   Temp rain
...

.

DO loop1
    Read the first 24 hours of data from the text file
    {Do some procedures using First 24 hour data}
    Read Second 24 hours of data from the text file
    {Do some procedures using First 24 hour data}
End DO

I want the next DO loop to work in the following way

DO loop2
    Read second 24 hours  **(I want to read the Second 24-hour data 
    again in this loop, how can I read this set again since its once read in loop 1?.** 
    {Do some procedures using second 24-hour data}
    Read the third 24 hours of data from the text file
    {Do some procedures using third 24-hour data}
End DO loop2
chw21
  • 7,970
  • 1
  • 16
  • 31
  • Agree with @IanBush that the question needs improvement. That said, the normal way to do this would be to save the data in a cache to be used later. Something like reading the data file into an array. – evets Nov 11 '20 at 22:30

1 Answers1

1

Your question is confusing.

What I understand is that you need to compare the first day to the second, then the second to the third, then the third to the fourth and so on.

And for some reason you believe that you need to read the data in every time. That isn't the case. You can either read all the data in at once, keeping all of it in memory, or, if that is too big (and it needs to be really big to be too big, don't forget, 10MB of ram can hold over 10 million 64 bit floating point numbers), you can read it day-by-day like this:

real :: data1(24), data2(24)
...
<read data1>
<work on data1>
do
    <read data2>
    <if EOF exit>
    <work on data2>
    <compare data1 and data2>
    data1 = data2
end do
chw21
  • 7,970
  • 1
  • 16
  • 31