繁体   English   中英

如何撤消 Fortran 文本文件中的读取行/如何重新读取之前在 Fortran 中读取的相同行

[英]How to undo reading lines from text file in Fortran/ How to Re-read the same lines already read before in Fortran

文本文件中有一组数据是每小时的温度和降雨量。 我想在 Fortran 中以特定方式读取此数据。

文本文件中的数据:

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

我希望下一个 DO 循环按以下方式工作

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

你的问题令人困惑。

我的理解是,您需要比较第一天和第二天,然后是第二天和第三天,然后是第三天和第四天,依此类推。

出于某种原因,您认为每次都需要读取数据。 事实并非如此。 您可以一次读取所有数据,将所有数据保存在 memory 中,或者,如果它太大(并且它需要非常大才能太大,不要忘记,10MB 的 ram 可以容纳超过 10百万 64 位浮点数),你可以像这样每天阅读它:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM