如何从文件中的特定行读取数据?

发布于 2024-09-13 04:14:00 字数 3588 浏览 2 评论 0原文

我有一个问题,如何从文本文件中读取行 n 和列 m 中的数字。

下面是文件。我想要阅读的数字被标记为粗体

G07 1437 1437 1437 1437 PRN / # OF OBS G08 1437 1437 1437 1437
PRN / OBS G10 数量 1437 1437 1437 1437
PRN / OBS G13 数量 1437 1437 1437 1437
PRN / OBS G15 数量 1437 1437 1437 1437
PRN / OBS 数量 G24 809 804 774 774
PRN / OBS 数量 G25 816 748 694 694
PRN / OBS G28 数量 1437 1437 1437 1437
PRN / OBS 载波相位测量数量:已移除相移 评论
标头结束 09 6 10 11 50 14.0000000 0 7G07G08G10G13G15G25G28

21640633.14117 211001.84417 145686.75058 21640629.92858 20270038.40917 47299.20717 29373.29759 20270035.88059 20921122.23717 35179.40617 20913.66459 20921119.72759 23375852.17815 245299.13715 159374.10256 23375851.73756 24332262.34516 -47567.80516 -24598.05157 24332261.03057 23397473.99216 238631.73016 166805.02757 23397473.15457 21826760.73217 -130774.53117 -98585.76258 21826757.69358 09 6 10 11 50 15.0000000 0 8G07G08G10G13G15G24G25G28
21641196.234 6 213960.266 6 147992.01248 21641193.20548 20270164.110 7 47960.691 7 29888.74248 20270161.61348 20921216.127 7 35674.703 7 21299.61749 20921213.51249 23376533.019 6 248872.664 6 162158.66846 23376531.77946 24331762.736 6 -50196.488 6 -26646.36747 24331760.98147 24599401.84316
23398117.377 6 242012.082 6 169439.07047 23398116.40347 21826403.256 7 -132653.473 7 -100049.87148 21826400.70948 09 6 10 11 50 16.0000000 0 8G07G08G10G13G15G24G25G28
21641758.805 7 216918.813 7 150297.37548 21641756.07848 20270290.115 7 48622.465 7 30404.41049 20270287.40449 20921310.905 7 36170.543 7 21685.98849 20921307.82749 23377213.438 6 252446.262 6 164943.27746 23377211.83946 24331261.918 6 -52825.297 6 -28694.78547 24331260.53947 24599639.441 6
23398760.704 6 245392.375 6 172073.07047 23398759.57647 21826045.702 7 -134532.152 7 -101513.77748 21826043.03148 09 6 10 11 50 17.0000000 0 8G07G08G10G13G15G24G25G28
21642322.125 7 219877.535 7 152602.87548 21642319.08048 20270416.177 7 49284.598 7 30920.36349 20270413.70449 20921405.154 7 36666.953 7 22072.80148 20921402.13148 23377893.321 6 256020.004 6 167728.00846 23377891.84946 24330762.414 6 -55454.160 6 -30743.25047 24330760.25447 24599877.399 6
23399403.485 6 248772.668 6 174707.06647 23399402.65647 21825688.338 7 -136410.488 7 -102977.41048 21825685.89248 09 6 10 11 50 18.0000000 0 8G07G08G10G13G15G24G25G28
21642885.530 7 222836.375 7 154908.46548 21642882.14548 20270542.254 7 49947.043 7 31436.54749 20270539.58049 20921499.789 7 37163.945 7 22460.07048 20921496.78948 23378573.557 6 259593.785 6 170512.77746 23378571.94746 24330261.660 6 -58083.102 6 -32791.77747 24330259.94247 24600114.981 6
23400047.052 6 252152.898 6 177341.01247 23400046.00147 21825331.225 7 -138288.496 7 -104440.78948 21825328.12748 09 6 10 11 50 19.0000000 0 8G07G08G10G13G15G24G25G28
21643448.790 7 225795.313 7 157214.13348 21643445.39848 20270668.553 7 50609.801 7 31952.98049 20270666.09149 20921594.496 7 37661.504 7 22847.77348 20921591.58548 23379252.757 5 263167.641 5 173297.60946 23379252.06246 24329761.100 6 -60712.121 6 -34840.36747 24329759.15547 24600353.301 6
23400690.655 6 255533.066 6 179974.90647 23400689.68747 21824974.083 7 -140166.188 7 -105903.92248 21824970.73848

I have a problem how to read the number from line n and column m from a text file.

Below is the file. The number I want to read is marked bold.

G07 1437 1437 1437 1437 PRN / # OF
OBS G08 1437 1437 1437 1437
PRN / # OF OBS G10 1437 1437 1437 1437
PRN / # OF OBS G13 1437 1437 1437 1437
PRN / # OF OBS G15 1437 1437 1437 1437
PRN / # OF OBS G24 809 804 774 774
PRN / # OF OBS G25 816 748 694 694
PRN / # OF OBS G28 1437 1437 1437 1437
PRN / # OF OBS CARRIER PHASE MEASUREMENTS: PHASE SHIFTS REMOVED
COMMENT
END OF HEADER 09 6 10 11 50 14.0000000 0 7G07G08G10G13G15G25G28

21640633.14117 211001.84417 145686.75058 21640629.92858
20270038.40917 47299.20717 29373.29759 20270035.88059
20921122.23717 35179.40617 20913.66459 20921119.72759
23375852.17815 245299.13715 159374.10256 23375851.73756
24332262.34516 -47567.80516 -24598.05157 24332261.03057
23397473.99216 238631.73016 166805.02757 23397473.15457
21826760.73217 -130774.53117 -98585.76258 21826757.69358 09 6 10 11 50 15.0000000 0 8G07G08G10G13G15G24G25G28
21641196.234 6 213960.266 6 147992.01248 21641193.20548
20270164.110 7 47960.691 7 29888.74248 20270161.61348
20921216.127 7 35674.703 7 21299.61749 20921213.51249
23376533.019 6 248872.664 6 162158.66846 23376531.77946
24331762.736 6 -50196.488 6 -26646.36747 24331760.98147
24599401.84316
23398117.377 6 242012.082 6 169439.07047 23398116.40347
21826403.256 7 -132653.473 7 -100049.87148 21826400.70948 09 6 10 11 50 16.0000000 0 8G07G08G10G13G15G24G25G28
21641758.805 7 216918.813 7 150297.37548 21641756.07848
20270290.115 7 48622.465 7 30404.41049 20270287.40449
20921310.905 7 36170.543 7 21685.98849 20921307.82749
23377213.438 6 252446.262 6 164943.27746 23377211.83946
24331261.918 6 -52825.297 6 -28694.78547 24331260.53947
24599639.441 6
23398760.704 6 245392.375 6 172073.07047 23398759.57647
21826045.702 7 -134532.152 7 -101513.77748 21826043.03148 09 6 10 11 50 17.0000000 0 8G07G08G10G13G15G24G25G28
21642322.125 7 219877.535 7 152602.87548 21642319.08048
20270416.177 7 49284.598 7 30920.36349 20270413.70449
20921405.154 7 36666.953 7 22072.80148 20921402.13148
23377893.321 6 256020.004 6 167728.00846 23377891.84946
24330762.414 6 -55454.160 6 -30743.25047 24330760.25447
24599877.399 6
23399403.485 6 248772.668 6 174707.06647 23399402.65647
21825688.338 7 -136410.488 7 -102977.41048 21825685.89248 09 6 10 11 50 18.0000000 0 8G07G08G10G13G15G24G25G28
21642885.530 7 222836.375 7 154908.46548 21642882.14548
20270542.254 7 49947.043 7 31436.54749 20270539.58049
20921499.789 7 37163.945 7 22460.07048 20921496.78948
23378573.557 6 259593.785 6 170512.77746 23378571.94746
24330261.660 6 -58083.102 6 -32791.77747 24330259.94247
24600114.981 6
23400047.052 6 252152.898 6 177341.01247 23400046.00147
21825331.225 7 -138288.496 7 -104440.78948 21825328.12748 09 6 10 11 50 19.0000000 0 8G07G08G10G13G15G24G25G28
21643448.790 7 225795.313 7 157214.13348 21643445.39848
20270668.553 7 50609.801 7 31952.98049 20270666.09149
20921594.496 7 37661.504 7 22847.77348 20921591.58548
23379252.757 5 263167.641 5 173297.60946 23379252.06246
24329761.100 6 -60712.121 6 -34840.36747 24329759.15547
24600353.301 6
23400690.655 6 255533.066 6 179974.90647 23400689.68747
21824974.083 7 -140166.188 7 -105903.92248 21824970.73848

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

和影子一齐双人舞 2024-09-20 04:14:00

以下是一些示例代码,展示了跳过行和数字以到达所需项目的技术。如果列对齐比数字计数更重要,您可能必须切换到格式化读取。

program test

integer, parameter :: DBL_K = selected_real_kind (14)

character (len=132) :: skip
integer :: i, j
real (DBL_K) :: junk (100), good (100)

open (file="test.txt", unit=25, form="formatted", access="sequential", status="old", action="read")

do i=1, 11
   read (25, '(A)' )  skip
end do

read (25, *) (junk (j), j=1,3), good (1)


write (*, *) good (1)

end program test

Here is some sample code that shows techniques to skip lines and numbers to reach the item that you want. You might have to switch to formatted reads if the column alignment is more important the the count of numbers.

program test

integer, parameter :: DBL_K = selected_real_kind (14)

character (len=132) :: skip
integer :: i, j
real (DBL_K) :: junk (100), good (100)

open (file="test.txt", unit=25, form="formatted", access="sequential", status="old", action="read")

do i=1, 11
   read (25, '(A)' )  skip
end do

read (25, *) (junk (j), j=1,3), good (1)


write (*, *) good (1)

end program test
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文