[英]Using BufferedReader in java to read a line of ints before reading lines of Strings from a text file
[英]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.