1 | """ This scrip takes a space separated data (ssv) x,y,z file and converts it to a (CSV) then to a |
---|
2 | River2D.bed input file. The user can then edit the River2DBED file using the River2D bed file editor program |
---|
3 | Once the edits are done, save the file and use the River2D2NETCDF program to convert the file back to a csv and ANUGA PTS file |
---|
4 | |
---|
5 | All you need to do is specify the data file name and output file name |
---|
6 | |
---|
7 | by Petar Milevski 19/9/2008 |
---|
8 | """ |
---|
9 | |
---|
10 | import string |
---|
11 | import os |
---|
12 | # ============================================================================= |
---|
13 | # Here we read in the space separated variable file (ssv) and create a csv file |
---|
14 | # ============================================================================= |
---|
15 | |
---|
16 | infid = open('ssv.grd') # input file |
---|
17 | outfid = open('csv.csv', 'w') |
---|
18 | |
---|
19 | for line in infid.readlines(): |
---|
20 | fields = line.split() |
---|
21 | x=float(fields[0]) |
---|
22 | y=float(fields[1]) |
---|
23 | z=float(fields[2]) |
---|
24 | outfid.write('%.3f,%.3f,%.3f\n' %(x, y, z)) |
---|
25 | |
---|
26 | # ============================================================================= |
---|
27 | # Here we close both the csv and ssv |
---|
28 | # ============================================================================= |
---|
29 | |
---|
30 | infid.close() |
---|
31 | outfid.close() |
---|
32 | |
---|
33 | # ============================================================================= |
---|
34 | # Here we read in the csv file and create a River2D bed file |
---|
35 | # ============================================================================= |
---|
36 | |
---|
37 | |
---|
38 | infid = open('csv.csv', 'r') |
---|
39 | outfid = open('River2D.bed', 'w') |
---|
40 | |
---|
41 | n=0 |
---|
42 | |
---|
43 | for line in infid.readlines(): |
---|
44 | fields = line.split(',') |
---|
45 | n=n+1 |
---|
46 | x=float(fields[0]) |
---|
47 | y=float(fields[1]) |
---|
48 | z=float(fields[2]) |
---|
49 | outfid.write('%d %.3f %.3f %.3f %s \n' %(n, x, y, z, '0.5 grd')) |
---|
50 | outfid.write('\n') |
---|
51 | outfid.write('no more nodes.') |
---|
52 | outfid.write('\n \n \n') |
---|
53 | outfid.write('no more breakline segments.') |
---|
54 | outfid.write('\n \n \n') |
---|
55 | outfid.write('no more boundary segments.') |
---|
56 | |
---|
57 | # ============================================================================= |
---|
58 | # Here we delete the superceeded csv file |
---|
59 | # ============================================================================= |
---|
60 | |
---|
61 | infid.close() |
---|
62 | outfid.close() |
---|
63 | os.remove('csv.csv') |
---|