脚本未从数据输入文件中查找文件结尾
我希望这是有道理的。我有一个 Python 脚本,它读取地理坐标的输入(从 csv 创建,并删除逗号)文件,并且出现此错误:
forrtl: severe (24): end of file during read. unit 23 file /home/filename
这似乎与代码期望输入文件中存在 EOF 相关,但这可能不存在。有人能够告诉我如何在输入文件中检查这一点以及 EOF 需要什么击键以及它的确切位置。 这是创建文件的脚本的摘录:
f = open(file_ls, "w")
#first line contains 3 integers: the grid dimension, nx and ny, and the total number of snapshots nt
print("%d %d %d" % (np.shape(kxx)[1], np.shape(kxx)[0], collapse_steps), file(f))
# then it follows by the X coordinates of gridded data (from lines 2 to nx+1), Y coordinates of gridded data (from lines nx+1 to nx+ny+1), and the times at which the snapshots are created (from lines nx+ny+2 to nx+ny+nt+1)
for ii in np.arange(np.shape(kxx)[1]):
print("%.8f" % (kxx[0, ii]), file(f))
# for ii in arrange(shape(kyy)[0]):
for ii in range(np.shape(kyy)[0] - 1, -1, -1):
print("%.8f" % (kyy[ii, 0]), file(f))
for ii in np.arange(collapse_steps):
mytime = collapse_times[ii] + collapse_starttime
print("%.8f" % mytime, file(f))
# all the nt snapshots of seafloor variation are written into a single column one by one from t=t1 to t=tn; for each snapshot, deltah, the data should be written row by row from the left (i=1) to the right (i=nx) from the bottom (j=1) to the top (j=nx)
# deltaH > 0 corresponds to UPLIFT
# deltaH < 0 corresponds to SUBSIDE
deltaH = elev_t0 - elev_t1
###### time - start of collapse => initial bath => zero difference ??? bit stupid ??? check w/comcot sources
for ii in np.arange(np.shape(elev_t1)[0]):
for jj in np.arange(np.shape(elev_t1)[1]):
print("%.8f" % 0.0, file(f))
for ii in np.arange(np.shape(elev_t1)[0]):
for jj in np.arange(np.shape(elev_t1)[1]):
print("%.8f" % (deltaH[ii, jj]), file(f))
f.close()
这是第一行输入文件的摘录:
1488 903 2 3560181.70300000 3560191.70300000 3560201.70300000 3560211.70300000 3560221.70300000 3560231.70300000 3560241.70300000 3560251.70300000 3560261.70300000 3560271.70300000 3560281.70300000 3560291.70300000 3560301.70300000 3560311.70300000 3560321.70300000 3560331.70300000 3560341.70300000 3560351.70300000 3560361.70300000 3560371.70300000 3560381.70300000 3560391.70300000 3560401.70300000 3560411.70300000 3560421.70300000 3560431.70300000 3560441.70300000 3560451.70300000 3560461.70300000 3560471.70300000 3560481.70300000
I hope this makes sense. I have a Python script that reads an input (created from csv with commmas stripped out) file of geographic coordinates and I get this error:
forrtl: severe (24): end of file during read. unit 23 file /home/filename
This seems to relate that the code was expecting an EOF in the input file but this was perhaps absent. Would someone be able to tell how I check for this in the input file and what keystroke(s) are required for an EOF and exactly where this is placed.
this is an extract of the script that creates the file:
f = open(file_ls, "w")
#first line contains 3 integers: the grid dimension, nx and ny, and the total number of snapshots nt
print("%d %d %d" % (np.shape(kxx)[1], np.shape(kxx)[0], collapse_steps), file(f))
# then it follows by the X coordinates of gridded data (from lines 2 to nx+1), Y coordinates of gridded data (from lines nx+1 to nx+ny+1), and the times at which the snapshots are created (from lines nx+ny+2 to nx+ny+nt+1)
for ii in np.arange(np.shape(kxx)[1]):
print("%.8f" % (kxx[0, ii]), file(f))
# for ii in arrange(shape(kyy)[0]):
for ii in range(np.shape(kyy)[0] - 1, -1, -1):
print("%.8f" % (kyy[ii, 0]), file(f))
for ii in np.arange(collapse_steps):
mytime = collapse_times[ii] + collapse_starttime
print("%.8f" % mytime, file(f))
# all the nt snapshots of seafloor variation are written into a single column one by one from t=t1 to t=tn; for each snapshot, deltah, the data should be written row by row from the left (i=1) to the right (i=nx) from the bottom (j=1) to the top (j=nx)
# deltaH > 0 corresponds to UPLIFT
# deltaH < 0 corresponds to SUBSIDE
deltaH = elev_t0 - elev_t1
###### time - start of collapse => initial bath => zero difference ??? bit stupid ??? check w/comcot sources
for ii in np.arange(np.shape(elev_t1)[0]):
for jj in np.arange(np.shape(elev_t1)[1]):
print("%.8f" % 0.0, file(f))
for ii in np.arange(np.shape(elev_t1)[0]):
for jj in np.arange(np.shape(elev_t1)[1]):
print("%.8f" % (deltaH[ii, jj]), file(f))
f.close()
This is an extract of the input file from 1st line:
1488 903 2 3560181.70300000 3560191.70300000 3560201.70300000 3560211.70300000 3560221.70300000 3560231.70300000 3560241.70300000 3560251.70300000 3560261.70300000 3560271.70300000 3560281.70300000 3560291.70300000 3560301.70300000 3560311.70300000 3560321.70300000 3560331.70300000 3560341.70300000 3560351.70300000 3560361.70300000 3560371.70300000 3560381.70300000 3560391.70300000 3560401.70300000 3560411.70300000 3560421.70300000 3560431.70300000 3560441.70300000 3560451.70300000 3560461.70300000 3560471.70300000 3560481.70300000
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论