-
Notifications
You must be signed in to change notification settings - Fork 1
/
wbellhopenvfil.py
244 lines (204 loc) · 7.55 KB
/
wbellhopenvfil.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
def wbellhopenvfil(filename=None, thetitle=None, source_info=None, surface_info=None, ssp_info=None, bathymetry_info=None, options=None ):
# Writes BELLHOP env file
#
# SYNTAX: wbellhopenvfil(filename, thetitle, source_info, surface_info, ssp_info, bottom_info, options)
#*******************************************************************************
# Faro, Qua Mai 26 19:06:06 WEST 2021
# Written by Orlando Camargo Rodriguez
#*******************************************************************************
envfil = filename + '.env'
atifil = filename + '.ati'
btyfil = filename + '.bty'
sspfil = filename + '.ssp'
#*******************************************************************************
# Get source data:
box = source_info["box"]
zs = source_info["zs"]
freq = source_info["f"]
thetas = source_info["thetas"]
beamp = source_info["p"]
beamc = source_info["comp"]
nthetas = thetas[0]
theta1 = thetas[1]
theta2 = thetas[2]
#*******************************************************************************
# Get surface data:
sitype = surface_info["itype"]
xati = surface_info["x"]
aunits = surface_info["units"]
pati = surface_info["p"]
#*******************************************************************************
# Get sound speed data:
c = ssp_info["c"]
r = ssp_info["r"]
z = ssp_info["z"]
csize = c.shape
Dmax = z[-1]
if len( r ) > 0:
nr = r.size
else:
nr = 0
#*******************************************************************************
# Get bathymetry data:
bitype = bathymetry_info["itype"]
bunits = bathymetry_info["units"]
xbty = bathymetry_info["x"]
pbty = bathymetry_info["p"]
#*******************************************************************************
# Get options:
options1 = options["options1"]
options2 = options["options2"]
options3 = options["options3"]
options4 = options["options4"]
rarray = options["rarray"]
zarray = options["zarray"]
#*******************************************************************************
# Write the ENVFIL:
fid = open(envfil, 'w')
fid.write('\'');fid.write(thetitle);fid.write('\'\n')
fid.write(str(freq))
fid.write("\n")
fid.write('1\n')
fid.write('\'');fid.write(options1);fid.write('\'\n')
s = options1[0]
if s == "Q":
fidssp = open(sspfil, 'w')
fidssp.write(str(nr))
fidssp.write("\n")
fidssp.write(str(r))
fidssp.write("\n")
for i in range(c.shape[0]):
for j in range(c.shape[1]):
fidssp.write(str(c[i,j]))
fidssp.write("\n")
fidssp.close()
s = options1[1]
if s == "A":
fid.write( str( pati[0] ) );fid.write(" ")
fid.write( str( pati[1] ) );fid.write(" ")
fid.write( str( pati[2] ) );fid.write(" ")
fid.write( str( pati[3] ) );fid.write(" ")
fid.write( str( pati[4] ) );
fid.write("/ \n")
if len( options1 ) > 5:
option5 = options1[5]
else:
option5 = " "
if option5 == "*":
nati = xati[0,:].size
fidati = open(atifil, 'w')
fidati.write("\'");fidati.write(aitype);fidati.write("\'\n")
fidati.write(str(nati));fidati.write("\n")
for i in range(nati):
fidati.write(str(xati[0,i]));fidati.write(" ")
fidati.write(str(xati[1,i]));fidati.write("\n")
fidati.close()
elif option5 == "~":
nati = xati[0,:].size
fidati = open(atifil, 'w')
fidati.write("\'");fidati.write(bitype);fidati.write("\'\n")
fidati.write(str(nati));fidati.write("\n")
for i in range(nati):
fidati.write(str(xati[0,i]));fidati.write(" ")
fidati.write(str(xati[1,i]));fidati.write(" ")
fidati.write(str(xati[2,i]));fidati.write(" ")
fidati.write(str(xati[3,i]));fidati.write(" ")
fidati.write(str(xati[4,i]));fidati.write(" ")
fidati.write(str(xati[5,i]));fidati.write(" ")
fidati.write(str(xati[6,i]));fidati.write("\n")
fidati.close()
else:
print("No ati file needed...")
fid.write('51 0.0 ' ) # Dummy parameters
fid.write(str(Dmax) )
fid.write("\n")
nz = z.size
if nr == 0:
for i in range(nz):
fid.write( str( z[i] ) ); fid.write(" ")
fid.write( str( c[i] ) ); fid.write(" /\n")
else:
for i in range(nz):
fid.write( str( z[i] ) ); fid.write(" ")
fid.write( str( c[i,0] ) ); fid.write("\n")
fid.write('\'');fid.write( options2 );fid.write('\'')
fid.write(' 0.0 ' )
fid.write("\n")
s = options2[0]
if s == "A":
fid.write( str(Dmax) ); fid.write(" ")
fid.write( str( pbty[0] ) );fid.write(" ")
fid.write( str( pbty[1] ) );fid.write(" ")
fid.write( str( pbty[2] ) );fid.write(" ")
fid.write( str( pbty[3] ) );fid.write(" ")
fid.write( str( pbty[4] ) );
fid.write(" / \n")
s = options2[1]
if s == "*":
nbty = xbty[0,:].size
fidbty = open(btyfil, 'w')
fidbty.write("\'");fidbty.write(bitype);fidbty.write("\'\n")
fidbty.write(str(nbty));fidbty.write("\n")
for i in range(nbty):
fidbty.write(str(xbty[0,i]));fidbty.write(" ")
fidbty.write(str(xbty[1,i]));fidbty.write("\n")
fidbty.close()
elif s == "~":
nbty = xbty[0,:].size
fidbty = open(btyfil, 'w')
fidbty.write("\'");fidbty.write(bitype);fidbty.write("\'\n")
fidbty.write(str(nbty));fidbty.write("\n")
for i in range(nbty):
fidbty.write(str(xbty[0,i]));fidbty.write(" ")
fidbty.write(str(xbty[1,i]));fidbty.write(" ")
fidbty.write(str(xbty[2,i]));fidbty.write(" ")
fidbty.write(str(xbty[3,i]));fidbty.write(" ")
fidbty.write(str(xbty[4,i]));fidbty.write(" ")
fidbty.write(str(xbty[5,i]));fidbty.write(" ")
fidbty.write(str(xbty[6,i]));fidbty.write("\n")
fidbty.close()
else:
print("No bty file needed...")
nzs = zs.size
fid.write( str( nzs ) )
fid.write("\n")
if nzs == 1:
fid.write( str( zs[0] ) ); fid.write(" / \n")
else:
fid.write( str( zs[0] ) )
fid.write( str( zs[-1] ) )
fid.write(" / \n")
nra = rarray.size
nza = zarray.size
fid.write( str( nza ) )
fid.write("\n")
if nza > 1:
fid.write( str( zarray[0] ) );fid.write(" ")
fid.write( str( zarray[-1] ) )
fid.write(" / \n")
else:
fid.write( str( zarray[0] ) )
fid.write(" / \n")
fid.write( str(nra) )
fid.write("\n")
if nra > 1:
fid.write( str( rarray[0] ) );fid.write(" ")
fid.write( str( rarray[-1] ) )
fid.write(" / \n")
else:
fid.write( str( rarray[0] ) )
fid.write(" / \n")
fid.write( options3 ); fid.write("\n")
fid.write( str( int( nthetas) ) ); fid.write("\n")
fid.write( str(theta1) ); fid.write(" ")
fid.write( str(theta2) ); fid.write(" / \n")
fid.write( str(box[0]) ); fid.write(" ")
fid.write( str(box[1]) ); fid.write(" ")
fid.write( str(box[2]) ); fid.write("\n")
if len( options4 ) > 0:
fid.write( options4 ); fid.write("\n")
fid.write( beamp[0:2] ); fid.write("\n")
fid.write( beamp[3:4] )
fid.write( beamc )
fid.write("\n")
fid.close()