提问人:Fitch 提问时间:3/27/2022 最后编辑:Burhan AliFitch 更新时间:3/28/2022 访问量:58
脚本未从数据输入文件中查找文件末尾
Script is not Finding End of File from Data Input File
问:
我希望这是有道理的。我有一个 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.703000003560451.70300000 3560461.70300000 3560471.70300000 3560481.70300000
答: 暂无答案
评论
f = open(file_ls, "w")
with open(file_ls, 'w') as f:
f.close()
print("%.8f" % (kxx[0, ii]), file(f))
什么?file()