I wonder if someone could point out why this script is not writing to a file. I can see the correct values populating the terminal but when I go to open the output file it wrote to, it was empty.
file = 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), open(file_ls, "a"))
# 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]), open(file_ls, "a"))
# for ii in arrange(shape(kyy)[0]):
for ii in range(np.shape(kyy)[0] - 1, -1, -1):
print("%.8f" % (kyy[ii, 0]), open(file_ls, "a"))
for ii in np.arange(collapse_steps):
mytime = collapse_times[ii] + collapse_starttime
print("%.8f" % mytime, open(file_ls, "a"))
# 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, open(file_ls, "a"))
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]), open(file_ls, "a"))
file.close()
buran write Mar-29-2022, 07:36 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
