source: trunk/anuga_work/development/tools/r2d/xyz2River2DBED.py @ 8866

Last change on this file since 8866 was 5780, checked in by ole, 17 years ago

Added contributed code from Petar Milevski

File size: 2.1 KB
Line 
1""" This scrip takes a space separated data (ssv) x,y,z file and converts it to a (CSV) then to a
2River2D.bed input file. The user can then edit the River2DBED file using the River2D bed file editor program
3Once 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
5All you need to do is specify the data file name and output file name
6
7by Petar Milevski 19/9/2008
8"""
9
10import string
11import os
12# =============================================================================
13# Here we read in the space separated variable file (ssv) and create a csv file
14# =============================================================================
15
16infid = open('ssv.grd') # input file
17outfid = open('csv.csv', 'w')
18
19for 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
30infid.close()
31outfid.close()
32
33# =============================================================================
34# Here we read in the csv file and create a River2D bed file
35# =============================================================================
36
37
38infid = open('csv.csv', 'r')
39outfid = open('River2D.bed', 'w')
40
41n=0
42
43for 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'))
50outfid.write('\n')
51outfid.write('no more nodes.')
52outfid.write('\n \n \n')
53outfid.write('no more breakline segments.')
54outfid.write('\n \n \n')
55outfid.write('no more boundary segments.')
56
57# =============================================================================
58# Here we delete the superceeded csv file
59# =============================================================================
60
61infid.close()
62outfid.close()
63os.remove('csv.csv')
Note: See TracBrowser for help on using the repository browser.