""" This scrip takes a space separated data (ssv) x,y,z file and converts it to a (CSV) then to a River2D.bed input file. The user can then edit the River2DBED file using the River2D bed file editor program 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 All you need to do is specify the data file name and output file name by Petar Milevski 19/9/2008 """ import string import os # ============================================================================= # Here we read in the space separated variable file (ssv) and create a csv file # ============================================================================= infid = open('ssv.grd') # input file outfid = open('csv.csv', 'w') for line in infid.readlines(): fields = line.split() x=float(fields[0]) y=float(fields[1]) z=float(fields[2]) outfid.write('%.3f,%.3f,%.3f\n' %(x, y, z)) # ============================================================================= # Here we close both the csv and ssv # ============================================================================= infid.close() outfid.close() # ============================================================================= # Here we read in the csv file and create a River2D bed file # ============================================================================= infid = open('csv.csv', 'r') outfid = open('River2D.bed', 'w') n=0 for line in infid.readlines(): fields = line.split(',') n=n+1 x=float(fields[0]) y=float(fields[1]) z=float(fields[2]) outfid.write('%d %.3f %.3f %.3f %s \n' %(n, x, y, z, '0.5 grd')) outfid.write('\n') outfid.write('no more nodes.') outfid.write('\n \n \n') outfid.write('no more breakline segments.') outfid.write('\n \n \n') outfid.write('no more boundary segments.') # ============================================================================= # Here we delete the superceeded csv file # ============================================================================= infid.close() outfid.close() os.remove('csv.csv')