""" This script takes a River2D msh file of format: node no.,x,y,z,roughness no more nodes. Vert1,Vert2,Vert3,Tag,TagValue no more boundary segments. and converts it to a format where it can be used to creat a domain from Points and Vertices. All you need to do is specify the data file name and output file name """ import string infid = open('Riv2dMesh.msh') # input file outfid1 = open('ANUGA_MeshPts.csv', 'w') # output filename outfid2 = open('ANUGA_MeshVertices.csv', 'w') # output filename print "\nFILES are open ready for conversion....\n" reading_points = True reading_vertices = False last_point_index = 0 for line in infid.readlines(): print 'line', line.strip() if line.strip() == '': continue if line.lower().startswith('no more nodes'): reading_vertices = True reading_points = False continue if line.lower().startswith('no more boundary segments'): break if reading_points is True: # Read Points # Check that point indices are consecutive s = line[:5] index = int(s.strip()) assert index-1 == last_point_index last_point_index = index # Get points s = line[9:38] fields = s.split(' ') x=float(fields[0]) y=float(fields[1]) #z=float(fields[3]) # TODO: Get elevation data a separate list outfid1.write('%.3f, %.3f\n' % (x, y)) elif reading_vertices is True: # Read Vertices fields = line.split(' ') # Create indices and make them start from 0 pt1=int(line[1:6]) - 1 pt2=int(line[10:16]) - 1 pt3=int(line[20:26]) - 1 outfid2.write('%d, %d, %d\n' % (pt1, pt2,pt3)) outfid1.close() outfid2.close() print "\nConversion complete.\n"