def write_new_infocell(path = "infocell_QC2.txt"): f = open(path, 'w') cell_list = [] #me format = '%15s' * 13 f.write(format % ('N','XX','YY','DA','CHSLP','IBN','NEXT','AREA', 'RID','ROUT','LON', 'LAT', 'CHLEN') + '\n') format = '%15d' * 3 + '%15.1f' + '%15.10f' + '%15d' * 2 + '%15.1f' + '%15d' * 2 + '%15.1f' * 3 # format = '%15s' * 12 # f.write(format % ('N','XX','YY','DA','CHSLP','IBN','NEXT','AREA', 'CLAY', 'SAND' ,'RID','ROUT') + '\n') # format = '%15d' * 3 + '%15.1f' + '%15.10f' + '%15d' * 2 + '%15.1f'*3 + '%15d' * 2 for basin in basins: for cell in basin.cells: put_to_list(cell, cell_list) final_cell = Cell() final_cell.id = len(cell_list) + 1 final_cell.next = final_cell final_cell.area = 0 final_cell.drainage_area = 0 final_cell.set_coords(-1, -1) for cell in cell_list: if cell.next is not None: if cell.next.basin is None: print cell.next.coords() write_cell(cell, f, format, final_cell) write_cell(final_cell, f, format, final_cell) print 'cell list: ', len(cell_list) for basin in basins: for the_cell in basin.cells: assert the_cell in cell_list assert len(set(cell_list)) == len(cell_list) f.close()