PA readswash black reformat
This commit is contained in:
parent
f27f44bbb6
commit
2092789aa2
1 changed files with 108 additions and 80 deletions
|
@ -1,83 +1,111 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
def readswash(filename,xlen,nlay):
|
|
||||||
with open('test.txt', 'r') as f:
|
|
||||||
|
def readswash(filename, nx, nlay):
|
||||||
|
with open(filename, "r") as f:
|
||||||
content = f.readlines()
|
content = f.readlines()
|
||||||
fsurf = []
|
fsurf = []
|
||||||
klay = np.zeros((7203,11,300))
|
klay = np.zeros((7203, nlay+1, nx))
|
||||||
brkp = []
|
brkp = []
|
||||||
Vxfield = np.zeros((7203,11,300))
|
Vxfield = np.zeros((7203, nlay+1, nx))
|
||||||
Vyfield = np.zeros((7203,11,300))
|
Vyfield = np.zeros((7203, nlay+1, nx))
|
||||||
Vzfield = np.zeros((7203,11,300))
|
Vzfield = np.zeros((7203, nlay+1, nx))
|
||||||
ts = []
|
ts = []
|
||||||
t = 0
|
t = 0
|
||||||
for i in range(len(content)):
|
for i in range(len(content)):
|
||||||
if content[i][33:93] == 'Layer interface k=00' :
|
if (
|
||||||
layint0 = content[i+7].split('.')
|
content[i][33:93]
|
||||||
layint1 = content[i+12].split('.')
|
== "Layer interface k=00"
|
||||||
surftemp = [float(layint0[0].split()[1])]+layint0[1:-1]+[float(layint1[0].split()[1])]+layint1[1:-1]
|
):
|
||||||
|
layint0 = content[i + 7].split(".")
|
||||||
|
layint1 = content[i + 12].split(".")
|
||||||
|
surftemp = (
|
||||||
|
[float(layint0[0].split()[1])]
|
||||||
|
+ layint0[1:-1]
|
||||||
|
+ [float(layint1[0].split()[1])]
|
||||||
|
+ layint1[1:-1]
|
||||||
|
)
|
||||||
j = 0
|
j = 0
|
||||||
while j < len(surftemp):
|
while j < len(surftemp):
|
||||||
surftemp[j] = float(surftemp[j])
|
surftemp[j] = float(surftemp[j])
|
||||||
j+=1
|
j += 1
|
||||||
fsurf.append(np.asarray(surftemp)/10)
|
fsurf.append(np.asarray(surftemp) / 10)
|
||||||
if content[i][33:56] == 'Flow velocity per layer' :
|
if content[i][33:56] == "Flow velocity per layer":
|
||||||
k = int(content[i][83:85])
|
k = int(content[i][83:85])
|
||||||
layint0 = content[i+7].split('.')
|
layint0 = content[i + 7].split(".")
|
||||||
layint1 = content[i+12].split('.')
|
layint1 = content[i + 12].split(".")
|
||||||
vktemp = [float(layint0[0].split()[1])]+layint0[1:-1]+[float(layint1[0].split()[1])]+layint1[1:-1]
|
vktemp = (
|
||||||
|
[float(layint0[0].split()[1])]
|
||||||
|
+ layint0[1:-1]
|
||||||
|
+ [float(layint1[0].split()[1])]
|
||||||
|
+ layint1[1:-1]
|
||||||
|
)
|
||||||
j = 0
|
j = 0
|
||||||
while j < len(vktemp):
|
while j < len(vktemp):
|
||||||
try :
|
try:
|
||||||
vktemp[j] = float(vktemp[j])
|
vktemp[j] = float(vktemp[j])
|
||||||
except :
|
except:
|
||||||
#vktemp[j] = float(vktemp[j][-5:])
|
# vktemp[j] = float(vktemp[j][-5:])
|
||||||
vktemp[j]=0
|
vktemp[j] = 0
|
||||||
j+=1
|
j += 1
|
||||||
if content[i][87:88] == 'X':
|
if content[i][87:88] == "X":
|
||||||
Vxfield[t,k,:] = np.asarray(vktemp)/1000
|
Vxfield[t, k, :] = np.asarray(vktemp) / 1000
|
||||||
else:
|
else:
|
||||||
Vyfield[t,k,:] = np.asarray(vktemp)/1000
|
Vyfield[t, k, :] = np.asarray(vktemp) / 1000
|
||||||
if content[i][33:56] == 'Velocity in z-direction' :
|
if content[i][33:56] == "Velocity in z-direction":
|
||||||
k = int(content[i][91:93])
|
k = int(content[i][91:93])
|
||||||
layint0 = content[i+7].split('.')
|
layint0 = content[i + 7].split(".")
|
||||||
layint1 = content[i+12].split('.')
|
layint1 = content[i + 12].split(".")
|
||||||
vktemp = [float(layint0[0].split()[1])]+layint0[1:-1]+[float(layint1[0].split()[1])]+layint1[1:-1]
|
vktemp = (
|
||||||
|
[float(layint0[0].split()[1])]
|
||||||
|
+ layint0[1:-1]
|
||||||
|
+ [float(layint1[0].split()[1])]
|
||||||
|
+ layint1[1:-1]
|
||||||
|
)
|
||||||
j = 0
|
j = 0
|
||||||
while j < len(vktemp):
|
while j < len(vktemp):
|
||||||
try:
|
try:
|
||||||
vktemp[j] = float(vktemp[j])
|
vktemp[j] = float(vktemp[j])
|
||||||
except:
|
except:
|
||||||
vktemp[j] = 0.0
|
vktemp[j] = 0.0
|
||||||
j+=1
|
j += 1
|
||||||
Vzfield[t,k,:len(vktemp)] = np.asarray(vktemp)/1000
|
Vzfield[t, k, : len(vktemp)] = np.asarray(vktemp) / 1000
|
||||||
Vzfield[t,k,len(vktemp):] = np.zeros(300-len(vktemp))
|
Vzfield[t, k, len(vktemp) :] = np.zeros(nx - len(vktemp))
|
||||||
if content[i][33:48] == 'Layer interface' :
|
if content[i][33:48] == "Layer interface":
|
||||||
k = int(content[i][91:93])
|
k = int(content[i][91:93])
|
||||||
layint0 = content[i+7].split('.')
|
layint0 = content[i + 7].split(".")
|
||||||
layint1 = content[i+12].split('.')
|
layint1 = content[i + 12].split(".")
|
||||||
layktemp = [float(layint0[0].split()[1])]+layint0[1:-1]+[float(layint1[0].split()[1])]+layint1[1:-1]
|
layktemp = (
|
||||||
|
[float(layint0[0].split()[1])]
|
||||||
|
+ layint0[1:-1]
|
||||||
|
+ [float(layint1[0].split()[1])]
|
||||||
|
+ layint1[1:-1]
|
||||||
|
)
|
||||||
j = 0
|
j = 0
|
||||||
while j < len(layktemp):
|
while j < len(layktemp):
|
||||||
layktemp[j] = float(layktemp[j])
|
layktemp[j] = float(layktemp[j])
|
||||||
j+=1
|
j += 1
|
||||||
klay[t,k,:] = np.asarray(layktemp)/10
|
klay[t, k, :] = np.asarray(layktemp) / 10
|
||||||
if content[i][33:52] == 'wave breaking point' :
|
if content[i][33:52] == "wave breaking point":
|
||||||
br0 = content[i+7].split('.')
|
br0 = content[i + 7].split(".")
|
||||||
br1 = content[i+12].split('.')
|
br1 = content[i + 12].split(".")
|
||||||
brtemp = [float(br0[0].split()[1])]+br0[1:-1]+[float(br1[0].split()[1])]+br1[1:-1]
|
brtemp = (
|
||||||
|
[float(br0[0].split()[1])]
|
||||||
|
+ br0[1:-1]
|
||||||
|
+ [float(br1[0].split()[1])]
|
||||||
|
+ br1[1:-1]
|
||||||
|
)
|
||||||
j = 0
|
j = 0
|
||||||
while j < len(brtemp):
|
while j < len(brtemp):
|
||||||
brtemp[j] = float(brtemp[j])
|
brtemp[j] = float(brtemp[j])
|
||||||
j+=1
|
j += 1
|
||||||
brkp.append(np.asarray(brtemp))
|
brkp.append(np.asarray(brtemp))
|
||||||
if content[i][33:68] == 'Time in seconds from reference time' :
|
if content[i][33:68] == "Time in seconds from reference time":
|
||||||
ts.append(float(content[i+1][7:16]))
|
ts.append(float(content[i + 1][7:16]))
|
||||||
t+=1
|
t += 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return fsurf, Vxfield, Vyfield, Vzfield, brkp, klay
|
return fsurf, Vxfield, Vyfield, Vzfield, brkp, klay
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(readswash("test.txt", 1250, 10))
|
||||||
|
|
Loading…
Reference in a new issue